Doris-Breakwater commented on issue #66829:
URL: https://github.com/apache/doris/issues/66829#issuecomment-5311876556

   Breakwater-GitHub-Analysis-Slot: slot_e2a072a96813
   
   This content is generated by AI for reference only.
   
   Initial assessment: **confirmed FE/Nereids constant-folding bug**. I checked 
the current public `master` head (`ef1d741df4ed40f081321100c08cc4c41a701d32`) 
as well as the local source snapshot. The issue currently has no labels, 
assignee, milestone, or linked PR; suggested ownership is Nereids FE expression 
rewriting/constant folding.
   
   Verified facts:
   
   - `FoldConstantRuleOnFE` rewrites the children and calls `preProcess()`, but 
once both children are literals, each of `visitGreaterThan`, 
`visitGreaterThanEqual`, `visitLessThan`, and `visitLessThanEqual` casts both 
operands directly to `ComparableLiteral`.
   - `DateTimeAcquire.curTime()` and `currentTime()` return `TimeV2Literal`. 
`TimeV2Literal` extends `Literal` and does not implement `ComparableLiteral`.
   - During comparison coercion, a character literal such as `'20:00:00'` can 
be converted to the other operand's `TIMEV2` type. The fold then reaches the 
unchecked cast with literal operands, explaining the reported 
`ClassCastException` during planning.
   - Primitive `TIMEV2` comparisons are accepted by comparison type checking 
and can be translated for execution. Therefore, preserving the rewritten 
predicate when FE cannot compare the literal classes is consistent with the 
existing execution path; this is a mismatch in the FE folding domain, not 
evidence that the SQL comparison itself is unsupported.
   - Equality paths already handle non-`ComparableLiteral` operands without 
this unchecked ordered cast, so the immediate scope is the four ordered 
operators.
   
   Recommended fix:
   
   1. After child rewriting and `preProcess()`, fold an ordered comparison only 
when **both** operands implement `ComparableLiteral`; otherwise return the 
rewritten comparison predicate unchanged. Applying the same helper or guard to 
all four visitors will avoid asymmetric coverage.
   2. Keep adding `ComparableLiteral` semantics to `TimeV2Literal` as a 
separate design option only if FE-side ordering is desired. That alternative 
needs explicit tests for negative times, fractional scales, and the 
cross-literal comparison contract; it is not necessary for the minimal crash 
fix.
   3. Add focused FE unit coverage for `>`, `>=`, `<`, and `<=` with 
non-comparable `TimeV2Literal` operands, plus a positive control showing 
existing comparable literals still fold to `BooleanLiteral`.
   4. Add a Nereids regression that executes the reported `SELECT curtime() >= 
'20:00:00'` (and preferably `current_time`/precision variants) and verifies 
planning/execution completes without an exception. The result is 
time-dependent, so the regression should test successful execution rather than 
hard-code a boolean value.
   
   Missing but non-blocking information:
   
   - The report says `master` but does not include the exact reporter-side 
commit SHA or full FE exception stack. Those would help pin the affected 
revision and confirm the precise optimizer entry point, especially if 
reproduction differs locally.
   - If a maintainer cannot reproduce, please also capture relevant 
constant-folding/type-coercion session variables. No query profile or 
storage/BE logs are needed for this failure mode.
   
   Impact appears limited to planning expressions whose folded 
ordered-comparison operands are literal classes outside the `ComparableLiteral` 
contract; it causes query failure but there is no indication of data corruption.
   


-- 
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