fix timewarp query results when using timezones and crossing DST transitions#5157
fix timewarp query results when using timezones and crossing DST transitions#5157jon-wei merged 13 commits intoapache:masterfrom
Conversation
changes: * `TimewarpOperator` will now compensate for daylight savings time shifts between date translation ranges for queries using a `PeriodGranularity` with a timezone defined * introduces a new abstract query type `TimeBucketedQuery` for all queries which have a `Granularity` (100% not attached to this name). `GroupByQuery`, `SearchQuery`, `SelectQuery`, `TimeseriesQuery`, and `TopNQuery` all extend `TimeBucke tedQuery`, cutting down on some duplicate code and providing a mechanism for `TimewarpOperator` (and anything else) that needs to be aware of granularity
|
Labelling |
| for (DimensionSpec spec : this.dimensions) { | ||
| Preconditions.checkArgument(spec != null, "dimensions has null DimensionSpec"); | ||
| } | ||
| Preconditions.checkNotNull(granularity, "Must specify a granularity"); |
There was a problem hiding this comment.
This check should be done in TimeBucketedQuery's constructor
| ) | ||
| { | ||
| super(dataSource, querySegmentSpec, descending, context); | ||
| super(dataSource, querySegmentSpec, descending, context, granularity == null ? Granularities.ALL : granularity); |
There was a problem hiding this comment.
I suggest to extract method Granularities.nullToAll()
| ) | ||
| { | ||
| super(dataSource, querySegmentSpec, descending, context); | ||
| super(dataSource, querySegmentSpec, descending, context, granularity); |
There was a problem hiding this comment.
How do timeseries queries behave with null granularity?
There was a problem hiding this comment.
I just tested and it throws a null pointer exception, moving the precondition check from group by into TimeBucketedQuery constructor should fix this.
There was a problem hiding this comment.
It appears TimeseriesQueryBuilder defaults to Granularities.ALL which is why all of the tests which do not specify a granularity do not explode.
| * @return the offset between the mapped time and time t | ||
| */ | ||
| protected long computeOffset(final long t) | ||
| protected long computeOffset(final long t, final DateTimeZone tz) |
There was a problem hiding this comment.
Is it possible to refactor this method? Maybe it's code could be simplified?
|
@clintropolis could you please also give this PR a title that looks more sensible in git commit history. |
|
All queries are time bucketed.
Would it make sense for |
|
@drcrallen The reason I added Thanks for the review! |
They don't all take a granularity parameter, but if you count "hardcoded 'all' granularity" as "time bucketed" then, okay, sure :)
If this is the way you go, it should be 'all', since 'none' really means 'millis'. |
|
@clintropolis there is a true error at least with intellij inspections, closing/reopening a pr won't help |
|
Oops indeed. But the tests should pass, I think. |
|
The inspection indicates that of the |
|
I personally think the inspection complaining about |
|
@clintropolis You can also add |
…sitions (apache#5157) * timewarp and timezones changes: * `TimewarpOperator` will now compensate for daylight savings time shifts between date translation ranges for queries using a `PeriodGranularity` with a timezone defined * introduces a new abstract query type `TimeBucketedQuery` for all queries which have a `Granularity` (100% not attached to this name). `GroupByQuery`, `SearchQuery`, `SelectQuery`, `TimeseriesQuery`, and `TopNQuery` all extend `TimeBucke tedQuery`, cutting down on some duplicate code and providing a mechanism for `TimewarpOperator` (and anything else) that needs to be aware of granularity * move precondition check to TimeBucketedQuery, add Granularities.nullToAll, add getTimezone to TimeBucketQuery * formatting * more formatting * unused import * changes: * add 'getGranularity' and 'getTimezone' to 'Query' interface * merge 'TimeBucketedQuery' into 'BaseQuery' * fixup tests from resulting serialization changes * dedupe * fix after merge * suppress warning
…ng DST tran… (#5252) * fix timewarp query results when using timezones and crossing DST transitions (#5157) * timewarp and timezones changes: * `TimewarpOperator` will now compensate for daylight savings time shifts between date translation ranges for queries using a `PeriodGranularity` with a timezone defined * introduces a new abstract query type `TimeBucketedQuery` for all queries which have a `Granularity` (100% not attached to this name). `GroupByQuery`, `SearchQuery`, `SelectQuery`, `TimeseriesQuery`, and `TopNQuery` all extend `TimeBucke tedQuery`, cutting down on some duplicate code and providing a mechanism for `TimewarpOperator` (and anything else) that needs to be aware of granularity * move precondition check to TimeBucketedQuery, add Granularities.nullToAll, add getTimezone to TimeBucketQuery * formatting * more formatting * unused import * changes: * add 'getGranularity' and 'getTimezone' to 'Query' interface * merge 'TimeBucketedQuery' into 'BaseQuery' * fixup tests from resulting serialization changes * dedupe * fix after merge * suppress warning * Fix compile issue
…sitions (apache#5157) * timewarp and timezones changes: * `TimewarpOperator` will now compensate for daylight savings time shifts between date translation ranges for queries using a `PeriodGranularity` with a timezone defined * introduces a new abstract query type `TimeBucketedQuery` for all queries which have a `Granularity` (100% not attached to this name). `GroupByQuery`, `SearchQuery`, `SelectQuery`, `TimeseriesQuery`, and `TopNQuery` all extend `TimeBucke tedQuery`, cutting down on some duplicate code and providing a mechanism for `TimewarpOperator` (and anything else) that needs to be aware of granularity * move precondition check to TimeBucketedQuery, add Granularities.nullToAll, add getTimezone to TimeBucketQuery * formatting * more formatting * unused import * changes: * add 'getGranularity' and 'getTimezone' to 'Query' interface * merge 'TimeBucketedQuery' into 'BaseQuery' * fixup tests from resulting serialization changes * dedupe * fix after merge * suppress warning
Fixes #5156
changes:
TimewarpOperatorwill now compensate for daylight savings time shifts between date translation ranges for queries using aPeriodGranularitywith a timezone definedQueryinterface has been expanded with 2 new methods,getGranularityandgetTimezone.BaseQuerynow has aGranularityand a new constructor that takes an additional argument to set it. When using the original constructor, granularity will be set toGranularities.ALL.getTimezonemethod inBaseQuerywill return thePeriodGranularitytimezone if it is used, else it will default toDateTimeZone.UTC.GroupByQuery,SearchQuery,SelectQuery,TimeseriesQuery, andTopNQueryall individually had a granularity, so this change toQueryandBaseQuerycuts down on some duplicate code in addition providing a mechanism forTimewarpOperator(and anything else) that needs to be aware of query granularity or timezone.BaseQueryresult in serialization differences forDataSourceMetadataQuery,SegmentMetadataQuery,ScanQuery, andTimeBoundaryQuery, which previously did not have a granularity, but are now set toGranularities.ALL.