github-actions[bot] commented on code in PR #70223:
URL: https://github.com/apache/doris/pull/70223#discussion_r4613363634
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/AggStateType.java:
##########
@@ -86,6 +110,67 @@ public AggStateType(String functionName, List<DataType>
subTypes,
this.returnNullable = returnNullable;
}
+ /** Record a declaration without binding functions or consulting the
session in the parser. */
+ public static AggStateType declaration(String name, List<DataType> inputs,
+ List<Boolean> nullables, boolean returnNullable) {
+ return new AggStateType(name, inputs, nullables, returnNullable);
+ }
+
+ /** Resolve new declarations only; catalog types retain their saved
signatures. */
+ public AggStateType resolveDeclaration() {
+ if (resultType != null) {
+ return this;
+ }
+ AggregateFunction nested = bindNestedAggregate();
+ // SQL declarations can require implicit casts before their signature
is saved.
+ nested = (AggregateFunction)
TypeCoercionUtils.implicitCastInputTypes(nested, nested.expectedInputTypes());
+ return new AggStateType(functionName,
+
nested.children().stream().map(Expression::getDataType).collect(Collectors.toList()),
+
nested.children().stream().map(Expression::nullable).collect(Collectors.toList()),
+ returnNullable, nested.getDataType());
+ }
+
+ static AggStateType
fromCatalogAggState(org.apache.doris.catalog.AggStateType catalogType) {
+ List<DataType> inputs =
catalogType.getSubTypes().stream().map(DataType::fromCatalogType)
+ .collect(Collectors.toList());
+ if (catalogType.getResultType() != null) {
+ return new AggStateType(catalogType.getFunctionName(), inputs,
catalogType.getSubTypeNullables(),
+ catalogType.getResultIsNullable(),
fromCatalogType(catalogType.getResultType()));
+ }
+ AggStateType legacy = new AggStateType(catalogType.getFunctionName(),
inputs,
+ catalogType.getSubTypeNullables(),
catalogType.getResultIsNullable());
+ DataType inferred = legacy.getResultType(legacy.bindNestedAggregate());
+ return new AggStateType(legacy.functionName, inputs,
legacy.subTypeNullables, legacy.returnNullable,
+ inferred, true);
+ }
+
+ private AggregateFunction bindNestedAggregate() {
+ ImmutableList.Builder<Expression> arguments =
ImmutableList.builderWithExpectedSize(subTypes.size());
+ for (int i = 0; i < subTypes.size(); i++) {
+ arguments.add(new SlotReference("input" + i, subTypes.get(i),
subTypeNullables.get(i)));
+ }
+ List<Expression> inputs = arguments.build();
+ FunctionBuilder builder =
Env.getCurrentEnv().getFunctionRegistry().findFunctionBuilder(functionName,
inputs);
Review Comment:
[P2] Bind state signatures to the builtin aggregate builder
With a legal alias such as `CREATE ALIAS FUNCTION sum(INT) WITH PARAMETER(x)
AS abs(x)` and `prefer_udf_over_builtin=true`, this lookup selects the alias
instead of the builtin SUM. `AliasUdfBuilder.build()` returns the scalar `abs`
expression, so the following cast to `AggregateFunction` throws while analyzing
`agg_state<sum(int)>`; the new eager legacy-type conversion also makes scans of
existing SUM state columns fail. Resolve the canonical builtin aggregate here,
as the reserved `sum_state`/`sum_merge` combinator lookup already does, so a
session's UDF precedence cannot change a stored state's identity.
--
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]