diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveTableScan.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveTableScan.java index 3d45a01..fbb8969 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveTableScan.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveTableScan.java @@ -28,6 +28,7 @@ import org.apache.calcite.plan.RelOptPlanner; import org.apache.calcite.plan.RelTraitSet; import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelWriter; import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.rel.core.TableScan; import org.apache.calcite.rel.metadata.RelMetadataQuery; @@ -58,14 +59,15 @@ private final RelDataType hiveTableScanRowType; private final ImmutableList neededColIndxsFrmReloptHT; private final String tblAlias; - private final String qbID; + private final String concatQbIDAlias; + private final boolean useQBIdInDigest; public String getTableAlias() { return tblAlias; } - public String getQbID() { - return qbID; + public String getConcatQbIDAlias() { + return concatQbIDAlias; } /** @@ -80,18 +82,20 @@ public String getQbID() { * @param table * HiveDB table */ - public HiveTableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptHiveTable table, String alias, String qbID) { - this(cluster, traitSet, table, alias, qbID, table.getRowType()); + public HiveTableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptHiveTable table, + String alias, String concatQbIDAlias, boolean useQBIdInDigest) { + this(cluster, traitSet, table, alias, concatQbIDAlias, table.getRowType(), useQBIdInDigest); } - private HiveTableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptHiveTable table, String alias, String qbID, - RelDataType newRowtype) { + private HiveTableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptHiveTable table, + String alias, String concatQbIDAlias, RelDataType newRowtype, boolean useQBIdInDigest) { super(cluster, TraitsUtil.getDefaultTraitSet(cluster), table); assert getConvention() == HiveRelNode.CONVENTION; this.tblAlias = alias; - this.qbID = qbID; + this.concatQbIDAlias = concatQbIDAlias; this.hiveTableScanRowType = newRowtype; this.neededColIndxsFrmReloptHT = buildNeededColIndxsFrmReloptHT(table.getRowType(), newRowtype); + this.useQBIdInDigest = useQBIdInDigest; } @Override @@ -108,8 +112,8 @@ public RelNode copy(RelTraitSet traitSet, List inputs) { * @return */ public HiveTableScan copy(RelDataType newRowtype) { - return new HiveTableScan(getCluster(), getTraitSet(), ((RelOptHiveTable) table), this.tblAlias, this.qbID, - newRowtype); + return new HiveTableScan(getCluster(), getTraitSet(), ((RelOptHiveTable) table), this.tblAlias, this.concatQbIDAlias, + newRowtype, this.useQBIdInDigest); } @Override @@ -117,6 +121,16 @@ public RelOptCost computeSelfCost(RelOptPlanner planner) { return RelMetadataQuery.getNonCumulativeCost(this); } + @Override public RelWriter explainTerms(RelWriter pw) { + if (this.useQBIdInDigest) { + // TODO: Only the qualified name should be left here + return super.explainTerms(pw).item("table", table.getQualifiedName()) + .item("qbid:alias", concatQbIDAlias); + } else { + return super.explainTerms(pw); + } + } + @Override public void register(RelOptPlanner planner) { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveOpConverter.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveOpConverter.java index 3afcb54..9e8b362 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveOpConverter.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveOpConverter.java @@ -243,7 +243,7 @@ OpAttr visit(HiveTableScan scanRel) { // 2. Setup TableScan TableScanOperator ts = (TableScanOperator) OperatorFactory.get(tsd, new RowSchema(colInfos)); - topOps.put(scanRel.getQbID(), ts); + topOps.put(scanRel.getConcatQbIDAlias(), ts); if (LOG.isDebugEnabled()) { LOG.debug("Generated " + ts + " with row schema: [" + ts.getSchema() + "]"); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java index 8b78471..8078567 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java @@ -1360,7 +1360,10 @@ private RelNode genTableLogicalPlan(String tableAlias, QB qb) throws SemanticExc partitionCache, noColsMissingStats); // 5. Build Hive Table Scan Rel - tableRel = new HiveTableScan(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION), optTable, null == tableAlias ? tabMetaData.getTableName() : tableAlias, getAliasId(tableAlias, qb)); + tableRel = new HiveTableScan(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION), optTable, + null == tableAlias ? tabMetaData.getTableName() : tableAlias, + getAliasId(tableAlias, qb), HiveConf.getBoolVar(conf, + HiveConf.ConfVars.HIVE_CBO_RETPATH_HIVEOP)); // 6. Add Schema(RR) to RelNode-Schema map ImmutableMap hiveToCalciteColMap = buildHiveToCalciteColumnMap(rr,