This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new ef8d18c0caf branch-3.0: [fix](Nereids) let anonymous alias same as user input #47093 (#47245) ef8d18c0caf is described below commit ef8d18c0caffb80563c709da3b9351cc66d07d00 Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> AuthorDate: Thu Feb 27 17:57:32 2025 +0800 branch-3.0: [fix](Nereids) let anonymous alias same as user input #47093 (#47245) Cherry-picked from #47093 Co-authored-by: morrySnow <zhangwen...@selectdb.com> --- .../doris/nereids/analyzer/UnboundAlias.java | 22 ++++++++++++++++----- .../doris/nereids/parser/LogicalPlanBuilder.java | 11 ++++++++++- .../nereids/rules/analysis/ExpressionAnalyzer.java | 2 +- .../doris/nereids/trees/expressions/Alias.java | 6 +++++- .../trees/plans/commands/insert/InsertUtils.java | 9 +++++++-- .../rules/analysis/FillUpMissingSlotsTest.java | 8 ++++---- .../data/nereids_hint_tpcds_p0/shape/query54.out | Bin 6456 -> 6448 bytes .../push_down_count_through_join.out | Bin 29580 -> 29586 bytes .../push_down_count_through_join_one_side.out | Bin 32823 -> 32829 bytes .../eager_aggregate/push_down_min_through_join.out | Bin 16427 -> 16433 bytes .../eager_aggregate/push_down_sum_through_join.out | Bin 16193 -> 16199 bytes .../push_down_sum_through_join_one_side.out | Bin 17453 -> 17459 bytes .../filter_push_down/push_filter_through.out | Bin 10024 -> 10023 bytes .../bs_downgrade_shape/query54.out | Bin 6290 -> 6282 bytes .../shape/query54.out | Bin 6290 -> 6282 bytes .../noStatsRfPrune/query54.out | Bin 5471 -> 5463 bytes .../no_stats_shape/query54.out | Bin 5740 -> 5732 bytes .../rf_prune/query54.out | Bin 6245 -> 6237 bytes .../nereids_tpcds_shape_sf100_p0/shape/query54.out | Bin 6292 -> 6284 bytes .../shape/query54.out | Bin 6064 -> 6056 bytes .../tpcds_sf100/noStatsRfPrune/query54.out | Bin 5471 -> 5463 bytes .../tpcds_sf100/no_stats_shape/query54.out | Bin 5740 -> 5732 bytes .../new_shapes_p0/tpcds_sf100/rf_prune/query54.out | Bin 6245 -> 6237 bytes .../new_shapes_p0/tpcds_sf100/shape/query54.out | Bin 6292 -> 6284 bytes .../tpcds_sf1000/bs_downgrade_shape/query54.out | Bin 6290 -> 6282 bytes .../new_shapes_p0/tpcds_sf1000/shape/query54.out | Bin 6290 -> 6282 bytes .../subquery/test_duplicate_name_in_view.groovy | 2 +- .../suites/nereids_syntax_p0/select_const.groovy | 2 ++ 28 files changed, 47 insertions(+), 15 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundAlias.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundAlias.java index 25d40dd5981..043542eaac6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundAlias.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundAlias.java @@ -36,21 +36,29 @@ import java.util.Optional; */ public class UnboundAlias extends NamedExpression implements UnaryExpression, Unbound, PropagateNullable { - private Optional<String> alias; + private final Optional<String> alias; + private final boolean nameFromChild; public UnboundAlias(Expression child) { - super(ImmutableList.of(child)); - this.alias = Optional.empty(); + this(ImmutableList.of(child), Optional.empty()); } public UnboundAlias(Expression child, String alias) { - super(ImmutableList.of(child)); - this.alias = Optional.of(alias); + this(ImmutableList.of(child), Optional.of(alias)); + } + + public UnboundAlias(Expression child, String alias, boolean nameFromChild) { + this(ImmutableList.of(child), Optional.of(alias), nameFromChild); } private UnboundAlias(List<Expression> children, Optional<String> alias) { + this(children, alias, false); + } + + private UnboundAlias(List<Expression> children, Optional<String> alias, boolean nameFromChild) { super(children); this.alias = alias; + this.nameFromChild = nameFromChild; } @Override @@ -89,4 +97,8 @@ public class UnboundAlias extends NamedExpression implements UnaryExpression, Un public Optional<String> getAlias() { return alias; } + + public boolean isNameFromChild() { + return nameFromChild; + } } 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 62bca860765..3e300722e90 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 @@ -232,6 +232,7 @@ import org.apache.doris.nereids.properties.SelectHintSetVar; import org.apache.doris.nereids.properties.SelectHintUseCboRule; import org.apache.doris.nereids.trees.TableSample; import org.apache.doris.nereids.trees.expressions.Add; +import org.apache.doris.nereids.trees.expressions.Alias; import org.apache.doris.nereids.trees.expressions.And; import org.apache.doris.nereids.trees.expressions.BitAnd; import org.apache.doris.nereids.trees.expressions.BitNot; @@ -1602,7 +1603,15 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { if (expression instanceof NamedExpression) { return (NamedExpression) expression; } else { - return new UnboundAlias(expression); + int start = ctx.expression().start.getStartIndex(); + int stop = ctx.expression().stop.getStopIndex(); + String alias = ctx.start.getInputStream() + .getText(new org.antlr.v4.runtime.misc.Interval(start, stop)); + if (expression instanceof Literal) { + return new Alias(expression, alias, true); + } else { + return new UnboundAlias(expression, alias, true); + } } } String alias = visitIdentifierOrText(ctx.identifierOrText()); 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 26c25a4e012..cf132d2ed85 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 @@ -259,7 +259,7 @@ public class ExpressionAnalyzer extends SubExprAnalyzer<ExpressionRewriteContext public Expression visitUnboundAlias(UnboundAlias unboundAlias, ExpressionRewriteContext context) { Expression child = unboundAlias.child().accept(this, context); if (unboundAlias.getAlias().isPresent()) { - return new Alias(child, unboundAlias.getAlias().get()); + return new Alias(child, unboundAlias.getAlias().get(), unboundAlias.isNameFromChild()); // TODO: the variant bind element_at(slot, 'name') will return a slot, and we should // assign an Alias to this function, this is trick and should refactor it } else if (!(unboundAlias.child() instanceof ElementAt) && child instanceof NamedExpression) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java index 9ff90b5ac96..48a98eb3ee1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java @@ -48,7 +48,11 @@ public class Alias extends NamedExpression implements UnaryExpression { * @param name alias name */ public Alias(Expression child, String name) { - this(StatementScopeIdGenerator.newExprId(), child, name, false); + this(child, name, false); + } + + public Alias(Expression child, String name, boolean nameFromChild) { + this(StatementScopeIdGenerator.newExprId(), child, name, nameFromChild); } public Alias(Expression child) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java index e6418e062be..a30592e21d1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java @@ -424,8 +424,13 @@ public class InsertUtils { } private static Expression castValue(Expression value, DataType targetType) { - if (value instanceof UnboundAlias) { - return value.withChildren(TypeCoercionUtils.castUnbound(((UnboundAlias) value).child(), targetType)); + if (value instanceof Alias) { + Expression oldChild = value.child(0); + Expression newChild = TypeCoercionUtils.castUnbound(oldChild, targetType); + return oldChild == newChild ? value : value.withChildren(newChild); + } else if (value instanceof UnboundAlias) { + UnboundAlias unboundAlias = (UnboundAlias) value; + return new Alias(TypeCoercionUtils.castUnbound(unboundAlias.child(), targetType)); } else { return TypeCoercionUtils.castUnbound(value, targetType); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/FillUpMissingSlotsTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/FillUpMissingSlotsTest.java index 02f3caffa80..cb01fc17e30 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/FillUpMissingSlotsTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/FillUpMissingSlotsTest.java @@ -230,7 +230,7 @@ public class FillUpMissingSlotsTest extends AnalyzeCheckTestBase implements Memo ).when(FieldChecker.check("projects", Lists.newArrayList(a1.toSlot(), sumA2.toSlot())))); sql = "SELECT a1, sum(a1 + a2) FROM t1 GROUP BY a1 HAVING sum(a1 + a2) > 0"; - Alias sumA1A2 = new Alias(new ExprId(3), new Sum(new Add(a1, a2)), "sum((a1 + a2))"); + Alias sumA1A2 = new Alias(new ExprId(3), new Sum(new Add(a1, a2)), "sum(a1 + a2)"); PlanChecker.from(connectContext).analyze(sql) .matches( logicalProject( @@ -353,7 +353,7 @@ public class FillUpMissingSlotsTest extends AnalyzeCheckTestBase implements Memo Alias sumA1 = new Alias(new ExprId(9), new Sum(a1), "sum(a1)"); Alias countA1 = new Alias(new ExprId(13), new Count(a1), "count(a1)"); Alias countA11 = new Alias(new ExprId(10), new Add(countA1.toSlot(), Literal.of((byte) 1)), "(count(a1) + 1)"); - Alias sumA1A2 = new Alias(new ExprId(11), new Sum(new Add(a1, a2)), "sum((a1 + a2))"); + Alias sumA1A2 = new Alias(new ExprId(11), new Sum(new Add(a1, a2)), "sum(a1 + a2)"); Alias v1 = new Alias(new ExprId(12), new Count(a2), "v1"); PlanChecker.from(connectContext).analyze(sql) .matches( @@ -466,7 +466,7 @@ public class FillUpMissingSlotsTest extends AnalyzeCheckTestBase implements Memo ).when(FieldChecker.check("projects", Lists.newArrayList(a1.toSlot(), sumA2.toSlot())))); sql = "SELECT a1, sum(a1 + a2) FROM t1 GROUP BY a1 ORDER BY sum(a1 + a2)"; - Alias sumA1A2 = new Alias(new ExprId(3), new Sum(new Add(a1, a2)), "sum((a1 + a2))"); + Alias sumA1A2 = new Alias(new ExprId(3), new Sum(new Add(a1, a2)), "sum(a1 + a2)"); PlanChecker.from(connectContext).analyze(sql) .matches( logicalSort( @@ -552,7 +552,7 @@ public class FillUpMissingSlotsTest extends AnalyzeCheckTestBase implements Memo Alias sumA1 = new Alias(new ExprId(9), new Sum(a1), "sum(a1)"); Alias countA1 = new Alias(new ExprId(13), new Count(a1), "count(a1)"); Alias countA11 = new Alias(new ExprId(10), new Add(new Count(a1), Literal.of((byte) 1)), "(count(a1) + 1)"); - Alias sumA1A2 = new Alias(new ExprId(11), new Sum(new Add(a1, a2)), "sum((a1 + a2))"); + Alias sumA1A2 = new Alias(new ExprId(11), new Sum(new Add(a1, a2)), "sum(a1 + a2)"); Alias v1 = new Alias(new ExprId(12), new Count(a2), "v1"); PlanChecker.from(connectContext).analyze(sql) .matches(logicalProject(logicalSort(logicalProject(logicalAggregate(logicalProject( diff --git a/regression-test/data/nereids_hint_tpcds_p0/shape/query54.out b/regression-test/data/nereids_hint_tpcds_p0/shape/query54.out index 04bebe19768..5d2c155f7e8 100644 Binary files a/regression-test/data/nereids_hint_tpcds_p0/shape/query54.out and b/regression-test/data/nereids_hint_tpcds_p0/shape/query54.out differ diff --git a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_count_through_join.out b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_count_through_join.out index a7a0f422ee8..076731ffa2f 100644 Binary files a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_count_through_join.out and b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_count_through_join.out differ diff --git a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_count_through_join_one_side.out b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_count_through_join_one_side.out index 8267eb3e38f..1f546d131d3 100644 Binary files a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_count_through_join_one_side.out and b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_count_through_join_one_side.out differ diff --git a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_min_through_join.out b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_min_through_join.out index d4efe7df093..d2129c0b417 100644 Binary files a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_min_through_join.out and b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_min_through_join.out differ diff --git a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_sum_through_join.out b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_sum_through_join.out index 9d20fb8b02d..e933630ef70 100644 Binary files a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_sum_through_join.out and b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_sum_through_join.out differ diff --git a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_sum_through_join_one_side.out b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_sum_through_join_one_side.out index 5013dc7dbdf..3a58dfd19d5 100644 Binary files a/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_sum_through_join_one_side.out and b/regression-test/data/nereids_rules_p0/eager_aggregate/push_down_sum_through_join_one_side.out differ diff --git a/regression-test/data/nereids_rules_p0/filter_push_down/push_filter_through.out b/regression-test/data/nereids_rules_p0/filter_push_down/push_filter_through.out index a6d0c88e829..7413117efb9 100644 Binary files a/regression-test/data/nereids_rules_p0/filter_push_down/push_filter_through.out and b/regression-test/data/nereids_rules_p0/filter_push_down/push_filter_through.out differ diff --git a/regression-test/data/nereids_tpcds_shape_sf1000_p0/bs_downgrade_shape/query54.out b/regression-test/data/nereids_tpcds_shape_sf1000_p0/bs_downgrade_shape/query54.out index 397a41b34c4..de5048e9120 100644 Binary files a/regression-test/data/nereids_tpcds_shape_sf1000_p0/bs_downgrade_shape/query54.out and b/regression-test/data/nereids_tpcds_shape_sf1000_p0/bs_downgrade_shape/query54.out differ diff --git a/regression-test/data/nereids_tpcds_shape_sf1000_p0/shape/query54.out b/regression-test/data/nereids_tpcds_shape_sf1000_p0/shape/query54.out index 397a41b34c4..de5048e9120 100644 Binary files a/regression-test/data/nereids_tpcds_shape_sf1000_p0/shape/query54.out and b/regression-test/data/nereids_tpcds_shape_sf1000_p0/shape/query54.out differ diff --git a/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query54.out b/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query54.out index de4dbe32cd1..138c011bf4a 100644 Binary files a/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query54.out and b/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query54.out differ diff --git a/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query54.out b/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query54.out index 96d57c63e6f..fe1b97d49f2 100644 Binary files a/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query54.out and b/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query54.out differ diff --git a/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query54.out b/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query54.out index ca44d791dc4..e382a96f81a 100644 Binary files a/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query54.out and b/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query54.out differ diff --git a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query54.out b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query54.out index c2d65d63990..5d85bf3be8e 100644 Binary files a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query54.out and b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query54.out differ diff --git a/regression-test/data/nereids_tpcds_shape_sf10t_orc/shape/query54.out b/regression-test/data/nereids_tpcds_shape_sf10t_orc/shape/query54.out index 4ee5ff3b075..e5be80576e2 100644 Binary files a/regression-test/data/nereids_tpcds_shape_sf10t_orc/shape/query54.out and b/regression-test/data/nereids_tpcds_shape_sf10t_orc/shape/query54.out differ diff --git a/regression-test/data/new_shapes_p0/tpcds_sf100/noStatsRfPrune/query54.out b/regression-test/data/new_shapes_p0/tpcds_sf100/noStatsRfPrune/query54.out index de4dbe32cd1..138c011bf4a 100644 Binary files a/regression-test/data/new_shapes_p0/tpcds_sf100/noStatsRfPrune/query54.out and b/regression-test/data/new_shapes_p0/tpcds_sf100/noStatsRfPrune/query54.out differ diff --git a/regression-test/data/new_shapes_p0/tpcds_sf100/no_stats_shape/query54.out b/regression-test/data/new_shapes_p0/tpcds_sf100/no_stats_shape/query54.out index 96d57c63e6f..fe1b97d49f2 100644 Binary files a/regression-test/data/new_shapes_p0/tpcds_sf100/no_stats_shape/query54.out and b/regression-test/data/new_shapes_p0/tpcds_sf100/no_stats_shape/query54.out differ diff --git a/regression-test/data/new_shapes_p0/tpcds_sf100/rf_prune/query54.out b/regression-test/data/new_shapes_p0/tpcds_sf100/rf_prune/query54.out index ca44d791dc4..e382a96f81a 100644 Binary files a/regression-test/data/new_shapes_p0/tpcds_sf100/rf_prune/query54.out and b/regression-test/data/new_shapes_p0/tpcds_sf100/rf_prune/query54.out differ diff --git a/regression-test/data/new_shapes_p0/tpcds_sf100/shape/query54.out b/regression-test/data/new_shapes_p0/tpcds_sf100/shape/query54.out index c2d65d63990..5d85bf3be8e 100644 Binary files a/regression-test/data/new_shapes_p0/tpcds_sf100/shape/query54.out and b/regression-test/data/new_shapes_p0/tpcds_sf100/shape/query54.out differ diff --git a/regression-test/data/new_shapes_p0/tpcds_sf1000/bs_downgrade_shape/query54.out b/regression-test/data/new_shapes_p0/tpcds_sf1000/bs_downgrade_shape/query54.out index 397a41b34c4..de5048e9120 100644 Binary files a/regression-test/data/new_shapes_p0/tpcds_sf1000/bs_downgrade_shape/query54.out and b/regression-test/data/new_shapes_p0/tpcds_sf1000/bs_downgrade_shape/query54.out differ diff --git a/regression-test/data/new_shapes_p0/tpcds_sf1000/shape/query54.out b/regression-test/data/new_shapes_p0/tpcds_sf1000/shape/query54.out index 397a41b34c4..de5048e9120 100644 Binary files a/regression-test/data/new_shapes_p0/tpcds_sf1000/shape/query54.out and b/regression-test/data/new_shapes_p0/tpcds_sf1000/shape/query54.out differ diff --git a/regression-test/suites/nereids_p0/subquery/test_duplicate_name_in_view.groovy b/regression-test/suites/nereids_p0/subquery/test_duplicate_name_in_view.groovy index c5d2c219527..775636aba17 100644 --- a/regression-test/suites/nereids_p0/subquery/test_duplicate_name_in_view.groovy +++ b/regression-test/suites/nereids_p0/subquery/test_duplicate_name_in_view.groovy @@ -77,7 +77,7 @@ suite("test_duplicate_name_in_view") { issue_19611_t1.c0 + 1 FROM issue_19611_t1 ) tmp; """ - exception "Duplicated inline view column alias: '(c0 + 1)' in inline view: 'tmp'" + exception "Duplicated inline view column alias: 'issue_19611_t1.c0 + 1' in inline view: 'tmp'" } test { diff --git a/regression-test/suites/nereids_syntax_p0/select_const.groovy b/regression-test/suites/nereids_syntax_p0/select_const.groovy index e802fbcca78..d65e9cb6ac2 100644 --- a/regression-test/suites/nereids_syntax_p0/select_const.groovy +++ b/regression-test/suites/nereids_syntax_p0/select_const.groovy @@ -49,4 +49,6 @@ suite("select_with_const") { """ sql "select all 1" + + sql "select `1 + 2` from (select 1 + 2) t" } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org