Hi, is it possible to access metric definition (an...
# gooddata-cn
p
Hi, is it possible to access metric definition (and its SQL equivalent) via the REST API or Python SDK? For example, I have created a metric via the UI
Copy code
SELECT {metric/revenue} - {metric/revenue_baseline}
and I would like to get a full PostgresSQL statement which would be executed on the database when I use this metric. Something like
Copy code
SELECT my_table.revenue - my_table.revenue_baseline FROM my_db.my_table
Is it possible?
i
Hi Piotr, May I know what version of GoodData Cloud are you working with, please? In general, you can find the apiary and SDK documentation here.
p
I run my local docker instance — gooddata-cn-ce:2.2.0
In general I have tried
Copy code
metrics = sdk.catalog_workspace_content.get_metrics_catalog(workspace_id=workspace_id)
but it does not seem like I could get what I want using CatalogMetric object (i don’t see any SQL formula definition easily accesible)
j
You can get SQL for reports(insights), not for metrics, because metrics are context-aware, they do not contain VIEW BY (~GROUP BY), SEGMENT BY(pivoting), and filters. However, you could simulate a report by filling it with the metric and empty view_by/segment_by/fillters, and get the SQL. Generally, the SQL is exposed by so-called explain API - https://www.gooddata.com/developers/cloud-native/doc/2.2/api-and-sdk/api/api_reference_all/#/actions/explainAFM. Unfortunately, this API is not covered in the Python SDK yet. I created an internal Jira for it. Note: it is also possible to get the SQL in our UI applications. Analytical Designer: • replace
edit
with
debug
in insight URL Metric Editor: • when you turn a feature flag on, it provides a completely new experience allowing you to execute metrics, view SQL , data preview, and even slice metrics by attributes • In gooddata-cn-ce I turn the feature flag like this:
Copy code
environment:
      GDC_FEATURES_VALUES_ENABLE_METRIC_SQL_AND_DATA_EXPLAIN: 'ENABLED'
Please, let me know if the UI way would be sufficient for you, or if you insist on the developer way with Python SDK. I prioritize the internal Jira based on that.
p
Thanks, the UI should be enough for now 🙂
One more question, is possible to import a partitioned table as a whole, not as a collection of partitions? Not quite sure if it is by design or it has something to do with naming of my table. The table is day-partitioned, individual partitions have names like
table_name_YYYY_MM_DD
. For that reason I am able to create metrics for individual partitions only.
j
Unfortunately, we do not support PG partitioned tables yet. It is on our roadmap. actually, I see the corresponding internal Jira in Hacking state, so it should be released soon. Meawhile, you can workaround it by manually editing PDM(extend it with the parent table, delete child tables if necessary).