abhinav-phi opened a new pull request, #68732:
URL: https://github.com/apache/doris/pull/68732

   ### What problem does this PR solve?
   
   Issue Number: close #68725
   
   Related PR: None
   
   Problem Summary:
   
   `DateTimeFormatterUtils.toFormatStringConservative(TimeV2Literal, 
StringLikeLiteral)` prefixed the
   sign before it checked whether the formatter produced a result:
   
   ```java
   String res = formatTemporalLiteral(0, 0, 0, time.getHour(), ...);
   if (time.isNegative()) {
       res = "-" + res;      // res is null here -> the string "-null"
   }
   return res;
   ```
   
   `formatTemporalLiteral` returns null when the pattern needs date fields, 
which a `TIME` value does
   not carry. So every date specifier (`%a %b %D %j %M %U %u %V %v %W %w %X 
%x`) on a negative TIME
   folded to the string `-null` in the planner, while BE returns NULL:
   
   ```
   SELECT time_format('-10:00:00', '%a') AS fe, time_format(CAST(s1 AS TIME), 
'%a') AS be FROM t;
   +-------+------+
   | -null | 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 to `new 
VarcharLiteral(...)`, whose
   constructor dereferences the string (`value.length()`). After this change 
both the negative and the
   positive 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:00` with the sign kept, as before.
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [x] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
   
     New 
`DateTimeExtractAndTransformTest.testTimeFormatKeepsNullForDateSpecifiers` 
covers
     `time_format('-10:00:00', '%a')` -> NULL, `time_format('10:00:00', '%a')` 
-> NULL and
     `time_format('-10:00:00', '%H:%i:%s')` -> `-10:00:00`.
   
     Red, on `master` with only the test added:
   
     ```
     [ERROR]   
DateTimeExtractAndTransformTest.testTimeFormatKeepsNullForDateSpecifiers:341
               Unexpected type, expected: <NullLiteral> but was: 
<VarcharLiteral>
     ```
   
     Green, focused run with both edits:
   
     ```
     [INFO] Tests run: 14, Failures: 0, Errors: 0, Skipped: 0 - in 
DateTimeExtractAndTransformTest
     [INFO] BUILD SUCCESS
     ```
   
     Wider net with the fix (`DateTimeExtractAndTransformTest`, 
`ConstantProjectionFoldingTest`) also
     clean: 14 and 1 tests, no failures. `FoldConstantTest` was run too and 
shows two failures
     (`testDateConstructFunction:1552`, `testFoldString:581`) that are 
**pre-existing on this machine
     and unrelated**: they fail identically on pristine `master` with my edits 
stashed, and they are
     session-time-zone dependent timestamp assertions.
   
     Command (project flags from `run-fe-ut.sh`):
   
     ```
     mvn test -pl fe-core -am -Dcheckstyle.skip=true -DfailIfNoTests=false \
         -Dmaven.build.cache.enabled=false 
-Dtest=DateTimeExtractAndTransformTest
     ```
   
     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.`
   
   - Behavior changed:
       - [ ] No.
       - [x] Yes. <!-- Explain the behavior change -->
         `time_format(<negative TIME literal>, <pattern with a date 
specifier>)` folds to NULL instead of
         the string `-null`, matching BE. No other input changes its folded 
value.
   
   - Does this need documentation?
       - [x] No.
       - [ ] Yes. <!-- Add document PR link here. -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label
   
   ### 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to