[FLINK-14925][table] Support precision-aware TO_TIMESTAMP with format-based inference#27793
Open
raminqaf wants to merge 4 commits intoapache:masterfrom
Open
[FLINK-14925][table] Support precision-aware TO_TIMESTAMP with format-based inference#27793raminqaf wants to merge 4 commits intoapache:masterfrom
raminqaf wants to merge 4 commits intoapache:masterfrom
Conversation
Collaborator
snuyanzin
reviewed
Mar 20, 2026
davidradl
reviewed
Mar 20, 2026
snuyanzin
reviewed
Mar 20, 2026
...able-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java
Show resolved
Hide resolved
snuyanzin
reviewed
Mar 20, 2026
...ntime/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampFunction.java
Outdated
Show resolved
Hide resolved
snuyanzin
reviewed
Mar 20, 2026
...ntime/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampFunction.java
Outdated
Show resolved
Hide resolved
snuyanzin
reviewed
Mar 20, 2026
snuyanzin
reviewed
Mar 22, 2026
snuyanzin
reviewed
Mar 22, 2026
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 makes the
TO_TIMESTAMPfunction precision-aware when a format pattern is provided. Previously,TO_TIMESTAMPalways returnedTIMESTAMP(3)regardless of the format pattern's fractional second precision, which forced users to lose sub-millisecond data. This is theTO_TIMESTAMPcounterpart to theTO_TIMESTAMP_LTZprecision support added in FLINK-39244.The output type for the 1-arg variant remains
TIMESTAMP(3)for backward compatibility. For the 2-arg variant, precision isinferred from the format pattern's trailing
Scount (e.g.,SSSSSS→TIMESTAMP(6)), with a minimum of 3.As part of this change,
TO_TIMESTAMPis migrated from the legacy Calcite-native function pattern (FlinkSqlOperatorTable + StringCallGen codegen) to the modern bridging function pattern (BuiltInFunctionDefinition + runtimeClass), matching howTO_TIMESTAMP_LTZis implemented. This was made possible by fixing the function name from camelCase"toTimestamp"to"TO_TIMESTAMP", which allowsCoreModuleto resolve it correctly for SQL queries without needing a separateFlinkSqlOperatorTableentry.Brief change log
ToTimestampTypeStrategy): New output type strategy that returnsTIMESTAMP(3)for the 1-arg variantand
TIMESTAMP(max(sCount, 3))for the 2-arg variant, wheresCountis inferred from the format pattern's trailingScharacters.
ToTimestampFunction): New runtime class witheval(StringData)andeval(StringData, StringData)methods. The 2-arg variant passes
precisionFromFormat(format)toparseTimestampDatafor precision-aware parsing.BuiltInFunctionDefinitions): Changed name from"toTimestamp"to"TO_TIMESTAMP"(removing the need for explicitsqlName), addedruntimeClass, and switched output type strategy toSpecificTypeStrategies.TO_TIMESTAMP.FlinkSqlOperatorTable.TO_TIMESTAMP,DirectConvertRulemapping,StringCallGencases, and
BuiltInMethods.STRING_TO_TIMESTAMP/STRING_TO_TIMESTAMP_WITH_FORMAT— all superseded by the bridging function mechanism.sql_functions.yml,sql_functions_zh.yml, and Pythonexpressions.py/expression.pydocstrings with precision-dependent output types and examples.
Verifying this change
This change added tests and can be verified as follows:
ToTimestampTypeStrategyTestcovering 1-arg default precision, 2-arg format-basedprecision (SSS/SSSSSS/SSSSSSSSS/no-S), invalid argument types, and argument count validation.
TimeFunctionsITCasefor 1-arg truncation to precision 3, 2-arg precision 6/9 from format, SSS format staying at precision 3, fewer input digits than format precision, unparsable string, and null input.TemporalTypesTest.scalathat are now covered by the newTimeFunctionsITCasetests.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noToTimestampFunction.eval()methods call the sameDateTimeUtils.parseTimestampDatamethods as before.Documentation