Repository navigation
Conversation
date_bin, the aggregation scan windows and date_bin_gapfill computed month bins from ChronoUnit.MONTHS.between, which is one short when the origin day does not exist in the source month (origin Jan 31, source Feb 29). They also built the window end and the next gap-fill step from the previous, already clamped bin. With an origin on day 29-31 rows went to the previous bin, the pushed-down GROUP BY kept emitting the same empty window and never finished, and gap fill stepped on the 29th of every month. Bin k now always starts at origin.plusMonths(k * monthDuration), the index is corrected in both directions, the window end is bin k + 1, and the month gap-fill operators get the origin through GapFillNode to step by bin index. Fixes apache#19374
Contributor
Author
|
The CI workflows for this PR are waiting for maintainer approval to run. Could someone approve them when convenient? The targeted unit tests and IoTDBGapFillTableIT pass locally; the commands and results are in the description. |
Contributor
Author
|
Hi @JackieTien97 could you please review this PR when you get a chance |
Contributor
Author
|
@JackieTien97 please review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #19374.
With a month or year interval and an origin on day 29-31 (or Feb 29 with a year interval), table-model
date_bin,GROUP BY date_bin(...)anddate_bin_gapfillused three different, wrong bin schedules.DateBinFunctionColumnTransformercaused all three:dateBin/dateBinStartEndtook the bin index fromChronoUnit.MONTHS.between(origin, source) / monthDuration.MONTHS.betweencompares the day of month, so it is one short when the origin day is clamped in the source month: from 2024-01-31 to 2024-02-29T12:00 it returns 0. The code only stepped back when the bin start was after the source and never stepped forward, so the row went to the previous bin.dateBinStartEndbuilt the window end from the clamped start (binStart.plusMonths(m)), so the window could end before the source.TableDateBinTimeRangeIteratoruses this window for the pushed-down aggregation. The block start fell outside the window, nothing was consumed, and the same empty window was emitted again on every call. The query never finished.nextDateBin(int, ZoneId, long)(month gap fill) added months to the previous step, so after Jan 31 -> Feb 29 every later step stayed on the 29th.Change
kalways starts atorigin.plusMonths(k * monthDuration).monthBinIndexstarts from theMONTHS.betweenestimate and corrects it in both directions, so it returns the last bin that starts at or before the source.dateBinreturns bink, anddateBinStartEndreturns[bin k, bin k + 1). The estimate is off by at most one, so each loop runs at most once.nextDateBin(int monthDuration, long origin, ZoneId, long currentTime)returns binindex(currentTime) + 1instead of adding months to the current step.GapFillNodecarries thedate_bin_gapfillorigin (it is already parsed inQueryPlanner.gapFill).TableOperatorGeneratorpasses it toGapFillWoGroupWMoOperator/GapFillWGroupWMoOperator. The node serializes the newlongafternonMonthDuration.Origins on day 1-28 (including the default origin) produce the same bins as before, because
MONTHS.betweenis exact for them and clamping never happens. Non-month intervals are unchanged.Before / after
Data (UTC, ms precision): rows at 2024-01-31, 2024-02-29T12:00, 2024-03-30, 2024-04-30, 2024-05-31 with
v= 1..5. Both runs used a 1C1D standalone build: master45cb9959f1before, this branch after.GROUP BY 1 LIMIT 6it returns01-31:1followed by five01-31:0rows, because the pushed-down scan keeps emitting the same empty window (the pushed-downdate_bin_gapfillcase below shows the same loop running until the query timeout)01-31:1, 02-29:2, 04-30:1, 05-31:1(exit code 0)01-31:1.0followed by 10,628,99901-31:nullrows, then720: Query execution is time out; the non-pushdown variant returns01-31:1.5, 02-29:3.0, 03-29:null, 03-31:4.0, 05-29:null, 05-31:5.001-31:1.0, 02-29:2.5, 03-31:null, 04-30:4.0, 05-31:5.0date_bin(1y, time, 2024-02-29T00:00:00+00:00)withGROUP BYnow returns2023-02-28:1, 2024-02-29:4on the same data.The missing trailing empty bin (
06-30) fortime < 2024-07-31happens with any origin on master, including2024-01-01. That is #18988 and is not changed here.Tests
DateBinFunctionTest: four new cases. They cover a Jan 31 origin with 1- and 3-month intervals, including sources before the origin; a Feb 29 origin with a 1-year interval;dateBinStartEndwindows that contain the source and end at the next bin; andnextDateBinsteps that matchdate_bin. On master all four fail (for exampleexpected:<1709164800000> but was:<1706659200000>); the other 13 cases pass with and without the change.GapFillWoGroupWMoOperatorTest/GapFillWGroupWMoOperatorTest: pass the origin. Their start time is a bin start, so the expected output is unchanged.IoTDBGapFillTableIT.monthIntervalWithMonthEndOriginTest: covers scalardate_bin, the pushed-downGROUP BY ... ORDER BY 1(which did not finish before), anddate_bin_gapfillwith and without group keys.Commands run locally (JDK 25):
The two skipped tests are existing ignored cases. Only
msprecision was tested end to end, and only theTableSimpleIT(1C1D) profile was run locally.This PR has: