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
How to use DB provided analytical functions #538
Comments
Hey @klausb ! You can define it as a number measure:
|
Hey @paveltiunov , I tried that, but it does not work because of the mentioned error. My example is a variation and fails because of the same issue
Asking for moveAvg using the Cube Playground app gets me this error from the DB:
Any idea how to add this GROUP BY to the resulting statement? |
@klausb Ah. Yep. Sorry. Right. Because it's dimension in fact as it's rolling window. Could you please try to define it as dimension instead? |
@paveltiunov With a dimension I get closer. One problem still remains: cubejs automatically appends GROUP BY snippets for selected dimensions. For the above dimension this is an error ( Analytic functions not allowed in GROUP BY clause). Edit: I tried with subQuery, but then the schema compiler complains about missing "case". |
@klausb Ah. Yep. Right. I believe the only option is to put it in cube SQL then and use it as a dimension referencing to a column. |
Can you explain how that works? I tried this so far:
With the cube Playground I create this query:
Which leads to this SQL
And then this error:
It works, if I manually change to GROUP BY 2,3. |
@paveltiunov , any further ideas? |
@klausb You can do it as simply as
This approach however expects you have fixed set of dimensions you want to analyze. If your dimension set should change please use https://cube.dev/docs/measures#parameters-rolling-window |
@klausb Did it work out for you? |
How can I use analytical functions from e.g. Vertica alongside with raw data access in a schema?
For example, I want to expose a calculated metric from a moving average computed in the DB, like this
See here: https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/AnalyzingData/SQLAnalytics/CalculatingMovingAverage.htm
Whenever I create a calculated metric and use this snippet
I see SQL errors. I need to add the corresponding GROUP BY to the end. But how?
The text was updated successfully, but these errors were encountered: