github-actions[bot] commented on code in PR #66967:
URL: https://github.com/apache/doris/pull/66967#discussion_r3842704524
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -616,6 +618,26 @@ public Expression visitUnboundFunction(UnboundFunction
unboundFunction, Expressi
}
}
+ @Override
+ public Expression visitBracketArray(BracketArray bracketArray,
ExpressionRewriteContext context) {
+ // at parse time the items may still be UnboundFunction, which
defaults to deterministic and
+ // is neither an aggregate nor a table generating function, so they
look constant. Bind the
+ // items first, then re-validate constantness, e.g. [random()] becomes
volatile and [sum(1)]
+ // becomes an aggregate after binding, and both must be rejected
before lowering to array().
+ List<Expression> boundItems = bracketArray.children().stream()
+ .map(item -> item.accept(this, context))
+ .collect(ImmutableList.toImmutableList());
+ for (Expression item : boundItems) {
+ if (!item.isConstant()) {
+ throw new AnalysisException("Array literal '[...]' only
supports constant expressions, "
+ + "but got non-constant expression: " + item.toSql());
+ }
+ }
+ Array array = new Array(boundItems);
+ array.checkLegalityBeforeTypeCoercion();
+ return array;
Review Comment:
[P1] Run array coercion after lowering
This visitor returns a new `Array` root, so the adjacent
`visitBoundFunction` path never processes it. For `SELECT [CAST(1 AS INT),
CAST(2 AS BIGINT)]`, the new node advertises `ARRAY<BIGINT>` but its first
child remains `INT`; later input-type checking rejects this otherwise valid
constant array, whereas sibling `ARRAY(...)` inserts the cast through
`TypeCoercionUtils.processBoundFunction`. Please return the processed bound
function here and add heterogeneous and nested analyzed-plan tests.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -3793,27 +3795,54 @@ private List<Literal> typeCoercionItems(List<Literal>
items) {
}
@Override
- public ArrayLiteral visitArrayLiteral(ArrayLiteralContext ctx) {
- List<Literal> items =
ctx.items.stream().<Literal>map(this::typedVisit).collect(Collectors.toList());
+ public Expression visitArrayLiteral(ArrayLiteralContext ctx) {
+ List<Expression> items =
ctx.items.stream().<Expression>map(this::typedVisit).collect(Collectors.toList());
if (items.isEmpty()) {
- return new ArrayLiteral(items);
+ return new ArrayLiteral(ImmutableList.of());
}
- return new ArrayLiteral(typeCoercionItems(items));
+ for (Expression item : items) {
+ if (!item.isConstant()) {
+ throw new ParseException("Array literal '[...]' only supports
constant expressions, "
+ + "but got non-constant expression: " +
displaySql(item), ctx);
+ }
+ }
+ if (items.stream().allMatch(Literal.class::isInstance)) {
+ List<Literal> literals =
items.stream().map(Literal.class::cast).collect(Collectors.toList());
+ return new ArrayLiteral(typeCoercionItems(literals));
+ }
+ // array literal contains constant but non-literal expressions (e.g.
cast), preserve the
+ // bracket-array origin through analysis: unbound function calls look
constant at parse time,
+ // so bound items are re-validated before lowering to the array
function (see BracketArray).
+ return new BracketArray(items);
Review Comment:
[P1] Analyze bracket arrays stored in skew hints
This node can escape the ordinary plan-expression path through the
`constantList` used by `skew(...)`: both hint builders store it directly in
`JoinSkewInfo`, but `BindSkewExpr` analyzes only the skew key and calls
`castIfNotSameType` on each untouched value. An array-key hint such as
`[shuffle[skew(tl.arr([CAST(1 AS INT)]))]]` therefore calls `getDataType()` on
`BracketArray` and throws `UnboundException` before this node can be lowered.
This is distinct from the literal-only callers because skew metadata already
accepts `Expression`; please analyze those values before casting and cover both
direct and leading hint paths.
--
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]