diff --git a/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java b/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java index 7abef0ba06d69644c325355416225453fe89f28b..87c28301bcc556930697ea5de721c6fe232c6aaf 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java @@ -432,7 +432,7 @@ UPDATE_CANNOT_UPDATE_BUCKET_VALUE(10302, "Updating values of bucketing columns is not supported. Column {0}.", true), IMPORT_INTO_STRICT_REPL_TABLE(10303,"Non-repl import disallowed against table that is a destination of replication."), CTAS_LOCATION_NONEMPTY(10304, "CREATE-TABLE-AS-SELECT cannot create table with location to a non-empty directory."), - + CTAS_CREATES_VOID_TYPE(10305, "CREATE-TABLE-AS-SELECT creates a VOID type, please use CAST to specify the type, near field: "), //========================== 20000 range starts here ========================// SCRIPT_INIT_ERROR(20000, "Unable to initialize custom script."), SCRIPT_IO_ERROR(20001, "An error occurred while reading or writing to your custom script. " 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 1076dfd4c10e51c7a6ba1ad9101941bc473da483..c5f39d3f7650d647fda4115b886ddce697b494b7 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 @@ -6477,7 +6477,13 @@ protected Operator genFileSinkPlan(String dest, QB qb, Operator input) } colName = fixCtasColumnName(colName); col.setName(colName); - col.setType(colInfo.getType().getTypeName()); + String typeName = colInfo.getType().getTypeName(); + // CTAS should NOT create a VOID type + if (typeName.equals(serdeConstants.VOID_TYPE_NAME)) { + throw new SemanticException(ErrorMsg.CTAS_CREATES_VOID_TYPE + .getMsg(colName)); + } + col.setType(typeName); field_schemas.add(col); } diff --git a/ql/src/test/queries/clientnegative/ctasnullcol.q b/ql/src/test/queries/clientnegative/ctasnullcol.q new file mode 100644 index 0000000000000000000000000000000000000000..b03c172934c41a8fc40f548276fe6796582bc590 --- /dev/null +++ b/ql/src/test/queries/clientnegative/ctasnullcol.q @@ -0,0 +1,2 @@ +drop table if exists orc_table_with_null; +CREATE TABLE orc_table_with_null STORED AS ORC AS SELECT key, null FROM src; diff --git a/ql/src/test/results/clientnegative/ctasnullcol.q.out b/ql/src/test/results/clientnegative/ctasnullcol.q.out new file mode 100644 index 0000000000000000000000000000000000000000..6d36bb8247baf8a5907beb7ac95469809bd68c1f --- /dev/null +++ b/ql/src/test/results/clientnegative/ctasnullcol.q.out @@ -0,0 +1,5 @@ +PREHOOK: query: drop table if exists orc_table_with_null +PREHOOK: type: DROPTABLE +POSTHOOK: query: drop table if exists orc_table_with_null +POSTHOOK: type: DROPTABLE +FAILED: SemanticException [Error 10305]: CREATE-TABLE-AS-SELECT creates a VOID type, please use CAST to specify the type, near field: c1