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

Bug: Time interval "CAST((NOW() + INTERVAL '-40 day')" leads to error #48

Open
BigBerny opened this issue Jul 12, 2024 · 9 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers priority-high High priority issue quickfix Fast-to-fix issue user-request This issue was directly requested by a user

Comments

@BigBerny
Copy link

BigBerny commented Jul 12, 2024

What
Running this query results in a warning that query can't be pushed down and finally crashes after 20-50 seconds.

SELECT *
FROM parquet_predictions as predictions
WHERE
 "predictions"."date_day" BETWEEN CAST((NOW() + INTERVAL '-40 day') AS date)
  AND CAST((NOW() + INTERVAL '-1 day') AS date)

This is the error I get:

WARNING: This query was not fully pushed down to DuckDB because DuckDB returned an error. Query times may be impacted. If you would like to see this query pushed down, please submit a request to https://github.com/paradedb/paradedb/issues with the following context:
Binder Error: No function matches the given name and argument types '+(TIMESTAMP WITH TIME ZONE, INTERVAL)'. You might need to add explicit type casts.
Candidate functions:
+(TINYINT) -> TINYINT
+(TINYINT, TINYINT) -> TINYINT
+(SMALLINT) -> SMALLINT
+(SMALLINT, SMALLINT) -> SMALLINT
+(INTEGER) -> INTEGER
+(INTEGER, INTEGER) -> INTEGER
+(BIGINT) -> BIGINT
+(BIGINT, BIGINT) -> BIGINT
+(HUGEINT) -> HUGEINT
+(HUGEINT, HUGEINT) -> HUGEINT
+(FLOAT) -> FLOAT
+(FLOAT, FLOAT) -> FLOAT
+(DOUBLE) -> DOUBLE
+(DOUBLE, DOUBLE) -> DOUBLE
+(DECIMAL) -> DECIMAL
+(DECIMAL, DECIMAL) -> DECIMAL
+(UTINYINT) -> UTINYINT
+(UTINYINT, UTINYINT) -> UTINYINT
+(USMALLINT) -> USMALLINT
+(USMALLINT, USMALLINT) -> USMALLINT
+(UINTEGER) -> UINTEGER
+(UINTEGER, UINTEGER) -> UINTEGER
+(UBIGINT) -> UBIGINT
+(UBIGINT, UBIGINT) -> UBIGINT
+(UHUGEINT) -> UHUGEINT
+(UHUGEINT, UHUGEINT) -> UHUGEINT
+(DATE, INTEGER) -> DATE
+(INTEGER, DATE) -> DATE
+(INTERVAL, INTERVAL) -> INTERVAL
+(DATE, INTERVAL) -> TIMESTAMP
+(INTERVAL, DATE) -> TIMESTAMP
+(TIME, INTERVAL) -> TIME
+(INTERVAL, TIME) -> TIME
+(TIMESTAMP, INTERVAL) -> TIMESTAMP
+(INTERVAL, TIMESTAMP) -> TIMESTAMP
+(TIME WITH TIME ZONE, INTERVAL) -> TIME WITH TIME ZONE
+(INTERVAL, TIME WITH TIME ZONE) -> TIME WITH TIME ZONE
+(TIME, DATE) -> TIMESTAMP
+(DATE, TIME) -> TIMESTAMP
+(TIME WITH TIME ZONE, DATE) -> TIMESTAMP WITH TIME ZONE
+(DATE, TIME WITH TIME ZONE) -> TIMESTAMP WITH TIME ZONE
+(ANY[], ANY[]) -> ANY[]

LINE 4: ...*
FROM parquet_predictions as predictions
WHERE
"predictions"."date_day" BETWEEN CAST((NOW() + INTERVAL '-40 day') AS date)

Why
Metabase filters data like that if you select "Last x days" and this can't be changed there.
The same query runs fine if I call it directly via DuckDB.

@philippemnoel philippemnoel added the bug Something isn't working label Jul 12, 2024
@rebasedming
Copy link
Contributor

There are a few issues I'm working through before I can get to this. In the meantime, casting now() to timestamp, ie now()::timestamp will probably solve since the error message says that (TIMESTAMP, INTERVAL) -> TIMESTAMP is allowed.

@BigBerny
Copy link
Author

Ok, thanks for having a look 👍 Unfortunately Metabase (and probably other graphical SQL IDEs) generate the sql query automatically based on what the user selects in the date widget. So there's no easy way to cast now() to timestamp when using their graphical interface.

@rebasedming
Copy link
Contributor

Okay, I have a temporary workaround for you. Just run the following:

SELECT duckdb_execute('INSTALL icu');
SELECT duckdb_execute('LOAD icu');

And the above query should work.

@BigBerny
Copy link
Author

Thanks, Devin 😄

@philippemnoel
Copy link
Collaborator

I am trying out Devin haha!

@BigBerny
Copy link
Author

Okay, I have a temporary workaround for you. Just run the following:

SELECT duckdb_execute('INSTALL icu');
SELECT duckdb_execute('LOAD icu');

And the above query should work.

When do we have to run that? Only once or every time the server starts or for every session? I just got the same error again and had to run the commands.

@philippemnoel
Copy link
Collaborator

Okay, I have a temporary workaround for you. Just run the following:

SELECT duckdb_execute('INSTALL icu');
SELECT duckdb_execute('LOAD icu');

And the above query should work.

When do we have to run that? Only once or every time the server starts or for every session? I just got the same error again and had to run the commands.

Until we merge this fix, it needs to be run in every session as a workaround.

@philippemnoel philippemnoel added the good first issue Good for newcomers label Aug 7, 2024
@evanxg852000
Copy link
Contributor

@rebasedming what's the consensus for resolving this, auto-installing the icu extension?

@rebasedming
Copy link
Contributor

@rebasedming what's the consensus for resolving this, auto-installing the icu extension?

Ideally we would have it already loaded in the embedded DuckDB provided by duckdb-rs. If that's prohibitive, I think we can use my caching PR to have it installed once when the DuckDB database file is created.

@philippemnoel philippemnoel transferred this issue from paradedb/paradedb Aug 8, 2024
@philippemnoel philippemnoel added the priority-medium Medium priority issue label Aug 8, 2024
@philippemnoel philippemnoel added priority-high High priority issue and removed priority-medium Medium priority issue labels Aug 23, 2024
@philippemnoel philippemnoel added quickfix Fast-to-fix issue user-request This issue was directly requested by a user labels Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers priority-high High priority issue quickfix Fast-to-fix issue user-request This issue was directly requested by a user
Projects
None yet
Development

No branches or pull requests

4 participants