-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Incorrect SQL generated for WHERE clause when using Native Query and DateTime Field Filter Variables: DATE_TRUNC #38384
Labels
Database/Athena
Priority:P1
Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness
Querying/Native
The SQL/native query editor
Querying/Parameters & Variables
Filter widgets, field filters, variables etc.
Querying/Processor
.Team/QueryProcessor
:hammer_and_wrench:
Type:Bug
Product defects
Comments
mayanala-coxauto
changed the title
Using Variable type: Field Filter and Filter widget type: Date Filter returns 0 rows due to DATE_TRUNC added by Metabase SQL.
Incorrect SQL generated for WHERE clause when using Native Query and DateTime Field Filter Variables: DATE_TRUNC
Feb 14, 2024
paoliniluis
added
Querying/Processor
Database/Athena
Priority:P1
Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness
Querying/Parameters & Variables
Filter widgets, field filters, variables etc.
Querying/Native
The SQL/native query editor
and removed
.Needs Triage
labels
Feb 14, 2024
was this working in a previous version? |
@paoliniluis We are not sure if it worked before as this is the first time we are trying such queries. |
Can you upgrade to 1.48.8 ... I think you might be hitting this one #38037 |
@mayanala-coxauto are you still facing this issue? We are unable to reproduce it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Database/Athena
Priority:P1
Security holes w/o exploit, crashing, setup/upgrade, login, broken common features, correctness
Querying/Native
The SQL/native query editor
Querying/Parameters & Variables
Filter widgets, field filters, variables etc.
Querying/Processor
.Team/QueryProcessor
:hammer_and_wrench:
Type:Bug
Product defects
Describe the bug
We have an Athena table with column 'partition_date_hour' string datatype. Data for that column looks like this in YYYY-MM-DD HH:00 format
partition_date_hour
2024-01-14 23:00
2024-01-14 23:00
2024-01-14 23:00
2024-01-14 23:00
2024-01-14 23:00
2024-01-14 23:00
We did casting at column level to Field Type -> Creation Timestamp and Cast to a specific data type -> Coercion/ISO8601 ->DateTime.
We created a query with variable p_date with Variable type -> Field Filter and Filter widget type: Date Filter
As you can see we get 0 results and following is the preview of the query,
SELECT
COUNT(*) AS "count"
FROM
"ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"
WHERE
"ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"."account_id" = '183385486431'
AND "ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"."action" = 'ALLOW'
AND "ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"."httpsourcename" in ('ALB','APIGW','APPRUNNER','APPSYNC','CF','COGNITOIDP')
AND DATE_TRUNC('day', CAST("ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"."partition_date_hour" AS timestamp)) BETWEEN timestamp '2024-01-15 18:00:00.000' AND timestamp '2024-01-15 19:00:00.000'
If we take DATE_TRUNC generated by metabase, it returns results.
To prove that, we created same query with 2 variables start_time and end time with Variable type -> Date
** Note: Above selection do not show the Hour selected but that is another bug I guess **
As you can see it returns results as expected 56,556 rows.
Preview of the above query is as follows
SELECT
COUNT(*) AS "count"
FROM
"ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"
WHERE
"ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"."account_id" = '183385486431'
AND "ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"."action" = 'ALLOW'
AND "ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"."httpsourcename" in ('ALB','APIGW','APPRUNNER','APPSYNC','CF','COGNITOIDP')
AND CAST("ca_secdatalakenp_waf_logs_fh_test"."waf_logs_fh_test_raw_h_v13"."partition_date_hour"
AS timestamp)
BETWEEN timestamp '2024-01-15 18:00:00.000' and timestamp '2024-01-15 19:00:00.000'
So DATE_TRUNC is making the difference of results here.
To Reproduce
I'm not able to reproduce this issue in Sample Database as there is no column with Datetime stored as string YYYY-MM-DD HH:00 format. I'll try to think of other ways to reproduce it.
Expected behavior
Explained in Describe Bug section
Logs
No response
Information about your Metabase installation
Severity
Blocking usage of timestamp in all queries as it returns incorrect results due to DATE_TRUNC
Additional context
No response
The text was updated successfully, but these errors were encountered: