Repository: kylin Updated Branches: refs/heads/KYLIN-2277 [created] 5ff1c34b4
KYLIN-2277 half way, almost done, need test case Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/5ff1c34b Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/5ff1c34b Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/5ff1c34b Branch: refs/heads/KYLIN-2277 Commit: 5ff1c34b4b93f40c54538b0b50b5dd823b2779d4 Parents: 5303651 Author: Yang Li <liy...@apache.org> Authored: Tue Dec 13 23:45:55 2016 +0800 Committer: Yang Li <liy...@apache.org> Committed: Tue Dec 13 23:45:55 2016 +0800 ---------------------------------------------------------------------- .../calcite/sql2rel/SqlToRelConverter.java | 46 +++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/5ff1c34b/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java ---------------------------------------------------------------------- diff --git a/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index d223cdf..7e00b8c 100644 --- a/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -67,6 +67,7 @@ import org.apache.calcite.rel.stream.Delta; import org.apache.calcite.rel.stream.LogicalDelta; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeFactory; +import org.apache.calcite.rel.type.RelDataTypeFactory.FieldInfoBuilder; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.rex.RexCall; @@ -194,6 +195,7 @@ import static org.apache.calcite.util.Static.RESOURCE; * - getInSubqueryThreshold(), was `20`, now `Integer.MAX_VALUE` * - isTrimUnusedFields(), override to false * - AggConverter.translateAgg(...), skip column reading for COUNT(COL), for https://jirap.corp.ebay.com/browse/KYLIN-104 + * - convertQuery(), call hackSelectStar() at the end */ /** @@ -553,7 +555,49 @@ public class SqlToRelConverter { } final RelDataType validatedRowType = validator.getValidatedNodeType(query); - return RelRoot.of(result, validatedRowType, query.getKind()).withCollation(collation); + return hackSelectStar(query, RelRoot.of(result, validatedRowType, query.getKind()).withCollation(collation)); + } + + /* OVERRIDE POINT */ + private RelRoot hackSelectStar(SqlNode query, RelRoot root) { + if (!(root.rel instanceof LogicalProject)) + return root; + + LogicalProject rootPrj = (LogicalProject) root.rel; + if (!rootPrj.getInput().getClass().getSimpleName().equals("OLAPTableScan")) + return root; + + RelNode scan = rootPrj.getInput(); + if (rootPrj.getRowType().getFieldCount() < scan.getRowType().getFieldCount()) + return root; + + RelDataType inType = scan.getRowType(); + List<String> inFields = inType.getFieldNames(); + List<RexNode> projExp = new ArrayList<>(); + List<Pair<Integer, String>> projFields = new ArrayList<>(); + FieldInfoBuilder projTypeBuilder = getCluster().getTypeFactory().builder(); + FieldInfoBuilder validTypeBuilder = getCluster().getTypeFactory().builder(); + SqlNodeList selectList = ((SqlSelect) query).getSelectList(); + SqlNodeList newSelectList = new SqlNodeList(selectList.getParserPosition()); + for (int i = 0; i < inFields.size(); i++) { + if (!inFields.get(i).endsWith("_")) { + RexBuilder rexBuilder = getCluster().getRexBuilder(); + projExp.add(rexBuilder.makeInputRef(scan, i)); + projFields.add(Pair.of(projFields.size(), inFields.get(i))); + projTypeBuilder.add(inType.getFieldList().get(i)); + validTypeBuilder.add(root.validatedRowType.getFieldList().get(i)); + newSelectList.add(selectList.get(i)); + } + } + + RelDataType projRowType = getCluster().getTypeFactory().createStructType(projTypeBuilder); + RelDataType validRowType = getCluster().getTypeFactory().createStructType(validTypeBuilder); + root = new RelRoot(LogicalProject.create(scan, projExp, projRowType), validRowType, root.kind, projFields, root.collation); + + ((SqlSelect) query).setSelectList(newSelectList); + validator.setValidatedNodeType(query, validRowType); + + return root; } private static boolean isStream(SqlNode query) {