Skip to content

[common][flink] Fix missing cast rule for DATE/TIME/TIMESTAMP to bounded CHAR/VARCHAR - #9670

Open
jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:casting-string-family
Open

[common][flink] Fix missing cast rule for DATE/TIME/TIMESTAMP to bounded CHAR/VARCHAR#9670
jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:casting-string-family

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Purpose

The three date/time-to-string cast rules target VarCharType.STRING_TYPE, so CastExecutors only matches a type equal to it — a bounded VARCHAR(n)/CHAR(n), or a plain STRING NOT NULL, resolves to no rule. SchemaManagerUtils treats a null executor as a rejection even though DataTypeCasts.supportsCast allows the change, so ALTER TABLE T MODIFY (b VARCHAR(10)) on a TIMESTAMP(3) column fails with "cannot be converted to VARCHAR(10) without losing information", while the same statement on an INT column works.

Keyed on DataTypeFamily.CHARACTER_STRING now, which the class javadoc of all three already claims, trimming and padding through BinaryStringUtils like the numeric and boolean rules. Truncating to a bounded target and blank padding CHAR is existing asserted behaviour for the other scalars (testModifyColumnTypeFromNumericToString, 47d4dd6). This also unblocks Spark's CAST(<datetime> AS VARCHAR(n)) pushdown through CastTransform, with the truncating semantics INT already has.

Tests

DateTimeToCharacterStringCastRuleTest, and SchemaChangeITCase.testModifyColumnTypeFromTimestampToBoundedString, which fails on master with the exception above.

Written with Claude Code; reasoning and verification are mine.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant