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 d395db1b59..2873c747a7 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -412,6 +412,12 @@ private static final CommonToken DOT_TOKEN = new ImmutableCommonToken(HiveParser.DOT, "."); + private static final String[] UPDATED_TBL_PROPS = { + hive_metastoreConstants.TABLE_IS_TRANSACTIONAL, + hive_metastoreConstants.TABLE_TRANSACTIONAL_PROPERTIES, + hive_metastoreConstants.TABLE_BUCKETING_VERSION + }; + static class Phase1Ctx { String dest; int nextNum; @@ -13123,6 +13129,24 @@ private void validate(Task task, boolean reworkMapredWork) validate(childTask, reworkMapredWork); } } + + /** + * Update the default table properties with values fetch from the original table properties. The property names are + * defined in {@link SemanticAnalyzer#UPDATED_TBL_PROPS}. + * @param source properties of source table, must be not null. + * @param target properties of target table. + */ + private void updateDefaultTblProps(Map source, Map target) { + if (source == null || target == null) { + return; + } + for (String property : UPDATED_TBL_PROPS) { + if (source.containsKey(property)) { + target.put(property, source.get(property)); + } + } + } + /** * Add default properties for table property. If a default parameter exists * in the tblProp, the value in tblProp will be kept. @@ -13331,6 +13355,14 @@ ASTNode analyzeCreateTable( case HiveParser.TOK_LIKETABLE: if (child.getChildCount() > 0) { likeTableName = getUnescapedName((ASTNode) child.getChild(0)); + Table likeTable = getTable(likeTableName, false); + Map likeTableProps = likeTable.getParameters(); + if (likeTableProps.containsKey(hive_metastoreConstants.TABLE_IS_TRANSACTIONAL)) { + isTransactional = true; + } + if (likeTable.isTemporary()) { + isTemporary = true; + } if (likeTableName != null) { if (command_type == CTAS) { throw new SemanticException(ErrorMsg.CTAS_CTLT_COEXISTENCE @@ -13547,17 +13579,19 @@ ASTNode analyzeCreateTable( break; case CTLT: // create table like + tblProps = validateAndAddDefaultProperties( tblProps, isExt, storageFormat, dbDotTab, sortCols, isMaterialization, isTemporary, isTransactional); addDbAndTabToOutputs(qualifiedTabName, TableType.MANAGED_TABLE, isTemporary, tblProps); + Table likeTable = getTable(likeTableName, false); if (isTemporary) { - Table likeTable = getTable(likeTableName, false); 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."); } } + updateDefaultTblProps(likeTable.getParameters(), tblProps); CreateTableLikeDesc crtTblLikeDesc = new CreateTableLikeDesc(dbDotTab, isExt, isTemporary, storageFormat.getInputFormat(), storageFormat.getOutputFormat(), location, storageFormat.getSerde(), storageFormat.getSerdeProps(), tblProps, ifNotExists,