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 d70fe130d70 [fix](explode-map) fix explode_map with alias (#39972)
d70fe130d70 is described below
commit d70fe130d70799619c3af61e51b4c14d5ff0005d
Author: amory <[email protected]>
AuthorDate: Tue Aug 27 18:32:10 2024 +0800
[fix](explode-map) fix explode_map with alias (#39972)
## Proposed changes
backport: https://github.com/apache/doris/pull/39757
Issue Number: close #xxx
<!--Describe your changes.-->
---
.../nereids/rules/analysis/BindExpression.java | 3 +-
.../doris/nereids/trees/expressions/Alias.java | 4 ++
.../sql_functions/table_function/explode_map.out | 43 ++++++++++++++++++++++
.../table_function/explode_map.groovy | 6 +++
4 files changed, 55 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java
index 97ba2267d03..b3d91743937 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java
@@ -271,7 +271,8 @@ public class BindExpression implements AnalysisRuleFactory {
for (int idx = 0; idx < fields.size(); ++idx) {
expandAlias.add(new Alias(new StructElement(
boundSlot, new
StringLiteral(fields.get(idx).getName())),
- generate.getExpandColumnAlias().get(i).get(idx)));
+ generate.getExpandColumnAlias().get(i).get(idx),
+ slot.getQualifier()));
}
}
}
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 6b31fc60f27..9eea3afd879 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
@@ -60,6 +60,10 @@ public class Alias extends NamedExpression implements
UnaryExpression {
this(exprId, ImmutableList.of(child), name, ImmutableList.of(), false);
}
+ public Alias(Expression child, String name, List<String> qualifier) {
+ this(StatementScopeIdGenerator.newExprId(), ImmutableList.of(child),
name, qualifier, false);
+ }
+
public Alias(ExprId exprId, Expression child, String name, boolean
nameFromChild) {
this(exprId, ImmutableList.of(child), name, ImmutableList.of(),
nameFromChild);
}
diff --git
a/regression-test/data/nereids_p0/sql_functions/table_function/explode_map.out
b/regression-test/data/nereids_p0/sql_functions/table_function/explode_map.out
index 295b908d7f8..44fb65a8d0c 100644
---
a/regression-test/data/nereids_p0/sql_functions/table_function/explode_map.out
+++
b/regression-test/data/nereids_p0/sql_functions/table_function/explode_map.out
@@ -49,3 +49,46 @@ zhangsan Math 60 Chinese 80
zhangsan Math 60 English 90
zhangsan Math 60 Math 60
+-- !explode_sql_alias --
+lisi null \N
+lisi2 \N \N
+wangwu Chinese 88
+wangwu English 96
+wangwu Math 90
+zhangsan Chinese 80
+zhangsan English 90
+zhangsan Math 60
+
+-- !explode_outer_sql_alias --
+amory \N \N
+lisi null \N
+lisi2 \N \N
+wangwu Chinese 88
+wangwu English 96
+wangwu Math 90
+zhangsan Chinese 80
+zhangsan English 90
+zhangsan Math 60
+
+-- !explode_sql_alias_multi --
+lisi null \N null \N
+lisi2 \N \N \N \N
+wangwu Chinese 88 Chinese 88
+wangwu Chinese 88 English 96
+wangwu Chinese 88 Math 90
+wangwu English 96 Chinese 88
+wangwu English 96 English 96
+wangwu English 96 Math 90
+wangwu Math 90 Chinese 88
+wangwu Math 90 English 96
+wangwu Math 90 Math 90
+zhangsan Chinese 80 Chinese 80
+zhangsan Chinese 80 English 90
+zhangsan Chinese 80 Math 60
+zhangsan English 90 Chinese 80
+zhangsan English 90 English 90
+zhangsan English 90 Math 60
+zhangsan Math 60 Chinese 80
+zhangsan Math 60 English 90
+zhangsan Math 60 Math 60
+
diff --git
a/regression-test/suites/nereids_p0/sql_functions/table_function/explode_map.groovy
b/regression-test/suites/nereids_p0/sql_functions/table_function/explode_map.groovy
index 338cf675042..6235bb5ee2e 100644
---
a/regression-test/suites/nereids_p0/sql_functions/table_function/explode_map.groovy
+++
b/regression-test/suites/nereids_p0/sql_functions/table_function/explode_map.groovy
@@ -45,4 +45,10 @@ suite("explode_map") {
// multi lateral view
order_qt_explode_sql_multi """ select name, k,v,k1,v1 from sdu lateral
view explode_map_outer(score) tmp as k,v lateral view explode_map(score) tmp2
as k1,v1 order by id;"""
+
+ // test with alias
+ order_qt_explode_sql_alias """ select name, tmp.k, tmp.v from sdu lateral
view explode_map(score) tmp as k,v order by id;"""
+ order_qt_explode_outer_sql_alias """ select name, tmp.k, tmp.v from sdu
lateral view explode_map_outer(score) tmp as k,v order by id; """
+
+ order_qt_explode_sql_alias_multi """ select name, tmp.k, tmp.v, tmp2.k,
tmp2.v from sdu lateral view explode_map_outer(score) tmp as k,v lateral view
explode_map(score) tmp2 as k,v order by id;"""
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]