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 e09fc379f5..de9e452c01 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -13135,13 +13135,14 @@ private void validate(Task task, boolean reworkMapredWork) * defined in {@link SemanticAnalyzer#UPDATED_TBL_PROPS}. * @param source properties of source table, must be not null. * @param target properties of target table. + * @param skipped a list of properties which should be not overwritten. It can be null or empty. */ - private void updateDefaultTblProps(Map source, Map target) { + private void updateDefaultTblProps(Map source, Map target, List skipped) { if (source == null || target == null) { return; } for (String property : UPDATED_TBL_PROPS) { - if (source.containsKey(property)) { + if ((skipped == null || !skipped.contains(property)) && source.containsKey(property)) { target.put(property, source.get(property)); } } @@ -13356,16 +13357,6 @@ ASTNode analyzeCreateTable( if (child.getChildCount() > 0) { likeTableName = getUnescapedName((ASTNode) child.getChild(0)); if (likeTableName != null) { - Table likeTable = getTable(likeTableName, false); - if (likeTable != null) { - Map likeTableProps = likeTable.getParameters(); - if (likeTableProps.containsKey(hive_metastoreConstants.TABLE_IS_TRANSACTIONAL)) { - isTransactional = true; - } - if (likeTable.isTemporary()) { - isTemporary = true; - } - } if (command_type == CTAS) { throw new SemanticException(ErrorMsg.CTAS_CTLT_COEXISTENCE .getMsg()); @@ -13587,14 +13578,18 @@ ASTNode analyzeCreateTable( addDbAndTabToOutputs(qualifiedTabName, TableType.MANAGED_TABLE, isTemporary, tblProps); Table likeTable = getTable(likeTableName, false); - if (isTemporary) { - if (likeTable != null && likeTable.getPartCols().size() > 0) { - throw new SemanticException("Partition columns are not supported on temporary tables " - + "and source table in CREATE TABLE LIKE is partitioned."); - } - } if (likeTable != null) { - updateDefaultTblProps(likeTable.getParameters(), tblProps); + if (isTemporary) { + if (likeTable.getPartCols().size() > 0) { + throw new SemanticException("Partition columns are not supported on temporary tables " + + "and source table in CREATE TABLE LIKE is partitioned."); + } + updateDefaultTblProps(likeTable.getParameters(), tblProps, + new ArrayList<>(Arrays.asList(hive_metastoreConstants.TABLE_IS_TRANSACTIONAL, + hive_metastoreConstants.TABLE_TRANSACTIONAL_PROPERTIES))); + } else { + updateDefaultTblProps(likeTable.getParameters(), tblProps, null); + } } CreateTableLikeDesc crtTblLikeDesc = new CreateTableLikeDesc(dbDotTab, isExt, isTemporary, storageFormat.getInputFormat(), storageFormat.getOutputFormat(), location,