Skip to content

Commit d70fe13

Browse files
authored
[fix](explode-map) fix explode_map with alias (#39972)
## Proposed changes backport: #39757 Issue Number: close #xxx <!--Describe your changes.-->
1 parent fc9936d commit d70fe13

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ private LogicalPlan bindGenerate(MatchingContext<LogicalGenerate<Plan>> ctx) {
271271
for (int idx = 0; idx < fields.size(); ++idx) {
272272
expandAlias.add(new Alias(new StructElement(
273273
boundSlot, new StringLiteral(fields.get(idx).getName())),
274-
generate.getExpandColumnAlias().get(i).get(idx)));
274+
generate.getExpandColumnAlias().get(i).get(idx),
275+
slot.getQualifier()));
275276
}
276277
}
277278
}

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public Alias(ExprId exprId, Expression child, String name) {
6060
this(exprId, ImmutableList.of(child), name, ImmutableList.of(), false);
6161
}
6262

63+
public Alias(Expression child, String name, List<String> qualifier) {
64+
this(StatementScopeIdGenerator.newExprId(), ImmutableList.of(child), name, qualifier, false);
65+
}
66+
6367
public Alias(ExprId exprId, Expression child, String name, boolean nameFromChild) {
6468
this(exprId, ImmutableList.of(child), name, ImmutableList.of(), nameFromChild);
6569
}

regression-test/data/nereids_p0/sql_functions/table_function/explode_map.out

+43
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,46 @@ zhangsan Math 60 Chinese 80
4949
zhangsan Math 60 English 90
5050
zhangsan Math 60 Math 60
5151

52+
-- !explode_sql_alias --
53+
lisi null \N
54+
lisi2 \N \N
55+
wangwu Chinese 88
56+
wangwu English 96
57+
wangwu Math 90
58+
zhangsan Chinese 80
59+
zhangsan English 90
60+
zhangsan Math 60
61+
62+
-- !explode_outer_sql_alias --
63+
amory \N \N
64+
lisi null \N
65+
lisi2 \N \N
66+
wangwu Chinese 88
67+
wangwu English 96
68+
wangwu Math 90
69+
zhangsan Chinese 80
70+
zhangsan English 90
71+
zhangsan Math 60
72+
73+
-- !explode_sql_alias_multi --
74+
lisi null \N null \N
75+
lisi2 \N \N \N \N
76+
wangwu Chinese 88 Chinese 88
77+
wangwu Chinese 88 English 96
78+
wangwu Chinese 88 Math 90
79+
wangwu English 96 Chinese 88
80+
wangwu English 96 English 96
81+
wangwu English 96 Math 90
82+
wangwu Math 90 Chinese 88
83+
wangwu Math 90 English 96
84+
wangwu Math 90 Math 90
85+
zhangsan Chinese 80 Chinese 80
86+
zhangsan Chinese 80 English 90
87+
zhangsan Chinese 80 Math 60
88+
zhangsan English 90 Chinese 80
89+
zhangsan English 90 English 90
90+
zhangsan English 90 Math 60
91+
zhangsan Math 60 Chinese 80
92+
zhangsan Math 60 English 90
93+
zhangsan Math 60 Math 60
94+

regression-test/suites/nereids_p0/sql_functions/table_function/explode_map.groovy

+6
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ suite("explode_map") {
4545

4646
// multi lateral view
4747
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;"""
48+
49+
// test with alias
50+
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;"""
51+
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; """
52+
53+
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;"""
4854
}

0 commit comments

Comments
 (0)