Doris-Breakwater commented on issue #70635: URL: https://github.com/apache/doris/issues/70635#issuecomment-6915055941
Breakwater-GitHub-Analysis-Slot: slot_19e2e905fedd The reported failure is supported by source inspection and should be triaged as an FE/Nereids constant-folding correctness bug. The issue currently has no labels or assignee; FE/Nereids ownership would be appropriate. A focused PR with regression coverage is a reasonable next step. **Verified in source** I checked the local `4.1.4` tag (`ad35a140c7fd0b842f18c23300bac581f7d04326`) and the exact cited master commit (`13cff7ff484596f29aa1381750e906db3c8bb704`). Both contain the mismatch described here: - The four ordered-comparison visitors rewrite their children, then call `preProcess()`. That helper checks foldability, NULL propagation, and whether the arguments are literals; it does **not** require `ComparableLiteral`. The visitors subsequently cast both operands unconditionally. `visitEqualTo()` checks the interface and otherwise uses `equals()`. See [4.1.4 comparison visitors](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java#L268-L325), [preProcess](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java#L808-L820), and the [master visitors](https://github.com/apache/doris/blob/13cff7ff484596f29aa1381750e906db3c8bb704/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java#L292-L348). - `TimeV2Literal` extends `Literal` without implementing that interface. Thus two non-NULL TIME literals reaching an ordered visitor necessarily fail at the cast. A column-dependent comparison does not satisfy the all-literal prerequisite. See [TimeV2Literal](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeV2Literal.java#L34). - The `CURRENT_TIME()` example fits the same mechanism: FE's executable function returns a `TimeV2Literal`, allowing the parent comparison to become an all-literal expression. See [DateTimeAcquire](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeAcquire.java#L104-L111). **Suggested fix and validation** Implementing `ComparableLiteral` for TIME is consistent with preserving FE folding. Compare the signed numeric microsecond value, including fractional seconds. One clarification: this is not restricted to “microseconds of the day”—TIME also supports negative values and hours beyond 23. FE's [getValue()](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeV2Literal.java#L402-L408) computes signed microseconds; BE represents TIMEV2 as [Float64](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/be/src/core/data_type/primitive_type.h#L340-L345) and routes it through [numeric comparison](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/be/src/exprs/function/functions_comparison.h#L845-L847). Avoid string ordering or conversion to a time-of-day representation. The proposed guard is also a viable way to avoid this known invalid cast: preserve the rewritten comparison when either operand lacks `ComparableLiteral`, keeping existing NULL handling. It must leave the expression executable later rather than substitute equality logic for ordering. Validate this path end to end before treating it as a complete alternative fix. Please cover all four operators with less/equal/greater operands; negative times (including negative subsecond values); values above 24 hours; microsecond differences and mixed scales; zero and supported boundaries; and NULL/equality behavior. Include both direct FE rule tests and SQL planner regression tests. Exercise constant casts, `CURRENT_TIME()`, and a real column-dependent control; the clock-dependent test should check successful boolean evaluation without assuming a fixed result. Compare FE-folded results with backend evaluation for deterministic inputs. **Evidence limits / missing information** This investigation verified the code paths; it did not execute the SQL or run Doris tests. The existing version, error, and minimal reproducer are sufficient for code triage. For independent runtime confirmation, attach the exact `SELECT VERSION()` output/build hash, the relevant FE exception stack from `fe.warn.log`, and session values for `debug_skip_fold_constant` and `enable_fold_constant_by_be`. No query profile is needed for this planning exception. A fix, runtime workaround, and release/backport availability remain unverified; maintainers should decide backports after tests pass. -- 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]
