Skip to content
Permalink
Browse files
[Bug][CTAS] create table by partition list (#9412)

Co-authored-by: Rongqian Li <rongqian_li@idgcapital.com>
  • Loading branch information
stalary and stalary committed May 7, 2022
1 parent ba2cc98 commit b6a74cfea5ddf3c66dcf3b4d31ec9a5131d66590
Showing 2 changed files with 275 additions and 183 deletions.
@@ -265,6 +265,7 @@
import com.sleepycat.je.rep.NetworkRestoreConfig;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -3133,10 +3134,17 @@ public void createTableAsSelect(CreateTableAsSelectStmt stmt) throws DdlExceptio
} else {
typeDef = new TypeDef(resultExpr.getType());
}
createTableStmt.addColumnDef(new ColumnDef(name, typeDef, false,
null, true,
new DefaultValue(false, null),
""));
ColumnDef columnDef;
if (resultExpr.getSrcSlotRef() == null) {
columnDef = new ColumnDef(name, typeDef, false, null, true, new DefaultValue(false, null), "");
} else {
Column column = resultExpr.getSrcSlotRef().getDesc().getColumn();
boolean setDefault = StringUtils.isNotBlank(column.getDefaultValue());
columnDef = new ColumnDef(name, typeDef, column.isKey(),
column.getAggregationType(), column.isAllowNull(),
new DefaultValue(setDefault, column.getDefaultValue()), column.getComment());
}
createTableStmt.addColumnDef(columnDef);
// set first column as default distribution
if (createTableStmt.getDistributionDesc() == null && i == 0) {
createTableStmt.setDistributionDesc(new HashDistributionDesc(10, Lists.newArrayList(name)));

0 comments on commit b6a74cf

Please sign in to comment.