github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3097768823
##########
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);
+ }
+ }
+ return variable.getRealExpression();
Review Comment:
Returning the literal here changes the analyzed tree too early.
`VariableToLiteral` already replaces variables later in analysis, but callers
like `CreateTableInfo.generatedColumnCheck()` analyze first and only then
reject `expr instanceof Variable`
(`fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java:1187-1261`).
With this change, a generated-column expression containing `@x` is accepted
and the current session value gets baked into the persisted expression instead
of being rejected.
```suggestion
return variable;
```
##########
fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java:
##########
@@ -88,6 +89,7 @@
import org.xnio.StreamConnection;
import java.io.IOException;
+import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
Review Comment:
This still widens `TINYINT`/`SMALLINT` user variables to `INTEGER`, so
exact-width signatures remain broken. `SET @p = 3` stores a `TINYINT` via
`LogicalPlanBuilder.visitIntegerLiteral()` and
`TinyIntLiteral.toLegacyLiteral()`, but this branch still returns
`Literal.of((int) ...)`, so `SELECT CURTIME(@p)` is analyzed as
`current_time(INT)` and fails against the existing `current_time(TINYINT)`
signature in `CurrentTime`. If the goal is to preserve the original integer
type, the `TINYINT` and `SMALLINT` cases need explicit `byte`/`short` handling
too.
--
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]