-
Notifications
You must be signed in to change notification settings - Fork 25.2k
SQL: Fix issue with date columns returned always in UTC #40163
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
Conversation
When selecting columns of ES type `date` (SQL's DATETIME) the `FieldHitExtractor` was not using the timezone of the client session but always resorted to UTC. The same behaviour (UTC only) was encountered also for grouping keys (`CompositeKeyExtractor`) and for First/Last functions on dates (`TopHitsAggExtractor`). Fixes: elastic#40152
Pinging @elastic/es-search |
/cc @bpintea |
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.
LGTM.
Please raise an another issue since in the future we should improve the way we serialize/deserialize extractors. The timezone is common property yet 3 types of extractors have a reference to it and serialize/deserialize it separately.
Ideally we would find a way to save it once per cursor and reused in all these places.
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.
LGTM. Left two comments.
sqle.getMessage()); | ||
sqle = expectThrows(SQLException.class, () -> results.getObject("test_date", Short.class)); | ||
assertEquals(format(Locale.ROOT, "Unable to convert value [%.128s] of type [DATETIME] to [Short]", of(randomDate)), | ||
assertEquals(format(Locale.ROOT, "Unable to convert value [%.128s] of type [DATETIME] to [Short]", of(randomDate, timeZoneId)), |
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 find it cumbersome to call every time this static method with the timeZoneId
that's initialized outside the tests methods. Maybe create a of
method inside the ResultSetTestCase class that will, in turn, call the JdbcTestUtils' of
method with the timeZoneId
param?
protected CompositeKeyExtractor mutateInstance(CompositeKeyExtractor instance) throws IOException { | ||
return new CompositeKeyExtractor(instance.key() + "mutated", instance.property(), instance.zoneId()); | ||
protected CompositeKeyExtractor mutateInstance(CompositeKeyExtractor instance) { | ||
return new CompositeKeyExtractor(instance.key() + "mutated", instance.property(), instance.zoneId(), instance.isDateTimeBased()); |
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.
Is this mutation mechanism accurate here? Not talking about this PR specific change, but the method in general. Shouldn't this have 4 different mutations? (the mutated key, the property, the zone id, and the freshly added boolean) Something similar to https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlQueryRequestTests.java#L102.
@elasticmachine run elasticsearch-ci/bwc |
@elasticmachine run |
@elasticmachine run elasticsearch-ci/packaging-sample |
When selecting columns of ES type `date` (SQL's DATETIME) the `FieldHitExtractor` was not using the timezone of the client session but always resorted to UTC. The same behaviour (UTC only) was encountered also for grouping keys (`CompositeKeyExtractor`) and for First/Last functions on dates (`TopHitsAggExtractor`). Fixes: #40152
When selecting columns of ES type `date` (SQL's DATETIME) the `FieldHitExtractor` was not using the timezone of the client session but always resorted to UTC. The same behaviour (UTC only) was encountered also for grouping keys (`CompositeKeyExtractor`) and for First/Last functions on dates (`TopHitsAggExtractor`). Fixes: #40152
When selecting columns of ES type `date` (SQL's DATETIME) the `FieldHitExtractor` was not using the timezone of the client session but always resorted to UTC. The same behaviour (UTC only) was encountered also for grouping keys (`CompositeKeyExtractor`) and for First/Last functions on dates (`TopHitsAggExtractor`). Fixes: #40152
When selecting columns of ES type `date` (SQL's DATETIME) the `FieldHitExtractor` was not using the timezone of the client session but always resorted to UTC. The same behaviour (UTC only) was encountered also for grouping keys (`CompositeKeyExtractor`) and for First/Last functions on dates (`TopHitsAggExtractor`). Fixes: #40152
When selecting columns of ES type
date
(SQL's DATETIME) theFieldHitExtractor
was not using the timezone of the client sessionbut always resorted to UTC. The same behaviour (UTC only) was
encountered also for grouping keys (
CompositeKeyExtractor
) andfor First/Last functions on dates (
TopHitsAggExtractor
).Fixes: #40152