diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index eb7ef00..c285018 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -1982,7 +1982,12 @@ private void getMetaData(QB qb, ReadEntity parentInput) String tabName = qb.getTabNameForAlias(alias); String cteName = tabName.toLowerCase(); - Table tab = db.getTable(tabName, false); + // Get table details from tabNameToTabObject cache + Table tab = getTableObjectByName(tabName, false); + if (tab != null) { + // do a deep copy, in case downstream changes it. + tab = new Table(tab.getTTable().deepCopy()); + } if (tab == null || tab.getDbName().equals(SessionState.get().getCurrentDatabase())) { Table materializedTab = ctx.getMaterializedTable(cteName); @@ -10914,9 +10919,9 @@ void resetToken() { } } - private Table getTableObjectByName(String tableName) throws HiveException { + private Table getTableObjectByName(String tableName, boolean throwException) throws HiveException { if (!tabNameToTabObject.containsKey(tableName)) { - Table table = db.getTable(tableName); + Table table = db.getTable(tableName, throwException); tabNameToTabObject.put(tableName, table); return table; } else { @@ -10924,6 +10929,10 @@ private Table getTableObjectByName(String tableName) throws HiveException { } } + private Table getTableObjectByName(String tableName) throws HiveException { + return getTableObjectByName(tableName, true); + } + private void walkASTMarkTABREF(ASTNode ast, Set cteAlias) throws SemanticException { Queue queue = new LinkedList<>();