[Fix](planner) fix select from inline table return only the first row (#24365)

This commit is contained in:
mch_ucchi
2023-09-15 18:14:54 +08:00
committed by GitHub
parent 4ad5845dcc
commit 0742af70ea
4 changed files with 26 additions and 5 deletions

View File

@ -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());
}

View File

@ -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

View File

@ -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());