cube
cube copied to clipboard
How to retrieve current query options?
Is there a way to retrieve current query options such as dimensions, measures as a compile_context or other variables to use them in the model?
This is useful when I need to calculate, for example, a metric:
{
sql: `sum(metric) over (partition by ${sub_set_of_dimensions.join(',')})`,
type: 'number'
}
In some cases, for cohort calculations, we need a subset of dimensions or something similar.
We try use extendContext but it work only correctly with restAPI to retrieve dimensions, not sql or graph.
Hi @itestyoy 👋
Is there a way to retrieve current query options such as dimensions, measures as a compile_context or other variables to use them in the model?
Nope, this is not supported.
Moreover, you are discouraged to do so as it will make your data model dependent on the queries—and would not allow to effectively apply caching, pre-aggregations, and security controls.
The recommended approach is to define as many measures as you'd like in the data model. If you'd like, you can generated them dynamically. You can also pick the correct measure judging by the dimensions in the query using query_rewrite.
I hope this helps.