Repository navigation
Conversation
At nanosecond precision, Util.parseTime multiplied the hour and day constants as int and widened to long only at the last factor, so the product overflowed first. "1h" became negative and was rejected as an unknown unit, and "1d" became 500,654,080,000 ns, which made INTEGRAL with unit '1d' return 172.57 times the correct value. Start both products with a long factor.
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
Util.parseTimeinlibrary-udfreturns wrong values for the unitshanddwhentimestamp_precisionisns. Both constants are multiplied asintand becomelongonly at the last factor, so the product overflows first (Util.java:303,:306):1h1dSo
INTEGRALrejects'unit'='1h'as an unknown unit and returns 172.57 times the correct value for'unit'='1d', andRESAMPLErejects'every'='1h'. The other library functions that read a duration throughparseTimeget the same values. I came across this while measuringINTEGRALfor the dev@ thread on its requirements.Change
The first factor is now
long(60L * ...,24L * ...), so the whole product is computed inlong. The other units, and all units atmsandusprecision, already fit inintbefore theLfactor, so their values do not change.#17871 also changes
parseTimeandUDAFIntegral, but not these two constants. The negative-timestamp case ofINTEGRALthat I mentioned on dev@ is handled there (hasLastValue), so it is not part of this PR.Verification
UtilParseTimeTest:1h,1dand2datns, and every unit from1msto1dcompared acrossms,usandns. Both tests fail on masterc6e194dwithexpected:<3600000000000> but was:<-694967296000>and pass with the change. All 21 tests inlibrary-udfpass, and so doesspotless:check.apache/iotdb:2.0.11-standalonewithtimestamp_precision=ns, with thelibrary-udfjar built from v2.0.11 (itsparseTimeis the same as on master) without and with the change. A jar built from master bundles a newer TsFile than the 2.0.11 server, so I used the release sources. Data:s1= 1.0 at time 0 and one day later.integral(s1, 'unit'='1s')integral(s1, 'unit'='1m')integral(s1, 'unit'='1h')701: ... Unknown time unit inputintegral(s1, 'unit'='1d')integral(s1, 'unit'='2d')resample(s1, 'every'='1h')on two points at 0 h and 2 h: v2.0.11 fails with701: ... gap should be a time period whose unit is ms, s, m, h, d.; with the change it returns the three rows at 0 h, 1 h and 2 h.This PR has: