Skip to content

Commit

Permalink
[fix](lateral_view) fix lateral view explode_split with temp table (a…
Browse files Browse the repository at this point in the history
…pache#12643)

Problem describe:

follow SQL return wrong result:
WITH example1 AS ( select 6 AS k1 ,'a,b,c' AS k2) select k1, e1 from example1 lateral view explode_split(k2, ',') tmp as e1;

Wrong result:

+------+------+
| k1   | e1   |
+------+------+
|    0 | a    |
|    0 | b    |
|    0 | c    |
+------+------+
Correct result should be:
+------+------+
| k1   | e1   |
+------+------+
|    6 | a    |
|    6 | b    |
|    6 | c    |
+------+------+
Why?
TableFunctionNode::outputSlotIds do not include column k1.

Co-authored-by: cambyzju <zhuxiaoli01@baidu.com>
  • Loading branch information
cambyzju and cambyzju authored Sep 21, 2022
1 parent b0b876f commit c5b6056
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@ private PlanNode createInlineViewPlan(Analyzer analyzer, InlineViewRef inlineVie
unionNode.init(analyzer);
//set outputSmap to substitute literal in outputExpr
unionNode.setWithoutTupleIsNullOutputSmap(inlineViewRef.getSmap());
unionNode.setOutputSmap(inlineViewRef.getSmap());
if (analyzer.isOuterJoined(inlineViewRef.getId())) {
List<Expr> nullableRhs;
if (analyzer.isOuterJoinedLeftSide(inlineViewRef.getId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
1 a,b,c c b
1 a,b,c c c

-- !explode_split --
6 a
6 b
6 c

-- !explode_split --
1 a,b,c a
1 a,b,c b
Expand All @@ -31,3 +36,8 @@
1 a,b,c c b
1 a,b,c c c

-- !explode_split --
6 a
6 b
6 c

Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,29 @@ suite("explode_split") {
sql """ INSERT INTO ${tableName} VALUES (1, 'a,b,c') """

// not_vectorized
sql """ set enable_vectorized_engine = false """
qt_explode_split """ select * from ${tableName}
lateral view explode_split(k2, ',') tmp1 as e1 """

qt_explode_split """ select * from ${tableName}
lateral view explode_split(k2, ',') tmp1 as e1
lateral view explode_split(k2, ',') tmp2 as e2 """

qt_explode_split """ WITH example1 AS ( select 6 AS k1 ,'a,b,c' AS k2)
select k1, e1 from example1
lateral view explode_split(k2, ',') tmp as e1 """

// vectorized
sql """ set enable_vectorized_engine = true """

qt_explode_split """ select * from ${tableName}
lateral view explode_split(k2, ',') tmp1 as e1 """

qt_explode_split """ select * from ${tableName}
lateral view explode_split(k2, ',') tmp1 as e1
lateral view explode_split(k2, ',') tmp2 as e2 """

qt_explode_split """ WITH example1 AS ( select 6 AS k1 ,'a,b,c' AS k2)
select k1, e1 from example1
lateral view explode_split(k2, ',') tmp as e1 """

}

0 comments on commit c5b6056

Please sign in to comment.