[fix](constant folding) time_format() on a TIME literal folds to NULL, not the string "-null" #68732
All Vouch review confidence checks passed
Residual risk 0.35 = Change Risk (0.59) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #68732"
general
weight: 0.35
abhinav-phi
What problem does this PR solve?
Issue Number: close #68725
Related PR: None
Problem Summary:
DateTimeFormatterUtils.toFormatStringConservative(TimeV2Literal, StringLikeLiteral)prefixed thesign before it checked whether the formatter produced a result:
formatTemporalLiteralreturns null when the pattern needs date fields, which aTIMEvalue doesnot carry. So every date specifier (
%a %b %D %j %M %U %u %V %v %W %w %X %x) on a negative TIMEfolded to the string
-nullin the planner, while BE returns NULL:The fix returns null before applying the sign, and the folding function now maps a null result to a
typed
NullLiteral(StringType)instead of handing null tonew VarcharLiteral(...), whoseconstructor dereferences the string (
value.length()). After this change both the negative and thepositive case fold to NULL, which is what BE already returns.
Time-only specifiers are untouched:
time_format('-10:00:00', '%H:%i:%s')still folds to-10:00:00with the sign kept, as before.Release note
None
Check List (For Author)
- [ ] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
New
DateTimeExtractAndTransformTest.testTimeFormatKeepsNullForDateSpecifierscoverstime_format('-10:00:00', '%a')-> NULL,time_format('10:00:00', '%a')-> NULL andtime_format('-10:00:00', '%H:%i:%s')->-10:00:00.Red, on
masterwith only the test added:Green, focused run with both edits:
Wider net with the fix (
DateTimeExtractAndTransformTest,ConstantProjectionFoldingTest) alsoclean: 14 and 1 tests, no failures.
FoldConstantTestwas run too and shows two failures(
testDateConstructFunction:1552,testFoldString:581) that are pre-existing on this machineand unrelated: they fail identically on pristine
masterwith my edits stashed, and they aresession-time-zone dependent timestamp assertions.
Command (project flags from
run-fe-ut.sh):Environment: JDK 17.0.20 (Temurin), Maven 3.9.16, thrift 0.24.0 from the prebuilt thirdparty
package, Ubuntu 22.04 under WSL2. Style gate
mvn -pl fe-core checkstyle:check->You have 0 Checkstyle violations.Review follow-up (second commit):
time_formatis declaredFunctionSignature.ret(, so folding the null result toVarcharType.SYSTEM_DEFAULT)
NullLiteral(StringType.INSTANCE)made the folded expression decide the result field type as STRING, which the MySQL protocol
reports as BLOB instead of VARCHAR. It is now
NullLiteral(VarcharType.SYSTEM_DEFAULT), andtestTimeFormatKeepsNullForDateSpecifiersassertsgetDataType()for both the negative and thepositive TIME input (it is NULL for both, since a TIME value carries no date fields). Re-run on
that commit:
DateTimeExtractAndTransformTest, FoldConstantTest, DateTimeLiteralTest,->TimeV2LiteralTest
Tests run: 77, Failures: 3, Errors: 0, the three being the samesession-timezone timestamp assertions quoted above, and
0 Checkstyle violations.The
FE UTfailure on the previous head was not this change: the failed test occurrences inTeamCity build 1064064 are
BatchRollupJobTest.testBatchRollup,ForwardToMasterTest.testAddBeDropBeand twoEliminateGroupByKeyByUniformTestcases, and allfour are reported with
currentlyMuted=true. None of them reachtime_format.- [ ] No.
- [x] Yes. <!-- Explain the behavior change -->
time_format(<TIME literal>, <pattern with a date specifier>)folds to NULL instead of thestring
-null(ornull), matching BE. The folded NULL carries the function's declaredVARCHAR type, so the result field of such a query is VARCHAR rather than STRING/BLOB. No other
input changes its folded value.
- [x] No.
- [ ] Yes. <!-- Add document PR link here. -->
Check List (For Reviewer who merge this PR)
AI assistance disclosure
An AI coding agent was used to draft this change and the new test. I read and reviewed every line
myself, ran the FE unit tests above on the exact commit in this branch (including the pristine-master
control run for
FoldConstantTest), and I take responsibility for the result.