diff --git ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java index bc18ef5..fa10124 100644 --- ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java +++ ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java @@ -404,6 +404,7 @@ NO_COMPACTION_PARTITION(10283, "You must specify a partition to compact for partitioned tables"), TOO_MANY_COMPACTION_PARTITIONS(10284, "Compaction can only be requested on one partition at a " + "time."), + DISTINCT_NOT_SUPPORTED(10284, "Distinct keyword is not support in current context"), //========================== 20000 range starts here ========================// SCRIPT_INIT_ERROR(20000, "Unable to initialize custom script."), 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 d5acb2e..f6b4c1a 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -3191,6 +3191,7 @@ private static boolean isRegex(String pattern, HiveConf conf) { TypeCheckCtx tcCtx = new TypeCheckCtx(inputRR); // We allow stateful functions in the SELECT list (but nowhere else) tcCtx.setAllowStatefulFunctions(true); + tcCtx.setAllowDistinctFunctions(false); ExprNodeDesc exp = genExprNodeDesc(expr, inputRR, tcCtx); String recommended = recommendName(exp, colAlias); if (recommended != null && out_rwsch.get(null, recommended) == null) { diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckCtx.java ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckCtx.java index 5b0538c..a95ae20 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckCtx.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckCtx.java @@ -52,6 +52,8 @@ */ private boolean allowStatefulFunctions; + private boolean allowDistinctFunctions; + /** * Constructor. * @@ -62,6 +64,7 @@ public TypeCheckCtx(RowResolver inputRR) { setInputRR(inputRR); error = null; allowStatefulFunctions = false; + allowDistinctFunctions = true; } /** @@ -129,4 +132,11 @@ public ASTNode getErrorSrcNode() { return errorSrcNode; } + public void setAllowDistinctFunctions(boolean allowDistinctFunctions) { + this.allowDistinctFunctions = allowDistinctFunctions; + } + + public boolean isAllowDistinctFunctions() { + return allowDistinctFunctions; + } } diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java index 9a947ec..e7da289 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java @@ -1088,6 +1088,11 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, expr.getType() == HiveParser.TOK_FUNCTIONSTAR || expr.getType() == HiveParser.TOK_FUNCTIONDI); + if (!ctx.isAllowDistinctFunctions() && expr.getType() == HiveParser.TOK_FUNCTIONDI) { + throw new SemanticException( + SemanticAnalyzer.generateErrorMessage(expr, ErrorMsg.DISTINCT_NOT_SUPPORTED.getMsg())); + } + // Create all children int childrenBegin = (isFunction ? 1 : 0); ArrayList children = new ArrayList(expr diff --git ql/src/test/queries/clientnegative/invalid_distinct1.q ql/src/test/queries/clientnegative/invalid_distinct1.q new file mode 100644 index 0000000..538ef81 --- /dev/null +++ ql/src/test/queries/clientnegative/invalid_distinct1.q @@ -0,0 +1 @@ +explain select hash(distinct value) from src; diff --git ql/src/test/queries/clientnegative/invalid_distinct2.q ql/src/test/queries/clientnegative/invalid_distinct2.q new file mode 100644 index 0000000..b01218e --- /dev/null +++ ql/src/test/queries/clientnegative/invalid_distinct2.q @@ -0,0 +1 @@ +explain select explode(distinct value) from src; diff --git ql/src/test/queries/clientnegative/invalid_distinct3.q ql/src/test/queries/clientnegative/invalid_distinct3.q new file mode 100644 index 0000000..ec8026b --- /dev/null +++ ql/src/test/queries/clientnegative/invalid_distinct3.q @@ -0,0 +1 @@ +explain select hash(upper(distinct value)) from src; diff --git ql/src/test/results/clientnegative/invalid_distinct1.q.out ql/src/test/results/clientnegative/invalid_distinct1.q.out new file mode 100644 index 0000000..c1c95a9 --- /dev/null +++ ql/src/test/results/clientnegative/invalid_distinct1.q.out @@ -0,0 +1 @@ +FAILED: SemanticException 1:15 Distinct keyword is not support in current context. Error encountered near token 'value' diff --git ql/src/test/results/clientnegative/invalid_distinct2.q.out ql/src/test/results/clientnegative/invalid_distinct2.q.out new file mode 100644 index 0000000..c1c95a9 --- /dev/null +++ ql/src/test/results/clientnegative/invalid_distinct2.q.out @@ -0,0 +1 @@ +FAILED: SemanticException 1:15 Distinct keyword is not support in current context. Error encountered near token 'value' diff --git ql/src/test/results/clientnegative/invalid_distinct3.q.out ql/src/test/results/clientnegative/invalid_distinct3.q.out new file mode 100644 index 0000000..e478860 --- /dev/null +++ ql/src/test/results/clientnegative/invalid_distinct3.q.out @@ -0,0 +1 @@ +FAILED: SemanticException 1:20 Distinct keyword is not support in current context. Error encountered near token 'value'