You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2014/09/24 17:45:23 UTC
svn commit: r1627350 - in /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql:
optimizer/optiq/RelOptHiveTable.java
optimizer/optiq/translator/ASTBuilder.java
optimizer/optiq/translator/ASTConverter.java parse/SemanticAnalyzer.java
Author: hashutosh
Date: Wed Sep 24 15:45:23 2014
New Revision: 1627350
URL: http://svn.apache.org/r1627350
Log:
HIVE-8237 : CBO: Use Fully qualified table name (db.tablename in ReloptHiveTable) (John Pullokkaran via Ashutosh Chauhan)
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/RelOptHiveTable.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTBuilder.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTConverter.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/RelOptHiveTable.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/RelOptHiveTable.java?rev=1627350&r1=1627349&r2=1627350&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/RelOptHiveTable.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/RelOptHiveTable.java Wed Sep 24 15:45:23 2014
@@ -55,6 +55,7 @@ import com.google.common.collect.Immutab
public class RelOptHiveTable extends RelOptAbstractTable {
private final Table hiveTblMetadata;
+ private final String tblAlias;
private final ImmutableList<ColumnInfo> hiveNonPartitionCols;
private final ImmutableMap<Integer, ColumnInfo> hiveNonPartitionColsMap;
private final ImmutableMap<Integer, ColumnInfo> hivePartitionColsMap;
@@ -71,11 +72,12 @@ public class RelOptHiveTable extends Rel
.getLog(RelOptHiveTable.class
.getName());
- public RelOptHiveTable(RelOptSchema optiqSchema, String name, RelDataType rowType,
+ public RelOptHiveTable(RelOptSchema optiqSchema, String qualifiedTblName, String tblAlias, RelDataType rowType,
Table hiveTblMetadata, List<ColumnInfo> hiveNonPartitionCols,
List<ColumnInfo> hivePartitionCols, HiveConf hconf, Map<String, PrunedPartitionList> partitionCache, AtomicInteger noColsMissingStats) {
- super(optiqSchema, name, rowType);
+ super(optiqSchema, qualifiedTblName, rowType);
this.hiveTblMetadata = hiveTblMetadata;
+ this.tblAlias = tblAlias;
this.hiveNonPartitionCols = ImmutableList.copyOf(hiveNonPartitionCols);
this.hiveNonPartitionColsMap = getColInfoMap(hiveNonPartitionCols, 0);
this.hivePartitionColsMap = getColInfoMap(hivePartitionCols, hiveNonPartitionColsMap.size());
@@ -141,6 +143,19 @@ public class RelOptHiveTable extends Rel
return hiveTblMetadata;
}
+ public String getTableAlias() {
+ // NOTE: Optiq considers tbls to be equal if their names are the same. Hence
+ // we need to provide Optiq the fully qualified table name (dbname.tblname)
+ // and not the user provided aliases.
+ // However in HIVE DB name can not appear in select list; in case of join
+ // where table names differ only in DB name, Hive would require user
+ // introducing explicit aliases for tbl.
+ if (tblAlias == null)
+ return hiveTblMetadata.getTableName();
+ else
+ return tblAlias;
+ }
+
private String getColNamesForLogging(Set<String> colLst) {
StringBuffer sb = new StringBuffer();
boolean firstEntry = true;
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTBuilder.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTBuilder.java?rev=1627350&r1=1627349&r2=1627350&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTBuilder.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTBuilder.java Wed Sep 24 15:45:23 2014
@@ -54,13 +54,18 @@ class ASTBuilder {
static ASTNode table(TableAccessRelBase scan) {
RelOptHiveTable hTbl = (RelOptHiveTable) scan.getTable();
- ASTBuilder b = ASTBuilder
- .construct(HiveParser.TOK_TABREF, "TOK_TABREF")
- .add(
- ASTBuilder.construct(HiveParser.TOK_TABNAME, "TOK_TABNAME")
- .add(HiveParser.Identifier, hTbl.getHiveTableMD().getDbName())
- .add(HiveParser.Identifier, hTbl.getHiveTableMD().getTableName()))
- .add(HiveParser.Identifier, hTbl.getName());
+ ASTBuilder b = ASTBuilder.construct(HiveParser.TOK_TABREF, "TOK_TABREF").add(
+ ASTBuilder.construct(HiveParser.TOK_TABNAME, "TOK_TABNAME")
+ .add(HiveParser.Identifier, hTbl.getHiveTableMD().getDbName())
+ .add(HiveParser.Identifier, hTbl.getHiveTableMD().getTableName()));
+
+ // NOTE: Optiq considers tbls to be equal if their names are the same. Hence
+ // we need to provide Optiq the fully qualified table name (dbname.tblname)
+ // and not the user provided aliases.
+ // However in HIVE DB name can not appear in select list; in case of join
+ // where table names differ only in DB name, Hive would require user
+ // introducing explicit aliases for tbl.
+ b.add(HiveParser.Identifier, hTbl.getTableAlias());
return b.node();
}
@@ -154,11 +159,11 @@ class ASTBuilder {
type = HiveParser.BigintLiteral;
break;
case DOUBLE:
- val = literal.getValue3()+"D";
+ val = literal.getValue3() + "D";
type = HiveParser.Number;
break;
case DECIMAL:
- val = literal.getValue3()+"BD";
+ val = literal.getValue3() + "BD";
type = HiveParser.DecimalLiteral;
break;
case FLOAT:
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTConverter.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTConverter.java?rev=1627350&r1=1627349&r2=1627350&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTConverter.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/translator/ASTConverter.java Wed Sep 24 15:45:23 2014
@@ -27,6 +27,7 @@ import net.hydromatic.optiq.util.BitSets
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.ql.optimizer.optiq.OptiqSemanticException;
+import org.apache.hadoop.hive.ql.optimizer.optiq.RelOptHiveTable;
import org.apache.hadoop.hive.ql.optimizer.optiq.reloperators.HiveSortRel;
import org.apache.hadoop.hive.ql.optimizer.optiq.translator.SqlFunctionConverter.HiveToken;
import org.apache.hadoop.hive.ql.parse.ASTNode;
@@ -479,7 +480,7 @@ public class ASTConverter {
private static final long serialVersionUID = 1L;
Schema(TableAccessRelBase scan) {
- String tabName = scan.getTable().getQualifiedName().get(0);
+ String tabName = ((RelOptHiveTable)scan.getTable()).getTableAlias();
for (RelDataTypeField field : scan.getRowType().getFieldList()) {
add(new ColumnInfo(tabName, field.getName()));
}
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1627350&r1=1627349&r2=1627350&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Wed Sep 24 15:45:23 2014
@@ -12713,19 +12713,25 @@ public class SemanticAnalyzer extends Ba
RelDataType rowType = TypeConverter.getType(cluster, rr, null);
// 4. Build RelOptAbstractTable
- RelOptHiveTable optTable = new RelOptHiveTable(relOptSchema, tableAlias, rowType, tab,
- nonPartitionColumns, partitionColumns, conf, partitionCache, noColsMissingStats);
+ String fullyQualifiedTabName = tab.getDbName();
+ if (fullyQualifiedTabName != null && !fullyQualifiedTabName.isEmpty())
+ fullyQualifiedTabName = fullyQualifiedTabName + "." + tab.getTableName();
+ else
+ fullyQualifiedTabName = tab.getTableName();
+ RelOptHiveTable optTable = new RelOptHiveTable(relOptSchema, fullyQualifiedTabName,
+ tableAlias, rowType, tab, nonPartitionColumns, partitionColumns, conf, partitionCache,
+ noColsMissingStats);
// 5. Build Hive Table Scan Rel
- tableRel = new HiveTableScanRel(cluster, cluster.traitSetOf(HiveRel.CONVENTION),
- optTable, rowType);
+ tableRel = new HiveTableScanRel(cluster, cluster.traitSetOf(HiveRel.CONVENTION), optTable,
+ rowType);
// 6. Add Schema(RR) to RelNode-Schema map
ImmutableMap<String, Integer> hiveToOptiqColMap = buildHiveToOptiqColumnMap(rr, tableRel);
relToHiveRR.put(tableRel, rr);
relToHiveColNameOptiqPosMap.put(tableRel, hiveToOptiqColMap);
} catch (Exception e) {
- if ( e instanceof SemanticException) {
+ if (e instanceof SemanticException) {
throw (SemanticException) e;
} else {
throw (new RuntimeException(e));