Skip to content
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

Cube is getting invalid query generated by Metabase when aggregating by custom field #8243

Open
LarissaSiqueirabp opened this issue May 7, 2024 · 1 comment
Labels
api:sql Issues related to SQL API question The issue is a question. Please use Stack Overflow for questions.

Comments

@LarissaSiqueirabp
Copy link

Failed SQL
Initial planning error: Error during planning: No field named 'source.count_distinct_users'. Valid fields are 'source.vl_watch_time_seconds', 'source.vl_session_time_seconds', 'source.bl_watch_session'.

SELECT
  "source"."bl_watch_session" AS "bl_watch_session",
  count(distinct "source"."count_distinct_users") AS "count"
FROM
  (
    SELECT
      "public"."dataset"."vl_watch_time_seconds" AS "vl_watch_time_seconds",
      "public"."dataset"."vl_session_time_seconds" AS "vl_session_time_seconds",
      CASE
        WHEN "public"."dataset"."vl_session_time_seconds" = "public"."dataset"."vl_watch_time_seconds" THEN TRUE
        ELSE FALSE
      END AS "bl_watch_session"
    FROM
      "public"."dataset"
  ) AS "source"
GROUP BY
  "source"."bl_watch_session"
ORDER BY
  "source"."bl_watch_session" ASC

Logical Plan
It did not generate a Logical Plan since it raised an error.

Version:
Cube: 0.35.29

Additional context
We are testing Metabase as BI Tool to integrate with Cube. We tried to create a custom dimension at Metabase and use a measure to aggregate upon it. However, the result query (seen above) does not bring the measure (distinct users) that was created at Cube at the subquery, and therefore it generates an error when Cube tries to translate the SQL API query to the SQL to our database.

The expected query would be something like the query below:

SELECT
    CASE
        WHEN "public"."dataset"."vl_session_time_seconds" = "public"."dataset"."vl_watch_time_seconds" THEN TRUE
        ELSE FALSE
      END AS "bl_watch_session",
  count(distinct "public"."dataset"."count_distinct_users") AS "count"
FROM
  "public"."dataset"
GROUP BY
1
@igorlukanin
Copy link
Member

Hi @LarissaSiqueirabp 👋

Could you please set CUBESQL_SQL_PUSH_DOWN=true on your Cube instance and try again to see if anything changes?

@igorlukanin igorlukanin added question The issue is a question. Please use Stack Overflow for questions. api:sql Issues related to SQL API labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:sql Issues related to SQL API question The issue is a question. Please use Stack Overflow for questions.
Projects
None yet
Development

No branches or pull requests

2 participants