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
Fix filtering on LocalDates #40530
Fix filtering on LocalDates #40530
Conversation
|
(let [t (parse-temporal-string-literal-to-class s OffsetDateTime)] | ||
[:absolute-datetime t target-unit])) | ||
|
||
(defmethod parse-temporal-string-literal :type/DateTimeWithZoneID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap-temporal-string-literal
may be a better name.
;; with it. | ||
t)) | ||
|
||
(defmethod coerce-temporal [LocalDate LocalTime] [_t _target-class] (throw-invalid-time)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that a few comment blocks explaining some of the things to consider would be helpful.
- All Local to Offset/Zoned conversions must consider
results-timezone-id
- All Offset/Zoned to Local conversions do not need to consider
results-timezone-id
because session timezone will already be applied (is that correct?) - Others?
(defmethod coerce-temporal [LocalTime ZonedDateTime] [_t _target-class] (throw-invalid-datetime)) | ||
(defmethod coerce-temporal [OffsetTime ZonedDateTime] [_t _target-class] (throw-invalid-datetime)) | ||
(defmethod coerce-temporal [LocalDateTime ZonedDateTime] [t _target-class] (t/zoned-date-time t (t/zone-id (qp.timezone/results-timezone-id)))) | ||
(defmethod coerce-temporal [OffsetDateTime ZonedDateTime] [t _target-class] t) ; OffsetDateTime is perfectly fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is perfectly fine, I believe adding/comparing time to an offsetdatetime across a daylight savings shift could give an incorrect result. I'm not sure when we would actually get into this conversion though to test this scenario.
snoe> snoe=# set timezone = "America/Edmonton";
SET
snoe> snoe=# select ('2024-03-09T23:59'::timestamp) at time zone 'America/Chicago' + '3 hour'::interval;
?column?
------------------------
2024-03-10 01:59:00-07
(1 row)
snoe> snoe=# select ('2024-03-09T23:59'::timestamp) at time zone 'America/Chicago' + '4 hour'::interval;
?column?
------------------------
2024-03-10 03:59:00-06
(1 row)
snoe> snoe=# set timezone = "MST";
SET
snoe> snoe=# select ('2024-03-09T23:59'::timestamp) at time zone 'America/Chicago' + '3 hour'::interval;
?column?
------------------------
2024-03-10 01:59:00-07
(1 row)
snoe> snoe=# select ('2024-03-09T23:59'::timestamp) at time zone 'America/Chicago' + '4 hour'::interval;
?column?
------------------------
2024-03-10 02:59:00-07
(1 row)
@camsaul Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone? |
* Split from #40146: only the filter changes * Don't include format-rows changes here. * Test fixes 🔧 * Test fix 🔧 * Misc test fixes 🔧 * Test fix 🔧 * Tweak SQL Server fix
* Add backport resolution script * Fix filtering on LocalDates (#40530) * Split from #40146: only the filter changes * Don't include format-rows changes here. * Test fixes 🔧 * Test fix 🔧 * Misc test fixes 🔧 * Test fix 🔧 * Tweak SQL Server fix * Fix Kondo errors * Updated api/dataset tests * Test fix 🔧 --------- Co-authored-by: Metabase bot <metabase-bot@metabase.com> Co-authored-by: Cam Saul <1455846+camsaul@users.noreply.github.com> Co-authored-by: Cam Saul <github@camsaul.com>
Stop doing dumb things with local dates that give you unexpected results.
Don't parse a local date literal like
2024-03-20
to anOffsetDateTime
orZonedDateTime
. Previously, we'd try to parse it to something like#t "2024-03-20T00:00:00-07:00[US/Pacific]"
using the QP results timezone (eitherreport-timezone
if the DB supports session timezones, or the database timezone if it does not). Predictably, this caused bugs. Just parse it to aLocalDate
instead.Don't try to optimize a
LocalDate = LocalDate
orday(LocalDate) = day(LocalDate)
filters to:between
filters; we can leave them as=
. E.g. instead of generatingwe should just generate
This causes way less problems and is more performant, and is nicer to look at.
Fixes #39769
Fixes #40332
This was split off from #40416, which is a more significant overhaul that fixes more things, but too big to backport.