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 08176a6..80d6289 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java @@ -291,6 +291,7 @@ public enum ErrorMsg { HIVE_GROUPING_SETS_EXPR_NOT_IN_GROUPBY(10213, "Grouping sets expression is not in GROUP BY key"), + INVALID_PARTITION_SPEC(10214, "Invalid partition spec specified"), 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/DDLSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java index 276bfdd..86929f4 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java @@ -2325,6 +2325,11 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer { } for (AddPartitionDesc addPartitionDesc : partitionDescs) { + try { + tab.isValidSpec(addPartitionDesc.getPartSpec()); + } catch (HiveException ex) { + throw new SemanticException(ErrorMsg.INVALID_PARTITION_SPEC.getMsg(ex.getMessage())); + } rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), addPartitionDesc), conf)); } @@ -2344,7 +2349,7 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer { // actually returns false). tab.isValidSpec(partitionDesc.getPartSpec()); } catch (HiveException ex) { - throw new SemanticException(ex.getMessage(), ex); + throw new SemanticException(ErrorMsg.INVALID_PARTITION_SPEC.getMsg(ex.getMessage())); } if (firstOr) { firstOr = false; diff --git a/ql/src/test/queries/clientnegative/alter_table_add_partition.q b/ql/src/test/queries/clientnegative/alter_table_add_partition.q new file mode 100644 index 0000000..2427c3b --- /dev/null +++ b/ql/src/test/queries/clientnegative/alter_table_add_partition.q @@ -0,0 +1,5 @@ +create table mp (a int) partitioned by (b int); + +-- should fail +alter table mp add partition (b='1', c='1'); + diff --git a/ql/src/test/results/clientnegative/alter_table_add_partition.q.out b/ql/src/test/results/clientnegative/alter_table_add_partition.q.out new file mode 100644 index 0000000..bd9c148 --- /dev/null +++ b/ql/src/test/results/clientnegative/alter_table_add_partition.q.out @@ -0,0 +1,6 @@ +PREHOOK: query: create table mp (a int) partitioned by (b int) +PREHOOK: type: CREATETABLE +POSTHOOK: query: create table mp (a int) partitioned by (b int) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@mp +FAILED: SemanticException [Error 10214]: Invalid partition spec specified table is partitioned but partition spec is not specified or does not fully match table partitioning: {b=1, c=1}