This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new 40567b5d699 [fix](nereids)support group_concat with distinct and order by (#38871) 40567b5d699 is described below commit 40567b5d699c630f1d0b075c8c5fc023fd379141 Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Mon Aug 5 18:23:55 2024 +0800 [fix](nereids)support group_concat with distinct and order by (#38871) ## Proposed changes pick from master https://github.com/apache/doris/pull/38080 <!--Describe your changes.--> --- .../glue/translator/ExpressionTranslator.java | 4 +- .../doris/nereids/parser/LogicalPlanBuilder.java | 25 +---- .../properties/ChildrenPropertiesRegulator.java | 7 +- .../nereids/rules/analysis/CheckAnalysis.java | 3 +- .../nereids/rules/analysis/ExpressionAnalyzer.java | 1 + .../nereids/rules/analysis/NormalizeAggregate.java | 14 ++- .../rules/implementation/AggregateStrategies.java | 5 +- .../trees/expressions/WindowExpression.java | 6 ++ .../functions/AggCombinerFunctionBuilder.java | 4 + .../trees/expressions/functions/BoundFunction.java | 17 ++++ .../functions/agg/AggregateFunction.java | 4 + .../expressions/functions/agg/GroupConcat.java | 101 +++++++------------- .../functions/agg/MultiDistinctCount.java | 35 ++++--- .../functions/agg/MultiDistinctGroupConcat.java | 83 ++++++++--------- .../functions/agg/MultiDistinctSum.java | 28 +++++- .../functions/agg/MultiDistinctSum0.java | 23 ++++- .../functions/agg/MultiDistinction.java | 1 + .../functions/combinator/StateCombinator.java | 8 ++ .../nereids/trees/plans/algebra/Aggregate.java | 10 ++ .../nereids_p0/aggregate/agg_group_concat.groovy | 102 +++++++++++++++++++++ .../group_concat/test_group_concat.groovy | 18 +--- .../query_p0/group_concat/test_group_concat.groovy | 19 +--- 22 files changed, 327 insertions(+), 191 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java index b5dabeefb94..0410ba997c9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java @@ -624,7 +624,9 @@ public class ExpressionTranslator extends DefaultExpressionVisitor<Expr, PlanTra @Override public Expr visitStateCombinator(StateCombinator combinator, PlanTranslatorContext context) { - List<Expr> arguments = combinator.getArguments().stream().map(arg -> arg.accept(this, context)) + List<Expr> arguments = combinator.getArguments().stream().map(arg -> arg instanceof OrderExpression + ? translateOrderExpression((OrderExpression) arg, context).getExpr() + : arg.accept(this, context)) .collect(Collectors.toList()); return Function.convertToStateCombinator( new FunctionCallExpr(visitAggregateFunction(combinator.getNestedFunction(), context).getFn(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index 9ffe16d0f81..309b98bc906 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -274,7 +274,6 @@ import org.apache.doris.nereids.trees.expressions.WindowExpression; import org.apache.doris.nereids.trees.expressions.WindowFrame; import org.apache.doris.nereids.trees.expressions.functions.Function; import org.apache.doris.nereids.trees.expressions.functions.agg.Count; -import org.apache.doris.nereids.trees.expressions.functions.agg.GroupConcat; import org.apache.doris.nereids.trees.expressions.functions.scalar.Array; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRange; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeDayUnit; @@ -2096,11 +2095,10 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { return ParserUtils.withOrigin(ctx, () -> { String functionName = ctx.functionIdentifier().functionNameIdentifier().getText(); boolean isDistinct = ctx.DISTINCT() != null; - List<Expression> params = visit(ctx.expression(), Expression.class); + List<Expression> params = Lists.newArrayList(); + params.addAll(visit(ctx.expression(), Expression.class)); List<OrderKey> orderKeys = visit(ctx.sortItem(), OrderKey.class); - if (!orderKeys.isEmpty()) { - return parseFunctionWithOrderKeys(functionName, isDistinct, params, orderKeys, ctx); - } + params.addAll(orderKeys.stream().map(OrderExpression::new).collect(Collectors.toList())); List<UnboundStar> unboundStars = ExpressionUtils.collectAll(params, UnboundStar.class::isInstance); if (!unboundStars.isEmpty()) { @@ -3471,23 +3469,6 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { return new StructField(ctx.identifier().getText(), typedVisit(ctx.dataType()), true, comment); } - private Expression parseFunctionWithOrderKeys(String functionName, boolean isDistinct, - List<Expression> params, List<OrderKey> orderKeys, ParserRuleContext ctx) { - if (functionName.equalsIgnoreCase("group_concat")) { - OrderExpression[] orderExpressions = orderKeys.stream() - .map(OrderExpression::new) - .toArray(OrderExpression[]::new); - if (params.size() == 1) { - return new GroupConcat(isDistinct, params.get(0), orderExpressions); - } else if (params.size() == 2) { - return new GroupConcat(isDistinct, params.get(0), params.get(1), orderExpressions); - } else { - throw new ParseException("group_concat requires one or two parameters: " + params, ctx); - } - } - throw new ParseException("Unsupported function with order expressions" + ctx.getText(), ctx); - } - private String parseConstant(ConstantContext context) { Object constant = visit(context); if (constant instanceof Literal && ((Literal) constant).isStringLikeLiteral()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java index 10b52dee899..9e795486f7a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java @@ -159,12 +159,15 @@ public class ChildrenPropertiesRegulator extends PlanVisitor<Boolean, Void> { distinctChildColumns, ShuffleType.REQUIRE); if ((!groupByColumns.isEmpty() && distributionSpecHash.satisfy(groupByRequire)) || (groupByColumns.isEmpty() && distributionSpecHash.satisfy(distinctChildRequire))) { - return false; + if (!agg.mustUseMultiDistinctAgg()) { + return false; + } } } // if distinct without group by key, we prefer three or four stage distinct agg // because the second phase of multi-distinct only have one instance, and it is slow generally. - if (agg.getOutputExpressions().size() == 1 && agg.getGroupByExpressions().isEmpty()) { + if (agg.getOutputExpressions().size() == 1 && agg.getGroupByExpressions().isEmpty() + && !agg.mustUseMultiDistinctAgg()) { return false; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAnalysis.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAnalysis.java index 64fd14019bb..7ca8637446b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAnalysis.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAnalysis.java @@ -21,6 +21,7 @@ import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.rules.Rule; import org.apache.doris.nereids.rules.RuleType; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.OrderExpression; import org.apache.doris.nereids.trees.expressions.WindowExpression; import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; import org.apache.doris.nereids.trees.expressions.functions.generator.TableGeneratingFunction; @@ -148,7 +149,7 @@ public class CheckAnalysis implements AnalysisRuleFactory { continue; } for (int i = 1; i < func.arity(); i++) { - if (!func.child(i).getInputSlots().isEmpty()) { + if (!func.child(i).getInputSlots().isEmpty() && !(func.child(i) instanceof OrderExpression)) { // think about group_concat(distinct col_1, ',') distinctMultiColumns = true; break; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java index fc9e1385b59..6dd0963b2fa 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java @@ -403,6 +403,7 @@ public class ExpressionAnalyzer extends SubExprAnalyzer<ExpressionRewriteContext } Pair<? extends Expression, ? extends BoundFunction> buildResult = builder.build(functionName, arguments); + buildResult.second.checkOrderExprIsValid(); Optional<SqlCacheContext> sqlCacheContext = Optional.empty(); if (wantToParseSqlFromSqlCache) { StatementContext statementContext = context.cascadesContext.getStatementContext(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java index d09204403f9..e5ebee120a3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java @@ -26,12 +26,14 @@ import org.apache.doris.nereids.trees.expressions.Alias; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.OrderExpression; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.expressions.SlotNotFromChildren; import org.apache.doris.nereids.trees.expressions.SlotReference; import org.apache.doris.nereids.trees.expressions.SubqueryExpr; import org.apache.doris.nereids.trees.expressions.WindowExpression; import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; +import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinction; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate; @@ -54,6 +56,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * normalize aggregate's group keys and AggregateFunction's child to SlotReference @@ -170,6 +173,7 @@ public class NormalizeAggregate implements RewriteRuleFactory, NormalizeToSlot { // should not push down literal under aggregate // e.g. group_concat(distinct xxx, ','), the ',' literal show stay in aggregate .filter(arg -> !(arg instanceof Literal)) + .flatMap(arg -> arg instanceof OrderExpression ? arg.getInputSlots().stream() : Stream.of(arg)) .collect( Collectors.groupingBy( child -> !(child instanceof SlotReference), @@ -255,7 +259,15 @@ public class NormalizeAggregate implements RewriteRuleFactory, NormalizeToSlot { normalizedAggFuncsToSlotContext.pushDownToNamedExpression(normalizedAggFuncs) ); // create new agg node - ImmutableList<NamedExpression> normalizedAggOutput = normalizedAggOutputBuilder.build(); + ImmutableList<NamedExpression> aggOutput = normalizedAggOutputBuilder.build(); + ImmutableList.Builder<NamedExpression> newAggOutputBuilder + = ImmutableList.builderWithExpectedSize(aggOutput.size()); + for (NamedExpression output : aggOutput) { + Expression rewrittenExpr = output.rewriteDownShortCircuit( + e -> e instanceof MultiDistinction ? ((MultiDistinction) e).withMustUseMultiDistinctAgg(true) : e); + newAggOutputBuilder.add((NamedExpression) rewrittenExpr); + } + ImmutableList<NamedExpression> normalizedAggOutput = newAggOutputBuilder.build(); LogicalAggregate<?> newAggregate = aggregate.withNormalized(normalizedGroupExprs, normalizedAggOutput, bottomPlan); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java index 96b7507f3dc..3f95a1b4384 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java @@ -40,6 +40,7 @@ import org.apache.doris.nereids.trees.expressions.Cast; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.IsNull; import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.OrderExpression; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.expressions.SlotReference; import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait; @@ -296,6 +297,7 @@ public class AggregateStrategies implements ImplementationRuleFactory { RuleType.THREE_PHASE_AGGREGATE_WITH_DISTINCT.build( basePattern .when(agg -> agg.getDistinctArguments().size() == 1) + .whenNot(agg -> agg.mustUseMultiDistinctAgg()) .thenApplyMulti(ctx -> threePhaseAggregateWithDistinct(ctx.root, ctx.connectContext)) ), /* @@ -319,6 +321,7 @@ public class AggregateStrategies implements ImplementationRuleFactory { basePattern .when(agg -> agg.getDistinctArguments().size() == 1) .when(agg -> agg.getGroupByExpressions().isEmpty()) + .whenNot(agg -> agg.mustUseMultiDistinctAgg()) .thenApplyMulti(ctx -> { Function<List<Expression>, RequireProperties> secondPhaseRequireDistinctHash = groupByAndDistinct -> RequireProperties.of( @@ -1940,7 +1943,7 @@ public class AggregateStrategies implements ImplementationRuleFactory { } for (int i = 1; i < func.arity(); i++) { // think about group_concat(distinct col_1, ',') - if (!func.child(i).getInputSlots().isEmpty()) { + if (!(func.child(i) instanceof OrderExpression) && !func.child(i).getInputSlots().isEmpty()) { return false; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WindowExpression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WindowExpression.java index d9fa8d36ddd..457c6d3a645 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WindowExpression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WindowExpression.java @@ -124,6 +124,12 @@ public class WindowExpression extends Expression { .orElseGet(() -> new WindowExpression(function, partitionKeys, orderKeys)); } + public WindowExpression withFunctionPartitionKeysOrderKeys(Expression function, + List<Expression> partitionKeys, List<OrderExpression> orderKeys) { + return windowFrame.map(frame -> new WindowExpression(function, partitionKeys, orderKeys, frame)) + .orElseGet(() -> new WindowExpression(function, partitionKeys, orderKeys)); + } + @Override public boolean nullable() { return function.nullable(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/AggCombinerFunctionBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/AggCombinerFunctionBuilder.java index 28b32628741..76a3c36ffe5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/AggCombinerFunctionBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/AggCombinerFunctionBuilder.java @@ -127,6 +127,10 @@ public class AggCombinerFunctionBuilder extends FunctionBuilder { String nestedName = getNestedName(name); if (combinatorSuffix.equalsIgnoreCase(STATE)) { AggregateFunction nestedFunction = buildState(nestedName, arguments); + // distinct will be passed as 1st boolean true arg. remove it + if (!arguments.isEmpty() && arguments.get(0) instanceof Boolean && (Boolean) arguments.get(0)) { + arguments = arguments.subList(1, arguments.size()); + } return Pair.of(new StateCombinator((List<Expression>) arguments, nestedFunction), nestedFunction); } else if (combinatorSuffix.equalsIgnoreCase(MERGE)) { AggregateFunction nestedFunction = buildMergeOrUnion(nestedName, arguments); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/BoundFunction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/BoundFunction.java index 06acb4c5782..c0f4ddc4404 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/BoundFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/BoundFunction.java @@ -18,8 +18,12 @@ package org.apache.doris.nereids.trees.expressions.functions; import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.exceptions.UnboundException; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.OrderExpression; +import org.apache.doris.nereids.trees.expressions.functions.agg.GroupConcat; +import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctGroupConcat; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.util.Utils; @@ -98,4 +102,17 @@ public abstract class BoundFunction extends Function implements ComputeSignature .collect(Collectors.joining(", ")); return getName() + "(" + args + ")"; } + + /** + * checkOrderExprIsValid. + */ + public void checkOrderExprIsValid() { + for (Expression child : children) { + if (child instanceof OrderExpression + && !(this instanceof GroupConcat || this instanceof MultiDistinctGroupConcat)) { + throw new AnalysisException( + String.format("%s doesn't support order by expression", getName())); + } + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AggregateFunction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AggregateFunction.java index e45d3fb4da8..58b9d0274dd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AggregateFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AggregateFunction.java @@ -134,4 +134,8 @@ public abstract class AggregateFunction extends BoundFunction implements Expects public List<Expression> getDistinctArguments() { return distinct ? getArguments() : ImmutableList.of(); } + + public boolean mustUseMultiDistinctAgg() { + return false; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java index d8b6646cff7..2505329b2fe 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java @@ -52,57 +52,30 @@ public class GroupConcat extends NullableAggregateFunction /** * constructor with 1 argument. */ - public GroupConcat(boolean distinct, boolean alwaysNullable, Expression arg, OrderExpression... orders) { - super("group_concat", distinct, alwaysNullable, ExpressionUtils.mergeArguments(arg, orders)); - this.nonOrderArguments = 1; - checkArguments(); + public GroupConcat(boolean distinct, boolean alwaysNullable, Expression arg, Expression... others) { + this(distinct, alwaysNullable, ExpressionUtils.mergeArguments(arg, others)); } /** * constructor with 1 argument. */ - public GroupConcat(boolean distinct, Expression arg, OrderExpression... orders) { - this(distinct, false, arg, orders); + public GroupConcat(boolean distinct, Expression arg, Expression... others) { + this(distinct, false, arg, others); } /** * constructor with 1 argument, use for function search. */ - public GroupConcat(Expression arg, OrderExpression... orders) { - this(false, arg, orders); - } - - /** - * constructor with 2 arguments. - */ - public GroupConcat(boolean distinct, boolean alwaysNullable, - Expression arg0, Expression arg1, OrderExpression... orders) { - super("group_concat", distinct, alwaysNullable, ExpressionUtils.mergeArguments(arg0, arg1, orders)); - this.nonOrderArguments = 2; - checkArguments(); - } - - /** - * constructor with 2 arguments. - */ - public GroupConcat(boolean distinct, Expression arg0, Expression arg1, OrderExpression... orders) { - this(distinct, false, arg0, arg1, orders); - } - - /** - * constructor with 2 arguments, use for function search. - */ - public GroupConcat(Expression arg0, Expression arg1, OrderExpression... orders) { - this(false, arg0, arg1, orders); + public GroupConcat(Expression arg, Expression... others) { + this(false, arg, others); } /** * constructor for always nullable. */ - public GroupConcat(boolean distinct, boolean alwaysNullable, int nonOrderArguments, List<Expression> args) { + public GroupConcat(boolean distinct, boolean alwaysNullable, List<Expression> args) { super("group_concat", distinct, alwaysNullable, args); - this.nonOrderArguments = nonOrderArguments; - checkArguments(); + this.nonOrderArguments = findOrderExprIndex(children); } @Override @@ -139,7 +112,7 @@ public class GroupConcat extends NullableAggregateFunction @Override public GroupConcat withAlwaysNullable(boolean alwaysNullable) { - return new GroupConcat(distinct, alwaysNullable, nonOrderArguments, children); + return new GroupConcat(distinct, alwaysNullable, children); } /** @@ -147,30 +120,7 @@ public class GroupConcat extends NullableAggregateFunction */ @Override public GroupConcat withDistinctAndChildren(boolean distinct, List<Expression> children) { - Preconditions.checkArgument(children().size() >= 1); - boolean foundOrderExpr = false; - int firstOrderExrIndex = 0; - for (int i = 0; i < children.size(); i++) { - Expression child = children.get(i); - if (child instanceof OrderExpression) { - foundOrderExpr = true; - } else if (!foundOrderExpr) { - firstOrderExrIndex++; - } else { - throw new AnalysisException("invalid group_concat parameters: " + children); - } - } - - List<OrderExpression> orders = (List) children.subList(firstOrderExrIndex, children.size()); - if (firstOrderExrIndex == 1) { - return new GroupConcat(distinct, alwaysNullable, - children.get(0), orders.toArray(new OrderExpression[0])); - } else if (firstOrderExrIndex == 2) { - return new GroupConcat(distinct, alwaysNullable, - children.get(0), children.get(1), orders.toArray(new OrderExpression[0])); - } else { - throw new AnalysisException("group_concat requires one or two parameters: " + children); - } + return new GroupConcat(distinct, alwaysNullable, children); } @Override @@ -186,15 +136,34 @@ public class GroupConcat extends NullableAggregateFunction public MultiDistinctGroupConcat convertToMultiDistinct() { Preconditions.checkArgument(distinct, "can't convert to multi_distinct_group_concat because there is no distinct args"); - return new MultiDistinctGroupConcat(alwaysNullable, nonOrderArguments, children); + return new MultiDistinctGroupConcat(alwaysNullable, children); } - // TODO: because of current be's limitation, we have to thow exception for now - // remove this after be support new method of multi distinct functions - private void checkArguments() { - if (isDistinct() && children().stream().anyMatch(expression -> expression instanceof OrderExpression)) { + @Override + public boolean mustUseMultiDistinctAgg() { + return distinct && children.stream().anyMatch(OrderExpression.class::isInstance); + } + + private int findOrderExprIndex(List<Expression> children) { + Preconditions.checkArgument(children().size() >= 1, "children's size should >= 1"); + boolean foundOrderExpr = false; + int firstOrderExrIndex = 0; + for (int i = 0; i < children.size(); i++) { + Expression child = children.get(i); + if (child instanceof OrderExpression) { + foundOrderExpr = true; + } else if (!foundOrderExpr) { + firstOrderExrIndex++; + } else { + throw new AnalysisException( + "invalid multi_distinct_group_concat parameters: " + children); + } + } + + if (firstOrderExrIndex > 2) { throw new AnalysisException( - "group_concat don't support using distinct with order by together"); + "multi_distinct_group_concat requires one or two parameters: " + children); } + return firstOrderExrIndex; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java index 3244ae563dc..7287fc5c554 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java @@ -18,6 +18,7 @@ package org.apache.doris.nereids.trees.expressions.functions.agg; import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.analyzer.Unbound; import org.apache.doris.nereids.trees.expressions.Cast; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; @@ -36,35 +37,35 @@ import java.util.List; /** MultiDistinctCount */ public class MultiDistinctCount extends AggregateFunction implements AlwaysNotNullable, ExplicitlyCastableSignature, MultiDistinction { - public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE).varArgs(AnyDataType.INSTANCE_WITHOUT_INDEX) ); + private final boolean mustUseMultiDistinctAgg; // MultiDistinctCount is created in AggregateStrategies phase // can't change getSignatures to use type coercion rule to add a cast expr // because AggregateStrategies phase is after type coercion public MultiDistinctCount(Expression arg0, Expression... varArgs) { - super("multi_distinct_count", true, ExpressionUtils.mergeArguments(arg0, varArgs).stream() - .map(arg -> arg.getDataType() instanceof DateLikeType ? new Cast(arg, BigIntType.INSTANCE) : arg) - .collect(ImmutableList.toImmutableList())); + this(false, arg0, varArgs); } public MultiDistinctCount(boolean distinct, Expression arg0, Expression... varArgs) { - super("multi_distinct_count", distinct, ExpressionUtils.mergeArguments(arg0, varArgs).stream() - .map(arg -> arg.getDataType() instanceof DateLikeType ? new Cast(arg, BigIntType.INSTANCE) : arg) + this(false, false, ExpressionUtils.mergeArguments(arg0, varArgs)); + } + + private MultiDistinctCount(boolean mustUseMultiDistinctAgg, boolean distinct, List<Expression> children) { + super("multi_distinct_count", false, children + .stream() + .map(arg -> !(arg instanceof Unbound) && arg.getDataType() instanceof DateLikeType + ? new Cast(arg, BigIntType.INSTANCE) : arg) .collect(ImmutableList.toImmutableList())); + this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } @Override public MultiDistinctCount withDistinctAndChildren(boolean distinct, List<Expression> children) { Preconditions.checkArgument(children.size() > 0); - if (children.size() > 1) { - return new MultiDistinctCount(distinct, children.get(0), - children.subList(1, children.size()).toArray(new Expression[0])); - } else { - return new MultiDistinctCount(distinct, children.get(0)); - } + return new MultiDistinctCount(mustUseMultiDistinctAgg, distinct, children); } @Override @@ -76,4 +77,14 @@ public class MultiDistinctCount extends AggregateFunction public List<FunctionSignature> getSignatures() { return SIGNATURES; } + + @Override + public boolean mustUseMultiDistinctAgg() { + return mustUseMultiDistinctAgg; + } + + @Override + public Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg) { + return new MultiDistinctCount(mustUseMultiDistinctAgg, false, children); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java index d400315ad4c..30bce48d67c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java @@ -37,7 +37,6 @@ import java.util.List; /** MultiDistinctGroupConcat */ public class MultiDistinctGroupConcat extends NullableAggregateFunction implements ExplicitlyCastableSignature, MultiDistinction { - public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT), FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT, @@ -57,49 +56,31 @@ public class MultiDistinctGroupConcat extends NullableAggregateFunction FunctionSignature.ret(CharType.SYSTEM_DEFAULT).varArgs(CharType.SYSTEM_DEFAULT, CharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE_WITHOUT_INDEX)); - private final int nonOrderArguments; + private final boolean mustUseMultiDistinctAgg; /** - * constructor with 1 argument. + * constructor with 1 argument with other arguments. */ - public MultiDistinctGroupConcat(boolean alwaysNullable, Expression arg, - OrderExpression... orders) { - super("multi_distinct_group_concat", true, alwaysNullable, - ExpressionUtils.mergeArguments(arg, orders)); - this.nonOrderArguments = 1; + public MultiDistinctGroupConcat(Expression arg, Expression... others) { + this(false, arg, others); } /** - * constructor with 1 argument. + * constructor with argument list. */ - public MultiDistinctGroupConcat(Expression arg, OrderExpression... orders) { - this(false, arg, orders); + public MultiDistinctGroupConcat(boolean alwaysNullable, List<Expression> args) { + this(false, alwaysNullable, args); } - /** - * constructor with 2 arguments. - */ - public MultiDistinctGroupConcat(boolean alwaysNullable, Expression arg0, - Expression arg1, OrderExpression... orders) { - super("multi_distinct_group_concat", true, alwaysNullable, - ExpressionUtils.mergeArguments(arg0, arg1, orders)); - this.nonOrderArguments = 2; + private MultiDistinctGroupConcat(boolean alwaysNullable, Expression arg, + Expression... others) { + this(alwaysNullable, ExpressionUtils.mergeArguments(arg, others)); } - /** - * constructor with 2 arguments. - */ - public MultiDistinctGroupConcat(Expression arg0, Expression arg1, OrderExpression... orders) { - this(false, arg0, arg1, orders); - } - - /** - * constructor for always nullable. - */ - public MultiDistinctGroupConcat(boolean alwaysNullable, int nonOrderArguments, - List<Expression> args) { - super("multi_distinct_group_concat", true, alwaysNullable, args); - this.nonOrderArguments = nonOrderArguments; + private MultiDistinctGroupConcat(boolean mustUseMultiDistinctAgg, boolean alwaysNullable, List<Expression> args) { + super("multi_distinct_group_concat", false, alwaysNullable, args); + checkArguments(children); + this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } @Override @@ -110,7 +91,7 @@ public class MultiDistinctGroupConcat extends NullableAggregateFunction @Override public MultiDistinctGroupConcat withAlwaysNullable(boolean alwaysNullable) { - return new MultiDistinctGroupConcat(alwaysNullable, nonOrderArguments, children); + return new MultiDistinctGroupConcat(mustUseMultiDistinctAgg, alwaysNullable, children); } /** @@ -118,7 +99,22 @@ public class MultiDistinctGroupConcat extends NullableAggregateFunction */ @Override public MultiDistinctGroupConcat withDistinctAndChildren(boolean distinct, List<Expression> children) { - Preconditions.checkArgument(children().size() >= 1); + checkArguments(children); + return new MultiDistinctGroupConcat(mustUseMultiDistinctAgg, alwaysNullable, children); + } + + @Override + public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { + return visitor.visitMultiDistinctGroupConcat(this, context); + } + + @Override + public List<FunctionSignature> getSignatures() { + return SIGNATURES; + } + + private void checkArguments(List<Expression> children) { + Preconditions.checkArgument(children().size() >= 1, "children's size should >= 1"); boolean foundOrderExpr = false; int firstOrderExrIndex = 0; for (int i = 0; i < children.size(); i++) { @@ -133,26 +129,19 @@ public class MultiDistinctGroupConcat extends NullableAggregateFunction } } - List<OrderExpression> orders = (List) children.subList(firstOrderExrIndex, children.size()); - if (firstOrderExrIndex == 1) { - return new MultiDistinctGroupConcat(alwaysNullable, children.get(0), - orders.toArray(new OrderExpression[0])); - } else if (firstOrderExrIndex == 2) { - return new MultiDistinctGroupConcat(alwaysNullable, children.get(0), - children.get(1), orders.toArray(new OrderExpression[0])); - } else { + if (firstOrderExrIndex > 2) { throw new AnalysisException( "multi_distinct_group_concat requires one or two parameters: " + children); } } @Override - public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { - return visitor.visitMultiDistinctGroupConcat(this, context); + public boolean mustUseMultiDistinctAgg() { + return mustUseMultiDistinctAgg || children.stream().anyMatch(OrderExpression.class::isInstance); } @Override - public List<FunctionSignature> getSignatures() { - return SIGNATURES; + public Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg) { + return new MultiDistinctGroupConcat(mustUseMultiDistinctAgg, alwaysNullable, children); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java index 212140fed93..538734eb139 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java @@ -43,16 +43,24 @@ public class MultiDistinctSum extends NullableAggregateFunction implements Unary FunctionSignature.ret(BigIntType.INSTANCE).varArgs(LargeIntType.INSTANCE) ); + private final boolean mustUseMultiDistinctAgg; + public MultiDistinctSum(Expression arg0) { - super("multi_distinct_sum", true, false, arg0); + this(false, arg0); } public MultiDistinctSum(boolean distinct, Expression arg0) { - super("multi_distinct_sum", true, false, arg0); + this(false, false, arg0); } public MultiDistinctSum(boolean distinct, boolean alwaysNullable, Expression arg0) { - super("multi_distinct_sum", true, alwaysNullable, arg0); + this(false, false, alwaysNullable, arg0); + } + + private MultiDistinctSum(boolean mustUseMultiDistinctAgg, boolean distinct, + boolean alwaysNullable, Expression arg0) { + super("multi_distinct_sum", false, alwaysNullable, arg0); + this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } @Override @@ -74,17 +82,27 @@ public class MultiDistinctSum extends NullableAggregateFunction implements Unary @Override public NullableAggregateFunction withAlwaysNullable(boolean alwaysNullable) { - return new MultiDistinctSum(distinct, alwaysNullable, children.get(0)); + return new MultiDistinctSum(mustUseMultiDistinctAgg, distinct, alwaysNullable, children.get(0)); } @Override public MultiDistinctSum withDistinctAndChildren(boolean distinct, List<Expression> children) { Preconditions.checkArgument(children.size() == 1); - return new MultiDistinctSum(distinct, children.get(0)); + return new MultiDistinctSum(mustUseMultiDistinctAgg, distinct, alwaysNullable, children.get(0)); } @Override public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { return visitor.visitMultiDistinctSum(this, context); } + + @Override + public boolean mustUseMultiDistinctAgg() { + return mustUseMultiDistinctAgg; + } + + @Override + public Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg) { + return new MultiDistinctSum(mustUseMultiDistinctAgg, false, alwaysNullable, children.get(0)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java index 89999258713..37ecd8f2a3d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java @@ -44,12 +44,19 @@ public class MultiDistinctSum0 extends AggregateFunction implements UnaryExpress FunctionSignature.ret(BigIntType.INSTANCE).varArgs(LargeIntType.INSTANCE) ); + private final boolean mustUseMultiDistinctAgg; + public MultiDistinctSum0(Expression arg0) { - super("multi_distinct_sum0", true, arg0); + this(false, arg0); } public MultiDistinctSum0(boolean distinct, Expression arg0) { - super("multi_distinct_sum0", true, arg0); + this(false, false, arg0); + } + + private MultiDistinctSum0(boolean mustUseMultiDistinctAgg, boolean distinct, Expression arg0) { + super("multi_distinct_sum0", false, arg0); + this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } @Override @@ -72,11 +79,21 @@ public class MultiDistinctSum0 extends AggregateFunction implements UnaryExpress @Override public MultiDistinctSum0 withDistinctAndChildren(boolean distinct, List<Expression> children) { Preconditions.checkArgument(children.size() == 1); - return new MultiDistinctSum0(distinct, children.get(0)); + return new MultiDistinctSum0(mustUseMultiDistinctAgg, distinct, children.get(0)); } @Override public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { return visitor.visitMultiDistinctSum0(this, context); } + + @Override + public boolean mustUseMultiDistinctAgg() { + return mustUseMultiDistinctAgg; + } + + @Override + public Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg) { + return new MultiDistinctSum0(mustUseMultiDistinctAgg, false, children.get(0)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinction.java index ab8842f7301..2709c4bcfe9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinction.java @@ -24,4 +24,5 @@ import org.apache.doris.nereids.trees.expressions.Expression; * base class of multi-distinct agg function */ public interface MultiDistinction extends TreeNode<Expression> { + Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/StateCombinator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/StateCombinator.java index 99f824b3238..ef1f66819e8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/StateCombinator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/StateCombinator.java @@ -21,7 +21,9 @@ import org.apache.doris.catalog.Env; import org.apache.doris.catalog.FunctionRegistry; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.common.Pair; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.OrderExpression; import org.apache.doris.nereids.trees.expressions.functions.AggCombinerFunctionBuilder; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; import org.apache.doris.nereids.trees.expressions.functions.BoundFunction; @@ -55,6 +57,12 @@ public class StateCombinator extends ScalarFunction */ public StateCombinator(List<Expression> arguments, AggregateFunction nested) { super(nested.getName() + AggCombinerFunctionBuilder.STATE_SUFFIX, arguments); + for (Expression arg : arguments) { + if (arg instanceof OrderExpression) { + throw new AnalysisException(String + .format("%s_state doesn't support order by expression", nested.getName())); + } + } this.nested = Objects.requireNonNull(nested, "nested can not be null"); this.returnType = new AggStateType(nested.getName(), arguments.stream().map(arg -> { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Aggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Aggregate.java index acce8eef309..d29f7f8daea 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Aggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Aggregate.java @@ -90,4 +90,14 @@ public interface Aggregate<CHILD_TYPE extends Plan> extends UnaryPlan<CHILD_TYPE } return hasDistinctArguments.get(); } + + /** mustUseMultiDistinctAgg */ + default boolean mustUseMultiDistinctAgg() { + for (AggregateFunction aggregateFunction : getAggregateFunctions()) { + if (aggregateFunction.mustUseMultiDistinctAgg()) { + return true; + } + } + return false; + } } diff --git a/regression-test/suites/nereids_p0/aggregate/agg_group_concat.groovy b/regression-test/suites/nereids_p0/aggregate/agg_group_concat.groovy new file mode 100644 index 00000000000..9b229c30462 --- /dev/null +++ b/regression-test/suites/nereids_p0/aggregate/agg_group_concat.groovy @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +suite("agg_group_concat") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + sql "set disable_nereids_rules=PRUNE_EMPTY_PARTITION" + + sql "drop table if exists agg_group_concat_table" + + sql """ + CREATE TABLE IF NOT EXISTS `agg_group_concat_table` ( + `kint` int(11) not null, + `kbint` int(11) not null, + `kstr` string not null, + `kstr2` string not null, + `kastr` array<string> not null + ) engine=olap + DISTRIBUTED BY HASH(`kint`) BUCKETS 4 + properties("replication_num" = "1"); + """ + + sql """ + INSERT INTO `agg_group_concat_table` VALUES + ( 1, 1, 'string1', 'string3', ['s11', 's12', 's13'] ), + ( 1, 2, 'string2', 'string1', ['s21', 's22', 's23'] ), + ( 2, 3, 'string3', 'string2', ['s31', 's32', 's33'] ), + ( 1, 1, 'string1', 'string3', ['s11', 's12', 's13'] ), + ( 1, 2, 'string2', 'string1', ['s21', 's22', 's23'] ), + ( 2, 3, 'string3', 'string2', ['s31', 's32', 's33'] ); + """ + + sql """select group_concat_state(kstr) from agg_group_concat_table;""" + sql """select group_concat_union(group_concat_state(kstr)) from agg_group_concat_table;""" + sql """select group_concat_merge(group_concat_state(kstr)) from agg_group_concat_table;""" + + sql """select group_concat_state(distinct kstr) from agg_group_concat_table;""" + sql """select group_concat_union(group_concat_state(kstr)) from agg_group_concat_table;""" + sql """select group_concat_merge(group_concat_state(kstr)) from agg_group_concat_table;""" + + sql """select multi_distinct_group_concat_state(kstr) from agg_group_concat_table;""" + sql """select multi_distinct_group_concat_union(multi_distinct_group_concat_state(kstr)) from agg_group_concat_table;""" + sql """select multi_distinct_group_concat_merge(multi_distinct_group_concat_state(kstr)) from agg_group_concat_table;""" + + test { + sql "select group_concat_state(kstr order by kint) from agg_group_concat_table;" + exception "doesn't support order by expression" + } + + test { + sql "select multi_distinct_group_concat_state(kstr order by kint) from agg_group_concat_table;" + exception "doesn't support order by expression" + } + + test { + sql "select count(kstr order by kint) from agg_group_concat_table;" + exception "doesn't support order by expression" + } + + sql """select multi_distinct_sum(kint) from agg_group_concat_table;""" + + sql """select group_concat(distinct kstr order by kint), group_concat(distinct kstr2 order by kbint) from agg_group_concat_table;""" + sql """select multi_distinct_group_concat(kstr order by kint), multi_distinct_group_concat(kstr2 order by kbint) from agg_group_concat_table;""" + sql """select group_concat(distinct kstr), group_concat(distinct kstr2) from agg_group_concat_table;""" + sql """select multi_distinct_group_concat(kstr), multi_distinct_group_concat(kstr2) from agg_group_concat_table;""" + + sql """select group_concat(distinct kstr order by kint), group_concat(distinct kstr2 order by kbint) from agg_group_concat_table group by kbint;""" + sql """select multi_distinct_group_concat(kstr order by kint), multi_distinct_group_concat(kstr2 order by kbint) from agg_group_concat_table group by kbint;""" + sql """select group_concat(distinct kstr), group_concat(distinct kstr2) from agg_group_concat_table group by kbint;""" + sql """select multi_distinct_group_concat(kstr), multi_distinct_group_concat(kstr2) from agg_group_concat_table group by kbint;""" + + sql """select group_concat(distinct kstr order by kbint), group_concat(distinct kstr2 order by kint) from agg_group_concat_table group by kint;""" + sql """select multi_distinct_group_concat(kstr order by kbint), multi_distinct_group_concat(kstr2 order by kint) from agg_group_concat_table group by kint;""" + sql """select group_concat(distinct kstr), group_concat(distinct kstr2) from agg_group_concat_table group by kint;""" + sql """select multi_distinct_group_concat(kstr), multi_distinct_group_concat(kstr2) from agg_group_concat_table group by kint;""" + + sql """select group_concat(distinct kstr order by kint), group_concat(kstr2 order by kbint) from agg_group_concat_table;""" + sql """select multi_distinct_group_concat(kstr order by kint), group_concat(kstr2 order by kbint) from agg_group_concat_table;""" + sql """select group_concat(distinct kstr), group_concat(kstr2) from agg_group_concat_table;""" + sql """select multi_distinct_group_concat(kstr), group_concat(kstr2) from agg_group_concat_table;""" + + sql """select group_concat(distinct kstr order by kint), group_concat(kstr2 order by kbint) from agg_group_concat_table group by kbint;""" + sql """select multi_distinct_group_concat(kstr order by kint), group_concat(kstr2 order by kbint) from agg_group_concat_table group by kbint;""" + sql """select group_concat(distinct kstr), group_concat(kstr2) from agg_group_concat_table group by kbint;""" + sql """select multi_distinct_group_concat(kstr), group_concat(kstr2) from agg_group_concat_table group by kbint;""" +} \ No newline at end of file diff --git a/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy b/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy index ecb4126afa1..d54d93bb417 100644 --- a/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy +++ b/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy @@ -34,21 +34,9 @@ suite("test_group_concat") { SELECT abs(k3), group_concat(cast(abs(k2) as varchar), ":" order by abs(k2), k1) FROM nereids_test_query_db.baseall group by abs(k3) order by abs(k3) """ - test { - sql"""SELECT abs(k3), group_concat(distinct cast(abs(k2) as char) order by abs(k1), k2) FROM nereids_test_query_db.baseall group by abs(k3) order by abs(k3);""" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } - } - - test { - sql"""SELECT abs(k3), group_concat(distinct cast(abs(k2) as char), ":" order by abs(k1), k2) FROM nereids_test_query_db.baseall group by abs(k3) order by abs(k3);""" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } - } + sql"""SELECT abs(k3), group_concat(distinct cast(abs(k2) as char) order by abs(k1), k2) FROM nereids_test_query_db.baseall group by abs(k3) order by abs(k3);""" + + sql"""SELECT abs(k3), group_concat(distinct cast(abs(k2) as char), ":" order by abs(k1), k2) FROM nereids_test_query_db.baseall group by abs(k3) order by abs(k3);""" qt_select """ SELECT count(distinct k7), group_concat(k6 order by k6) FROM nereids_test_query_db.baseall; diff --git a/regression-test/suites/query_p0/group_concat/test_group_concat.groovy b/regression-test/suites/query_p0/group_concat/test_group_concat.groovy index 8bacf756642..522d66ed64b 100644 --- a/regression-test/suites/query_p0/group_concat/test_group_concat.groovy +++ b/regression-test/suites/query_p0/group_concat/test_group_concat.groovy @@ -31,21 +31,10 @@ suite("test_group_concat", "query,p0,arrow_flight_sql") { qt_select """ SELECT abs(k3), group_concat(cast(abs(k2) as varchar), ":" order by abs(k2), k1) FROM test_query_db.baseall group by abs(k3) order by abs(k3) """ - test { - sql"""SELECT abs(k3), group_concat(distinct cast(abs(k2) as char) order by abs(k1), k2) FROM test_query_db.baseall group by abs(k3) order by abs(k3);""" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } - } - - test { - sql"""SELECT abs(k3), group_concat(distinct cast(abs(k2) as char), ":" order by abs(k1), k2) FROM test_query_db.baseall group by abs(k3) order by abs(k3);""" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } - } + + sql"""SELECT abs(k3), group_concat(distinct cast(abs(k2) as char) order by abs(k1), k2) FROM test_query_db.baseall group by abs(k3) order by abs(k3);""" + + sql"""SELECT abs(k3), group_concat(distinct cast(abs(k2) as char), ":" order by abs(k1), k2) FROM test_query_db.baseall group by abs(k3) order by abs(k3);""" qt_select """ SELECT count(distinct k7), group_concat(k6 order by k6) FROM test_query_db.baseall; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org