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 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]]) + } }