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

DATE_TRUNC filtering failing only in some cases #8886

Open
lara-bellatin opened this issue Oct 30, 2024 · 1 comment
Open

DATE_TRUNC filtering failing only in some cases #8886

lara-bellatin opened this issue Oct 30, 2024 · 1 comment
Assignees
Labels
api:sql Issues related to SQL API

Comments

@lara-bellatin
Copy link

lara-bellatin commented Oct 30, 2024

Describe the bug
DATE_TRUNC filtering fails in some cases but not others.

It fails for this query:

SELECT
  "public"."Order"."channel" AS "channel",
  SUM(
    CASE
      WHEN DATE_TRUNC('month', "public"."Order"."orderDate") BETWEEN DATE_TRUNC('month', (NOW() + INTERVAL '-2 month'))
     
   AND DATE_TRUNC('month', (NOW() + INTERVAL '-1 month')) THEN "public"."Order"."lineSubtotal"
      ELSE 0.0
    END
  ) AS "tst2"
FROM
  "public"."Order"
GROUP BY
  "public"."Order"."channel"
ORDER BY
  "public"."Order"."channel" ASC

But not for this one:

SELECT
  "public"."Order"."channel" AS "channel",
  SUM(
    CASE
      WHEN DATE_TRUNC('month', "public"."Order"."orderDate") = DATE_TRUNC('month', (NOW() + INTERVAL '-1 month')) THEN "public"."Order"."lineSubtotal"
      ELSE 0.0
    END
  ) AS "tst2"
FROM
  "public"."Order"
GROUP BY
  "public"."Order"."channel"
ORDER BY
  "public"."Order"."channel" ASC

Error Message:

ERROR: Error during rewrite: Can't detect Cube query and it may be not supported yet. Please check logs for additional information. QUERY: SELECT "public"."Order"."channel" AS "channel", SUM(CASE WHEN DATE_TRUNC('month', "public"."Order"."orderDate") BETWEEN DATE_TRUNC('month', (NOW() + INTERVAL '-2 month')) AND DATE_TRUNC('month', (NOW() + INTERVAL '-1 month')) THEN "public"."Order"."lineSubtotal" ELSE 0.0 END) AS "tst2" FROM "public"."Order" GROUP BY "public"."Order"."channel" ORDER BY "public"."Order"."channel" ASC

Version:
1.0.5

@igorlukanin
Copy link
Member

Hi @lara-bellatin 👋

Just to double-check: do you have CUBESQL_SQL_PUSH_DOWN set to true?

Also, which BI tool generates these queries? (If they are indeed generated.)

@igorlukanin igorlukanin added question The issue is a question. Please use Stack Overflow for questions. api:sql Issues related to SQL API and removed question The issue is a question. Please use Stack Overflow for questions. labels Nov 1, 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
Projects
None yet
Development

No branches or pull requests

3 participants