github-actions[bot] commented on code in PR #61813:
URL: https://github.com/apache/doris/pull/61813#discussion_r2999756345


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -875,6 +875,33 @@ public Expression 
visitComparisonPredicate(ComparisonPredicate cp, ExpressionRew
 
     @Override
     public Expression visitCaseWhen(CaseWhen caseWhen, 
ExpressionRewriteContext context) {
+        if (caseWhen.getValue().isPresent()) {
+            // Simple case: CASE value WHEN cond THEN result ...
+            // Analyze value once, then construct EqualTo(analyzedValue, 
analyzedCond) per WhenClause
+            Expression analyzedValue = caseWhen.getValue().get().accept(this, 
context);
+
+            List<WhenClause> newWhenClauses = new ArrayList<>();
+            for (WhenClause whenClause : caseWhen.getWhenClauses()) {
+                Expression operand = whenClause.getOperand().accept(this, 
context);
+                Expression result = whenClause.getResult().accept(this, 
context);
+                EqualTo rawEqualTo = new EqualTo(analyzedValue, operand);
+                registerPlaceholderIdToSlot(rawEqualTo, context, 
analyzedValue, operand);
+                Expression equalTo = 
TypeCoercionUtils.processComparisonPredicate(rawEqualTo);

Review Comment:
   Nit: This `registerPlaceholderIdToSlot` call is effectively dead code in 
this context. The method checks whether `cp.right()` or `cp.left()` is a 
`Placeholder` instance. In `visitComparisonPredicate`, the original 
pre-analysis `cp` is passed (so Placeholder children are still visible), but 
here `rawEqualTo` is freshly constructed with already-analyzed children 
(`analyzedValue` and `operand`), which have already had their Placeholders 
resolved by `accept(this, context)`. So `rawEqualTo.right() instanceof 
Placeholder` and `rawEqualTo.left() instanceof Placeholder` will always be 
false.
   
   This is harmless (just two instanceof checks that always fail), but if the 
intent is to support prepared statement short-circuit optimization for simple 
CASE expressions, the approach would need to pass the original unanalyzed 
expressions as the `ComparisonPredicate` argument — similar to how 
`visitComparisonPredicate` passes the original `cp`.
   
   Consider either removing this call (since it's a no-op) or adding a comment 
explaining it's kept for future correctness if the prepared statement path 
needs to handle this case.



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