[common][flink] Fix missing cast rule for DATE/TIME/TIMESTAMP to bounded CHAR/VARCHAR - #9670
Open
jackylee-ch wants to merge 1 commit into
Open
[common][flink] Fix missing cast rule for DATE/TIME/TIMESTAMP to bounded CHAR/VARCHAR#9670jackylee-ch wants to merge 1 commit into
jackylee-ch wants to merge 1 commit into
Conversation
…ded CHAR/VARCHAR DateToStringCastRule, TimeToStringCastRule and TimestampToStringCastRule registered VarCharType.STRING_TYPE as their target, so CastExecutors only matched a type equal to it. A bounded VARCHAR/CHAR target, or a plain STRING NOT NULL, resolved to no rule, and SchemaManagerUtils rejects the column type change when the executor is null even though DataTypeCasts.supportsCast allows it. Key them on DataTypeFamily.CHARACTER_STRING, which the class javadoc here already claims, and trim or pad through BinaryStringUtils like the numeric and boolean rules. Bounded character targets already truncate and blank pad for the other scalar types, asserted since 47d4dd6.
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.
Purpose
The three date/time-to-string cast rules target
VarCharType.STRING_TYPE, soCastExecutorsonly matches a type equal to it — a boundedVARCHAR(n)/CHAR(n), or a plainSTRING NOT NULL, resolves to no rule.SchemaManagerUtilstreats a null executor as a rejection even thoughDataTypeCasts.supportsCastallows the change, soALTER TABLE T MODIFY (b VARCHAR(10))on aTIMESTAMP(3)column fails with "cannot be converted to VARCHAR(10) without losing information", while the same statement on anINTcolumn works.Keyed on
DataTypeFamily.CHARACTER_STRINGnow, which the class javadoc of all three already claims, trimming and padding throughBinaryStringUtilslike the numeric and boolean rules. Truncating to a bounded target and blank paddingCHARis existing asserted behaviour for the other scalars (testModifyColumnTypeFromNumericToString, 47d4dd6). This also unblocks Spark'sCAST(<datetime> AS VARCHAR(n))pushdown throughCastTransform, with the truncating semanticsINTalready has.Tests
DateTimeToCharacterStringCastRuleTest, andSchemaChangeITCase.testModifyColumnTypeFromTimestampToBoundedString, which fails on master with the exception above.Written with Claude Code; reasoning and verification are mine.