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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -219,7 +219,18 @@ public Expression visit(Expression expr, 
ExpressionRewriteContext context) {
      * 
********************************************************************************************
 */
     @Override
     public Expression visitUnboundVariable(UnboundVariable unboundVariable, 
ExpressionRewriteContext context) {
-        return resolveUnboundVariable(unboundVariable);
+        Variable variable = resolveUnboundVariable(unboundVariable);
+        // Record used variable for SQL cache when context is available.
+        // Defensive null-check: some callers may invoke analysis without a 
full
+        // ExpressionRewriteContext (e.g. in isolated tests), so guard access.
+        if (context != null && context.cascadesContext != null) {
+            Optional<SqlCacheContext> sqlCacheContext = 
context.cascadesContext.getStatementContext()
+                    .getSqlCacheContext();
+            if (sqlCacheContext.isPresent()) {
+                sqlCacheContext.get().addUsedVariable(variable);
+            }
+        }

Review Comment:
   This changes `UnboundVariable` analysis from producing a `Variable` node to 
producing its literal value immediately. That fixes the early type-coercion 
problem, but it also removes `Variable` from every analyzed tree, which breaks 
downstream semantic checks that intentionally inspect analyzed expressions for 
`Variable`. One concrete case is generated columns: `CreateTableInfo` analyzes 
the expression first and only then rejects `instanceof Variable` 
(`checkExpressionInGeneratedColumn()`), so after this change a generated column 
like `c AS (@x + 1)` can slip through as a plain literal expression instead of 
being rejected. The old flow kept the `Variable` until the later 
`VariableToLiteral` rule, so that check still worked. Please either preserve 
`Variable` until those validations finish, or move the generated-column 
variable rejection earlier and add coverage for it.



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