[FLINK-39244][table] Support precision 0-9 for TO_TIMESTAMP_LTZ function#27757
Open
raminqaf wants to merge 3 commits intoapache:masterfrom
Open
[FLINK-39244][table] Support precision 0-9 for TO_TIMESTAMP_LTZ function#27757raminqaf wants to merge 3 commits intoapache:masterfrom
raminqaf wants to merge 3 commits intoapache:masterfrom
Conversation
Collaborator
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.
What is the purpose of the change
This pull request extends the
TO_TIMESTAMP_LTZ(numeric, precision)function to support all precision values from 0 to 9, where precision specifies the unit of the epoch value as 10^(-precision) seconds. Previously only 0 (seconds) and 3 (milliseconds) were supported, which limited users working with higher-precision epoch values such as microseconds (6) or nanoseconds (9).Brief change log
ToTimestampLtzTypeStrategyto read the precision literal from the second argument and returnTIMESTAMP_LTZ(precision)with the correct precision. Validates precision is between 0 and 9.ToTimestampLtzInputTypeStrategy, so out-of-range epoch values fail at validation time rather than silently returning null at runtime.DateTimeUtilswith a genericepochToTimestampDatamethod usingMath.powfor factor computation. Added inverse methodtoEpochValue(Instant, precision).ValueLiteralExpressionto serializeTIMESTAMP_LTZliterals using the precision from theDataType, preserving full precision. Previously it was hardcoded to precision 3 and threw for sub-millisecond values.sql_functions.ymlandsql_functions_zh.ymlto reflect the expanded precision support.Verifying this change
This change added tests and can be verified as follows:
ExpressionTestto verifyTIMESTAMP_LTZliteral serialization round-trips correctly at every precision.ToTimestampLtzTypeStrategyTestcovering precision 0/3/6/9, out-of-range precision, and nullable/not-null input combinations.TimeFunctionsITCasefor precision 6 (microseconds) and precision 9 (nanoseconds) with numeric epoch values.LiteralExpressionsSerializationITCasefor precisions 0, 3, 6, and 9.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDateTimeUtils.epochToTimestampDatais called per-record but the change replaces a switch statement withMath.powcomputations, which has negligible performance impact.Documentation