FieldFilter variables mapped to DateTime datatype don't show results correctly #229
Description
Describe the bug
Hello. I didn't knew how to lable it - bug or suggestion, but IMHO this looks like a bug.
I've discovered, that Field Filter doesn't work "correctly" if being mapped to DateTime
datatype. All Filter Widget types for dates are affected, except one - Single Date
type.
Steps to reproduce
We are checking result of the following query for Date Filter
Filter Widget type:
select date_time
from date_filter
[[where {{date_time}}]]
order by date_time desc
Filter option | Where clause | Actual Result | Expected Result |
---|---|---|---|
Today | testing.date_filter.date_time = toDate('2024-03-19') | We got data only for midnight time: 19/3/2024, 00:00(check first screenshot 1) | Should show all timestamps for 19/3/2024 |
Yesterday | testing .date_filter .date_time = toDate('2024-03-18') |
We got data only for midnight time: 18/3/2024, 00:00(check first screenshot 2) | Should show all timestamps for 18/3/2024 |
Last 7 days | testing .date_filter .date_time BETWEEN toDate('2024-03-12') AND toDate('2024-03-18') |
For 18/3/2024 shows only midnight time: 18/3/2024, 00:00(check first screenshot 3) | Should show all timestamps between 11/3/2024 till 18/3/2024 including timestamps from 18/3/2024 |
Specific dates -> Between without time | testing .date_filter .date_time BETWEEN toDate('2024-03-11') AND toDate('2024-03-12') |
For 12/3/2024 shows only midnight time: 12/3/2024, 00:00(check first screenshot 4) | Should show all timestamps for 12/3/2024 |
Specific dates -> Between with time | testing .date_filter .date_time BETWEEN '2024-03-11 00:00:00.000' AND '2024-03-12 23:59:00.000' |
It didn't showed record for 2024-03-12 where time was 23:59:59(check first screenshot 5) | Should show all timestamps for 2024-03-12 23:59 |
Specific dates -> After | testing .date_filter .date_time > toDate('2024-03-18') |
We're missing midnight for 2024-03-18, and show other records for that day(screenshot 6) | Shouldn't show any timestamps for 2024-03-18 |
Specific dates -> On | CAST(testing .date_filter .date_time AS date) = toDate('2024-03-12') |
As expected - we got all records for 2024-03-12 (check screenshot7) | All timestamps for 2024-03-12 had been shown |
Following table will be all affected with same issue as above, so i'll just mention
Filter type (& option) | Where clause |
---|---|
Month and Year |
testing .date_filter .date_time BETWEEN toDate('2023-05-01') AND toDate('2023-05-31') |
Quater and Year |
where testing .date_filter .date_time BETWEEN toDate('2023-07-01') AND toDate('2023-09-30') |
Data Range without time |
testing .date_filter .date_time BETWEEN toDate('2024-03-18') AND toDate('2024-03-19') |
Data Range with time |
testing .date_filter .date_time BETWEEN '2024-03-18 00:00:00.000' AND '2024-03-19 23:59:00.000' |
Data Range single date |
testing .date_filter .date_time = toDate('2024-03-18') |
Relative date | Basically the same as for Date Filter options |
And here is table for Single Date
Filter Widget type:
Filter option | Where clause | Result |
---|---|---|
Just date | CAST(testing .date_filter .date_time AS date) = toDate('2024-03-19') |
As we wanted - all records for 2024-03-19 are shown by this query (screenshot 8) |
Date with time | toStartOfMinute (testing .date_filter .date_time ) = '2024-03-19 23:59:00.000' |
It showed every record for 23:59, as we expected(screenshot 9) |
These works perfectly with DateTime
datatype, and negate all "issues" mentioned above.
Can we somehow implement same "methods" for other Filter Widgets?
Configuration
Environment
- metabase-clickhouse-driver version: 1.4.0
- metabase-clickhouse-driver configuration: default
- Metabase version: 0.49.0
- OS: Oracle Linux Server 8.6
ClickHouse server
- ClickHouse Server version: 23.8.9.54 (official build)
CREATE TABLE
statements for tables involved:
CREATE TABLE date_filter
(
date_time
DateTime('Europe/Moscow'),
)
ENGINE = TinyLog
This is example of DateTime records from the table - 5 records with different time for a day:
2023-03-25 00:00:00
2023-03-25 06:30:34
2023-03-25 12:00:00
2023-03-25 18:45:58
2023-03-25 23:59:59
2023-03-26 00:00:00
Where max value for date_time is 2024-03-19 23:59:59 and min value for date_time is 2023-03-25 00:00:00
Screenshots: