This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 0742af70ea [Fix](planner) fix select from inline table return only the 
first row (#24365)
0742af70ea is described below

commit 0742af70eafd720916bcf4471c8582a3b7a4b484
Author: mch_ucchi <[email protected]>
AuthorDate: Fri Sep 15 18:14:54 2023 +0800

    [Fix](planner) fix select from inline table return only the first row 
(#24365)
---
 .../java/org/apache/doris/analysis/InlineViewRef.java    | 16 +++++++++++++---
 .../main/java/org/apache/doris/analysis/SelectStmt.java  |  2 +-
 .../java/org/apache/doris/planner/SingleNodePlanner.java |  8 +++++++-
 regression-test/suites/query_p0/union/test_union.groovy  |  5 +++++
 4 files changed, 26 insertions(+), 5 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java
index b40af41e72..4274ed37f3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java
@@ -231,11 +231,21 @@ public class InlineViewRef extends TableRef {
             String colName = getColLabels().get(i);
             SlotDescriptor slotDesc = 
analyzer.registerColumnRef(getAliasAsName(), colName);
             Expr colExpr = queryStmt.getResultExprs().get(i);
-            slotDesc.setSourceExpr(colExpr);
+            if (queryStmt instanceof SelectStmt && ((SelectStmt) 
queryStmt).getValueList() != null) {
+                ValueList valueList = ((SelectStmt) queryStmt).getValueList();
+                for (int j = 0; j < valueList.getRows().size(); ++j) {
+                    slotDesc.addSourceExpr(valueList.getRows().get(j).get(i));
+                }
+            } else {
+                slotDesc.setSourceExpr(colExpr);
+            }
             slotDesc.setIsNullable(slotDesc.getIsNullable() || 
colExpr.isNullable());
             SlotRef slotRef = new SlotRef(slotDesc);
-            sMap.put(slotRef, colExpr);
-            baseTblSmap.put(slotRef, queryStmt.getBaseTblResultExprs().get(i));
+            // to solve select * from (values(1, 2, 3), (4, 5, 6)) a returns 
only one row.
+            if (slotDesc.getSourceExprs().size() == 1) {
+                sMap.put(slotRef, colExpr);
+                baseTblSmap.put(slotRef, 
queryStmt.getBaseTblResultExprs().get(i));
+            }
             if (createAuxPredicate(colExpr)) {
                 analyzer.createAuxEquivPredicate(new SlotRef(slotDesc), 
colExpr.clone());
             }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 67c2a06a1c..a159695246 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -589,7 +589,7 @@ public class SelectStmt extends QueryStmt {
                 } else {
                     resultExprs.add(rewriteQueryExprByMvColumnExpr(expr, 
analyzer));
                 }
-                colLabels.add(expr.toColumnLabel());
+                colLabels.add("col_" + colLabels.size());
             }
         }
         // analyze valueList if exists
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
index 9a61dc676f..80d22e25b1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
@@ -1647,7 +1647,13 @@ public class SingleNodePlanner {
                     return unionNode;
                 }
                 
unionNode.setTblRefIds(Lists.newArrayList(inlineViewRef.getId()));
-                unionNode.addConstExprList(selectStmt.getBaseTblResultExprs());
+                if (selectStmt.getValueList() != null) {
+                    for (List<Expr> row : selectStmt.getValueList().getRows()) 
{
+                        unionNode.addConstExprList(row);
+                    }
+                } else {
+                    
unionNode.addConstExprList(selectStmt.getBaseTblResultExprs());
+                }
                 unionNode.init(analyzer);
                 //set outputSmap to substitute literal in outputExpr
                 
unionNode.setWithoutTupleIsNullOutputSmap(inlineViewRef.getSmap());
diff --git a/regression-test/suites/query_p0/union/test_union.groovy 
b/regression-test/suites/query_p0/union/test_union.groovy
index 73ad6c013b..d67e3aa65c 100644
--- a/regression-test/suites/query_p0/union/test_union.groovy
+++ b/regression-test/suites/query_p0/union/test_union.groovy
@@ -279,4 +279,9 @@ suite("test_union") {
     qt_union35 """select cast("2016-07-01" as date) union (select 
cast("2016-07-02 1:10:0" as date)) order by 1"""
 
     qt_union36 """SELECT a,2 as a FROM (SELECT '1' as a) b where a=1;"""
+    
+    test {
+        sql 'select * from (values (1, 2, 3), (4, 5, 6)) a'
+        result([[1, 2, 3], [4, 5, 6]])
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to