-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minor fixes #773
minor fixes #773
Conversation
|
curl --location 'https://d7nifimeibcde.cloudfront.net/engine/api/sql/v1/execution/executeQueryString?serializationFormat=DEFAULT&client_name=gitlabPAToken' \
--header 'legend-test-pat: PUT_YOUR_PAT_HERE' \
--header 'Content-Type: text/plain' \
--data 'SELECT
"root"."entityId" AS "entityId",
"root"."fiscalYear" AS "fiscalYear",
"root"."env.climate.emissions.ghgScope1Absolute" AS "env.climate.emissions.ghgScope1Absolute",
"root"."env.climate.emissions.ghgScope1Absolute_unit" AS "env.climate.emissions.ghgScope1Absolute_unit",
"root"."env.climate.emissions.ghgScope1Absolute.pcafScore" AS "env.climate.emissions.ghgScope1Absolute.pcafScore",
"root"."env.climate.emissions.ghgScope1Absolute.sourceDescription" AS "env.climate.emissions.ghgScope1Absolute.sourceDescription",
"root"."env.climate.emissions.ghgScope2LocAbsolute" AS "env.climate.emissions.ghgScope2LocAbsolute",
"root"."env.climate.emissions.ghgScope2LocAbsolute_unit" AS "env.climate.emissions.ghgScope2LocAbsolute_unit",
"root"."env.climate.emissions.ghgScope2LocAbsolute.pcafScore" AS "env.climate.emissions.ghgScope2LocAbsolute.pcafScore",
"root"."env.climate.emissions.ghgScope2LocAbsolute.sourceDescription" AS "env.climate.emissions.ghgScope2LocAbsolute.sourceDescription"
FROM
service(
pattern => '\''/finos/esg/env/climate/getEmissionData'\'',
project => '\''OMNIBUS-51104062'\'',
groupWorkspace => '\''GWS8'\''
) AS "root"' |
# Below is a demonstration of how to use pylegend lib service frame taking esgEmissionsData service.
# It assumes Legend engine running on localhost at 6300 port. There is no Auth here on local
# you can grab pylegend from pip
# pip install pylegend
import pylegend # version >= 0.3.0
from pylegend.core.request.auth import HeaderTokenAuthScheme
tds_client = pylegend.LegendApiTdsClient(
legend_client=pylegend.LegendClient(
host="d7nifimeibcde.cloudfront.net",
port=80,
path_prefix="/engine/api",
auth_scheme=HeaderTokenAuthScheme(header_name='legend-test-pat', token_provider=lambda: '________YOUR_TOKEN_HERE________'),
secure_http=False
)
)
frame = tds_client.legend_service_frame(
service_pattern="/finos/esg/env/climate/getEmissionData",
project_coordinates=pylegend.GroupWorkspaceProjectCoordinates(
project_id="OMNIBUS-51104062",
group_workspace="GWS8",
)
)
df = frame.execute_frame_to_pandas_df()
print(df)
dfteststring = frame.to_sql_query()
print(dfteststring) |
Try this URL for testing |
from urllib.request import Request, urlopen req = Request('https://dla3uc9je36km.cloudfront.net/engine/api/sql/v1/execution/executeQueryString?serializationFormat=DEFAULT&client_name=gitlabPAToken') req.add_header('legend-test-pat', my_pat ) req.add_header('Content-Type', 'text/plain' ) req.data = b"""SELECT * FROM service( pattern => '/finos/esg/pos/getJSONPortfolioReport', project => 'OMNIBUS-51104062', groupWorkspace => 'marrid' ) AS "root" """ #req.data = b"""SELECT * FROM service( pattern => '/finos/esg/env/climate/getEmissionData', project => 'OMNIBUS-51104062', groupWorkspace => 'marrid' ) AS "root" """ string_result = urlopen(req).read() string_result |
/engine/api/server/v1/info |
https://dla3uc9je36km.cloudfront.net/studio/edit/OMNIBUS-51104062/groupWorkspace/gfjson/ /finos/esg/pos/getJSONPortfolioReport |
GITLAB_PRIVATE_ACCESS_TOKEN = "____YOUR_PRIVATE_ACCESS_TOKEN____"
PROJECT_ID = "OMNIBUS-51104062"
GROUP_WORKSPACE = "gfjson"
SERVICE_PATH = "FinOS::ESG::services::pos::getJSONPortfolioReport"
RUNTIME_PATH = "" # if error occured when runtime is not specified as an runtime pointer in the service
SDLC_BASE_URL = "https://dla3uc9je36km.cloudfront.net/sdlc/api"
ENGINE_BASE_URL = "https://dla3uc9je36km.cloudfront.net/engine/api"
# ------------------------------- MAIN --------------------------------
import requests
from pylegend.core.request.auth import HeaderTokenAuth
# get the service
service_entity_fetch_result = requests.get(
SDLC_BASE_URL
+ "/projects/{projectId}/groupWorkspaces/{workspace}/entities/{entityPath}".format(
projectId=PROJECT_ID, workspace=GROUP_WORKSPACE, entityPath=SERVICE_PATH
),
auth=HeaderTokenAuth(
header_name="legend-test-pat",
token_provider=lambda: GITLAB_PRIVATE_ACCESS_TOKEN,
),
)
# extract mapping, runtime, and the function
service_element_protocol = service_entity_fetch_result.json()["content"]
mappingPath = service_element_protocol["execution"]["mapping"]
runtimePath = ""
try:
runtimePath = service_element_protocol["execution"]["runtime"]["runtime"]
except:
# if runtime pointer is not specified, fallback to use the custom runtime path
runtimePath = RUNTIME_PATH
function_protocol = service_element_protocol["execution"]["func"]
pmcd_fetch_result = requests.get(
SDLC_BASE_URL
+ "/projects/{projectId}/groupWorkspaces/{workspace}/pureModelContextData".format(
projectId=PROJECT_ID, workspace=GROUP_WORKSPACE
),
auth=HeaderTokenAuth(
header_name="legend-test-pat",
token_provider=lambda: GITLAB_PRIVATE_ACCESS_TOKEN,
),
)
# get PMCD (if engine supports SDLC workspace pointer, we don't need to do this)
# See https://github.com/finos/legend-engine/pull/2437
pmcd = pmcd_fetch_result.json()
# execute
execution_result = requests.post(
ENGINE_BASE_URL + "/pure/v1/execution/execute",
json={
"function": function_protocol,
"mapping": mappingPath,
"model": pmcd,
"runtime": {
"_type": "runtimePointer",
"runtime": runtimePath,
},
"context": {
"_type": "BaseExecutionContext",
"queryTimeOutInSeconds": None,
"enableConstraints": True,
},
},
auth=HeaderTokenAuth(
header_name="legend-test-pat",
token_provider=lambda: GITLAB_PRIVATE_ACCESS_TOKEN,
),
)
print(execution_result.text) |
SELECT |
script to run backup omnibus (with SDLC using file-system) curl https://legend.finos.org/omnibus/start.esg.sh | bash Usage
example Python script import pylegend
from pylegend.core.request.auth import HeaderTokenAuthScheme
tds_client = pylegend.LegendApiTdsClient(
legend_client=pylegend.LegendClient(
host="localhost",
port=6900,
path_prefix="/engine/api",
secure_http=False
)
)
frame = tds_client.legend_service_frame(
service_pattern="/finos/esg/env/climate/getEmissionData",
project_coordinates=pylegend.GroupWorkspaceProjectCoordinates(
project_id="ESG%20Reg%20Reporting",
group_workspace="example",
)
)
df = frame.execute_frame_to_pandas_df()
print(df)
dfteststring = frame.to_sql_query()
print(dfteststring) curl --location 'http://localhost:6900/engine/api/sql/v1/execution/executeQueryString?serializationFormat=DEFAULT' \
--header 'Content-Type: text/plain' \
--data 'SELECT
"root"."portfolioId" AS "portfolioId",
"root"."portfolioDate" AS "portfolioDate",
"root"."fiscalYear" AS "fiscalYear",
"root"."portfolioGhgScope1Emissions" AS "portfolioGhgScope1Emissions"
FROM
service(
pattern => '\''/finos/esg/env/climate/getPortfolioEmissions'\'',
project => '\''ESG%20Reg%20Reporting'\'',
groupWorkspace => '\''example'\''
) AS "root"' |
No description provided.