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 cde8eada64..7bce4f7e70 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 @@ -5222,10 +5222,14 @@ private QBParseInfo getQBParseInfo(QB qb) throws CalciteSemanticException { } @Override - protected Table getTableObjectByName(String tableName, boolean throwException) throws HiveException { - if (!tabNameToTabObject.containsKey(tableName)) { + protected Table getTableObjectByName(String tabName, boolean throwException) throws HiveException { + String[] names = Utilities.getDbTableName(tabName); + final String tableName = names[1]; + final String dbName = names[0]; + final String fullyQualName = dbName + "." + tableName; + if (!tabNameToTabObject.containsKey(fullyQualName)) { // TODO: The code below should be a single HMS call and possibly unified with method in SemanticAnalyzer - Table table = db.getTable(tableName, throwException); + Table table = db.getTable(dbName, tableName, throwException); if (table != null) { table.setPrimaryKeyInfo(db.getReliablePrimaryKeys( table.getDbName(), table.getTableName())); @@ -5235,11 +5239,11 @@ protected Table getTableObjectByName(String tableName, boolean throwException) t table.getDbName(), table.getTableName())); table.setNotNullConstraint(db.getReliableNotNullConstraints( table.getDbName(), table.getTableName())); - tabNameToTabObject.put(tableName, table); + tabNameToTabObject.put(fullyQualName, table); } return table; } - return tabNameToTabObject.get(tableName); + return tabNameToTabObject.get(fullyQualName); } /** diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 6adfb6d16c..ee52ec3673 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -484,7 +484,7 @@ protected void reset(boolean clearCache) { } else { mergeIsDirect = false; } - tabNameToTabObject.clear(); + //tabNameToTabObject.clear(); loadTableWork.clear(); loadFileWork.clear(); columnStatsAutoGatherContexts.clear(); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java index 8084dcd62a..cb2d0a7a7e 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java @@ -1024,7 +1024,7 @@ else if(colTypeLowerCase.equals(serdeConstants.SMALLINT_TYPE_NAME)){ // This table is dummy and has no stats return stats; } - if (fetchColStats) { + if (fetchColStats && !colStatsToRetrieve.isEmpty()) { try { List colStat = Hive.get().getTableColumnStatistics( dbName, tabName, colStatsToRetrieve, false);