You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by we...@apache.org on 2017/05/08 22:17:50 UTC
[33/50] [abbrv] hive git commit: HIVE-13583: E061-14: Search
Conditions (Zoltan Haindrich, reviewed by Ashutosh Chauhan)
HIVE-13583: E061-14: Search Conditions (Zoltan Haindrich, reviewed by Ashutosh Chauhan)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/54dbca69
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/54dbca69
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/54dbca69
Branch: refs/heads/hive-14535
Commit: 54dbca69c9ea630b9cccd5550bdb455b9bbc240c
Parents: 0f8840a
Author: Zoltan Haindrich <ki...@rxd.hu>
Authored: Mon May 8 07:27:01 2017 +0200
Committer: Zoltan Haindrich <ki...@rxd.hu>
Committed: Mon May 8 07:44:07 2017 +0200
----------------------------------------------------------------------
.../hadoop/hive/ql/exec/FunctionRegistry.java | 4 +
.../translator/SqlFunctionConverter.java | 4 +-
.../apache/hadoop/hive/ql/parse/HiveParser.g | 4 -
.../hadoop/hive/ql/parse/IdentifiersParser.g | 19 ++-
.../hadoop/hive/ql/parse/SubQueryUtils.java | 2 +-
.../hive/ql/parse/TypeCheckProcFactory.java | 9 --
.../hive/ql/udf/generic/GenericUDFOPFalse.java | 65 +++++++++
.../ql/udf/generic/GenericUDFOPNotFalse.java | 65 +++++++++
.../ql/udf/generic/GenericUDFOPNotTrue.java | 65 +++++++++
.../hive/ql/udf/generic/GenericUDFOPTrue.java | 65 +++++++++
.../apache/hadoop/hive/ql/parse/TestIUD.java | 8 +-
.../hive/ql/parse/TestMergeStatement.java | 4 +-
ql/src/test/queries/clientpositive/udf_isops.q | 34 +++++
.../results/clientpositive/show_functions.q.out | 8 +
.../test/results/clientpositive/udf_isops.q.out | 146 +++++++++++++++++++
15 files changed, 472 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
index 1b556ac..bf18a8d 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
@@ -359,6 +359,10 @@ public final class FunctionRegistry {
system.registerGenericUDF("isnull", GenericUDFOPNull.class);
system.registerGenericUDF("isnotnull", GenericUDFOPNotNull.class);
+ system.registerGenericUDF("istrue", GenericUDFOPTrue.class);
+ system.registerGenericUDF("isnottrue", GenericUDFOPNotTrue.class);
+ system.registerGenericUDF("isfalse", GenericUDFOPFalse.class);
+ system.registerGenericUDF("isnotfalse", GenericUDFOPNotFalse.class);
system.registerGenericUDF("if", GenericUDFIf.class);
system.registerGenericUDF("in", GenericUDFIn.class);
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java
index 10f5eb3..c6b34d4 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java
@@ -350,8 +350,8 @@ public class SqlFunctionConverter {
registerFunction("in", HiveIn.INSTANCE, hToken(HiveParser.Identifier, "in"));
registerFunction("between", HiveBetween.INSTANCE, hToken(HiveParser.Identifier, "between"));
registerFunction("struct", SqlStdOperatorTable.ROW, hToken(HiveParser.Identifier, "struct"));
- registerFunction("isnotnull", SqlStdOperatorTable.IS_NOT_NULL, hToken(HiveParser.TOK_ISNOTNULL, "TOK_ISNOTNULL"));
- registerFunction("isnull", SqlStdOperatorTable.IS_NULL, hToken(HiveParser.TOK_ISNULL, "TOK_ISNULL"));
+ registerFunction("isnotnull", SqlStdOperatorTable.IS_NOT_NULL, hToken(HiveParser.Identifier, "isnotnull"));
+ registerFunction("isnull", SqlStdOperatorTable.IS_NULL, hToken(HiveParser.Identifier, "isnull"));
registerFunction("is not distinct from", SqlStdOperatorTable.IS_NOT_DISTINCT_FROM, hToken(HiveParser.EQUAL_NS, "<=>"));
registerFunction("when", SqlStdOperatorTable.CASE, hToken(HiveParser.Identifier, "when"));
registerDuplicateFunction("case", SqlStdOperatorTable.CASE, hToken(HiveParser.Identifier, "when"));
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
index ca639d3..3136c93 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
@@ -105,8 +105,6 @@ TOK_IMPORT;
TOK_REPLICATION;
TOK_METADATA;
TOK_NULL;
-TOK_ISNULL;
-TOK_ISNOTNULL;
TOK_PRIMARY_KEY;
TOK_FOREIGN_KEY;
TOK_VALIDATE;
@@ -397,8 +395,6 @@ TOK_OPERATOR;
TOK_EXPRESSION;
TOK_DETAIL;
TOK_BLOCKING;
-TOK_LIKEANY;
-TOK_LIKEALL;
}
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g b/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g
index 645ced9..1c78c1a 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g
@@ -435,10 +435,13 @@ precedenceUnaryOperator
PLUS | MINUS | TILDE
;
-nullCondition
- :
- KW_NULL -> ^(TOK_ISNULL)
- | KW_NOT KW_NULL -> ^(TOK_ISNOTNULL)
+isCondition
+ : KW_NULL -> Identifier["isnull"]
+ | KW_TRUE -> Identifier["istrue"]
+ | KW_FALSE -> Identifier["isfalse"]
+ | KW_NOT KW_NULL -> Identifier["isnotnull"]
+ | KW_NOT KW_TRUE -> Identifier["isnottrue"]
+ | KW_NOT KW_FALSE -> Identifier["isnotfalse"]
;
precedenceUnaryPrefixExpression
@@ -447,8 +450,8 @@ precedenceUnaryPrefixExpression
;
precedenceUnarySuffixExpression
- : precedenceUnaryPrefixExpression (a=KW_IS nullCondition)?
- -> {$a != null}? ^(TOK_FUNCTION nullCondition precedenceUnaryPrefixExpression)
+ : precedenceUnaryPrefixExpression (a=KW_IS isCondition)?
+ -> {$a != null}? ^(TOK_FUNCTION isCondition precedenceUnaryPrefixExpression)
-> precedenceUnaryPrefixExpression
;
@@ -569,10 +572,10 @@ precedenceSimilarExpressionAtom[CommonTree t]
-> ^(TOK_FUNCTION Identifier["between"] KW_FALSE {$t} $min $max)
|
KW_LIKE KW_ANY (expr=expressionsInParenthesis[false])
- -> ^(TOK_FUNCTION TOK_LIKEANY {$t} {$expr.tree})
+ -> ^(TOK_FUNCTION Identifier["likeany"] {$t} {$expr.tree})
|
KW_LIKE KW_ALL (expr=expressionsInParenthesis[false])
- -> ^(TOK_FUNCTION TOK_LIKEALL {$t} {$expr.tree})
+ -> ^(TOK_FUNCTION Identifier["likeall"] {$t} {$expr.tree})
;
precedenceSimilarExpressionIn[CommonTree t]
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/parse/SubQueryUtils.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SubQueryUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SubQueryUtils.java
index 06cf56d..45db6f6 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SubQueryUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SubQueryUtils.java
@@ -95,7 +95,7 @@ public class SubQueryUtils {
static ASTNode isNull(ASTNode expr) {
ASTNode node = (ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_FUNCTION, "TOK_FUNCTION");
- node.addChild((ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_ISNULL, "TOK_ISNULL"));
+ node.addChild((ASTNode) ParseDriver.adaptor.create(HiveParser.Identifier, "isnull"));
node.addChild(expr);
return node;
}
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
index c3227c9..82141be 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
@@ -198,7 +198,6 @@ public class TypeCheckProcFactory {
+ HiveParser.KW_WHEN + "%|" + HiveParser.KW_IN + "%|"
+ HiveParser.KW_ARRAY + "%|" + HiveParser.KW_MAP + "%|"
+ HiveParser.KW_STRUCT + "%|" + HiveParser.KW_EXISTS + "%|"
- + HiveParser.TOK_LIKEALL + "%|" + HiveParser.TOK_LIKEANY + "%|"
+ HiveParser.TOK_SUBQUERY_OP_NOTIN + "%"),
tf.getStrExprProcessor());
opRules.put(new RuleRegExp("R4", HiveParser.KW_TRUE + "%|"
@@ -715,18 +714,12 @@ public class TypeCheckProcFactory {
public static class DefaultExprProcessor implements NodeProcessor {
static HashMap<Integer, String> specialUnaryOperatorTextHashMap;
- static HashMap<Integer, String> specialFunctionTextHashMap;
static HashMap<Integer, String> conversionFunctionTextHashMap;
static HashSet<Integer> windowingTokens;
static {
specialUnaryOperatorTextHashMap = new HashMap<Integer, String>();
specialUnaryOperatorTextHashMap.put(HiveParser.PLUS, "positive");
specialUnaryOperatorTextHashMap.put(HiveParser.MINUS, "negative");
- specialFunctionTextHashMap = new HashMap<Integer, String>();
- specialFunctionTextHashMap.put(HiveParser.TOK_ISNULL, "isnull");
- specialFunctionTextHashMap.put(HiveParser.TOK_ISNOTNULL, "isnotnull");
- specialFunctionTextHashMap.put(HiveParser.TOK_LIKEANY, "likeany");
- specialFunctionTextHashMap.put(HiveParser.TOK_LIKEALL, "likeall");
conversionFunctionTextHashMap = new HashMap<Integer, String>();
conversionFunctionTextHashMap.put(HiveParser.TOK_BOOLEAN,
serdeConstants.BOOLEAN_TYPE_NAME);
@@ -818,7 +811,6 @@ public class TypeCheckProcFactory {
// special dictionary.
assert (expr.getChildCount() >= 1);
int funcType = ((ASTNode) expr.getChild(0)).getType();
- funcText = specialFunctionTextHashMap.get(funcType);
if (funcText == null) {
funcText = conversionFunctionTextHashMap.get(funcType);
}
@@ -1305,7 +1297,6 @@ public class TypeCheckProcFactory {
// Return nulls for conversion operators
if (conversionFunctionTextHashMap.keySet().contains(expr.getType())
- || specialFunctionTextHashMap.keySet().contains(expr.getType())
|| expr.getToken().getType() == HiveParser.CharSetName
|| expr.getToken().getType() == HiveParser.CharSetLiteral) {
return null;
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPFalse.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPFalse.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPFalse.java
new file mode 100644
index 0000000..b74abd3
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPFalse.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.BooleanWritable;
+
+@Description(name = "isfalse", value = "_FUNC_ a - Returns true if a is FALSE and false otherwise")
+@NDV(maxNdv = 2)
+public class GenericUDFOPFalse extends GenericUDF {
+ private final BooleanWritable result = new BooleanWritable();
+ private Converter conditionConverter;
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+ if (arguments.length != 1) {
+ throw new UDFArgumentLengthException("Invalid number of arguments");
+ }
+ conditionConverter = ObjectInspectorConverters.getConverter(arguments[0],
+ PrimitiveObjectInspectorFactory.writableBooleanObjectInspector);
+
+ return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
+ }
+
+ @Override
+ public Object evaluate(DeferredObject[] arguments) throws HiveException {
+ BooleanWritable condition = (BooleanWritable) conditionConverter.convert(arguments[0].get());
+ result.set(condition != null && !condition.get());
+ return result;
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == 1);
+ return children[0] + " is false";
+ }
+
+ @Override
+ public GenericUDF negative() {
+ return new GenericUDFOPNotFalse();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotFalse.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotFalse.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotFalse.java
new file mode 100644
index 0000000..229ed4d
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotFalse.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.BooleanWritable;
+
+@Description(name = "isnotfalse", value = "_FUNC_ a - Returns true if a is NOT FALSE and false otherwise")
+@NDV(maxNdv = 2)
+public class GenericUDFOPNotFalse extends GenericUDF {
+ private final BooleanWritable result = new BooleanWritable();
+ private Converter conditionConverter;
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+ if (arguments.length != 1) {
+ throw new UDFArgumentLengthException("Invalid number of arguments");
+ }
+ conditionConverter = ObjectInspectorConverters.getConverter(arguments[0],
+ PrimitiveObjectInspectorFactory.writableBooleanObjectInspector);
+
+ return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
+ }
+
+ @Override
+ public Object evaluate(DeferredObject[] arguments) throws HiveException {
+ BooleanWritable condition = (BooleanWritable) conditionConverter.convert(arguments[0].get());
+ result.set(condition == null || condition.get());
+ return result;
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == 1);
+ return children[0] + " is not false";
+ }
+
+ @Override
+ public GenericUDF negative() {
+ return new GenericUDFOPFalse();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotTrue.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotTrue.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotTrue.java
new file mode 100644
index 0000000..bf639af
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotTrue.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.BooleanWritable;
+
+@Description(name = "isnottrue", value = "_FUNC_ a - Returns true if a is NOT TRUE and false otherwise")
+@NDV(maxNdv = 2)
+public class GenericUDFOPNotTrue extends GenericUDF {
+ private final BooleanWritable result = new BooleanWritable();
+ private Converter conditionConverter;
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+ if (arguments.length != 1) {
+ throw new UDFArgumentLengthException("Invalid number of arguments");
+ }
+ conditionConverter = ObjectInspectorConverters.getConverter(arguments[0],
+ PrimitiveObjectInspectorFactory.writableBooleanObjectInspector);
+
+ return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
+ }
+
+ @Override
+ public Object evaluate(DeferredObject[] arguments) throws HiveException {
+ BooleanWritable condition = (BooleanWritable) conditionConverter.convert(arguments[0].get());
+ result.set(condition == null || !condition.get());
+ return result;
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == 1);
+ return children[0] + " is not true";
+ }
+
+ @Override
+ public GenericUDF negative() {
+ return new GenericUDFOPTrue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPTrue.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPTrue.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPTrue.java
new file mode 100644
index 0000000..764f705
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPTrue.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.BooleanWritable;
+
+@Description(name = "istrue", value = "_FUNC_ a - Returns true if a is TRUE and false otherwise")
+@NDV(maxNdv = 2)
+public class GenericUDFOPTrue extends GenericUDF {
+ private final BooleanWritable result = new BooleanWritable();
+ private Converter conditionConverter;
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+ if (arguments.length != 1) {
+ throw new UDFArgumentLengthException("Invalid number of arguments");
+ }
+ conditionConverter = ObjectInspectorConverters.getConverter(arguments[0],
+ PrimitiveObjectInspectorFactory.writableBooleanObjectInspector);
+
+ return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
+ }
+
+ @Override
+ public Object evaluate(DeferredObject[] arguments) throws HiveException {
+ BooleanWritable condition = (BooleanWritable) conditionConverter.convert(arguments[0].get());
+ result.set(condition != null && condition.get());
+ return result;
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == 1);
+ return children[0] + " is true";
+ }
+
+ @Override
+ public GenericUDF negative() {
+ return new GenericUDFOPNotTrue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/test/org/apache/hadoop/hive/ql/parse/TestIUD.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestIUD.java b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestIUD.java
index 4ed765d..5f8ed93 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestIUD.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestIUD.java
@@ -73,7 +73,7 @@ public class TestIUD {
"(tok_tabname src) " +
"(tok_where " +
"(and " +
- "(tok_function tok_isnotnull (tok_table_or_col key)) " +
+ "(tok_function isnotnull (tok_table_or_col key)) " +
"(< (. (tok_table_or_col src) value) 0))))",
ast.toStringTree());
}
@@ -110,7 +110,7 @@ public class TestIUD {
"(tok_set_columns_clause " +
"(= " +
"(tok_table_or_col key) 3)) " +
- "(tok_where (tok_function tok_isnull (tok_table_or_col value))))",
+ "(tok_where (tok_function isnull (tok_table_or_col value))))",
ast.toStringTree());
}
@Test
@@ -122,7 +122,7 @@ public class TestIUD {
"(= (tok_table_or_col key) (+ (- 3) (% (* 5 9) 8))) " +
"(= (tok_table_or_col val) (tok_function tok_int (+ 6.1 (tok_table_or_col c)))) " +
"(= (tok_table_or_col d) (- (tok_table_or_col d) 1))) " +
- "(tok_where (tok_function tok_isnull (tok_table_or_col value))))",
+ "(tok_where (tok_function isnull (tok_table_or_col value))))",
ast.toStringTree());
}
@Test
@@ -150,7 +150,7 @@ public class TestIUD {
"(tok_select " +
"(tok_selexpr (. (tok_table_or_col pvs) viewtime)) " +
"(tok_selexpr (. (tok_table_or_col pvs) userid))) " +
- "(tok_where (tok_function tok_isnull (. (tok_table_or_col pvs) userid)))))",
+ "(tok_where (tok_function isnull (. (tok_table_or_col pvs) userid)))))",
ast.toStringTree());
}
@Test
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/test/org/apache/hadoop/hive/ql/parse/TestMergeStatement.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestMergeStatement.java b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestMergeStatement.java
index 8e0ac9d..5bdffb5 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestMergeStatement.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestMergeStatement.java
@@ -87,7 +87,7 @@ public class TestMergeStatement {
"(tok_update " +
"(tok_set_columns_clause " +
"(= (tok_table_or_col a) (. (tok_table_or_col source) b)) " +
- "(= (tok_table_or_col b) (tok_function when (tok_function tok_isnull (tok_table_or_col c1)) (tok_table_or_col c1) (tok_table_or_col c1)))" +
+ "(= (tok_table_or_col b) (tok_function when (tok_function isnull (tok_table_or_col c1)) (tok_table_or_col c1) (tok_table_or_col c1)))" +
")" +
") " +
"(< (. (tok_table_or_col source) c2) (tok_function current_time)))" +
@@ -129,7 +129,7 @@ public class TestMergeStatement {
"(tok_value_row " +
"(. (tok_table_or_col source) a) " +
"(tok_function when " +
- "(tok_function tok_isnull (. (tok_table_or_col source) b)) (. (tok_table_or_col target) b) " +
+ "(tok_function isnull (. (tok_table_or_col source) b)) (. (tok_table_or_col target) b) " +
"(. (tok_table_or_col source) b)" +
")" +
")" +
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/test/queries/clientpositive/udf_isops.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/udf_isops.q b/ql/src/test/queries/clientpositive/udf_isops.q
new file mode 100644
index 0000000..414209e
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/udf_isops.q
@@ -0,0 +1,34 @@
+drop table if exists t;
+create table t (a int,v int, b boolean);
+insert into t values (1,null, true);
+insert into t values (2,1, false);
+insert into t values (3,2, null);
+
+select assert_true(sum(a*a) = 1) from t
+ where v is null;
+select assert_true(sum(a*a) = 2*2+3*3) from t
+ where v is not null;
+
+select assert_true(sum(a*a) = 1) from t
+ where b is true;
+
+select assert_true(sum(a*a) = 2*2 + 3*3) from t
+ where b is not true;
+
+select assert_true(sum(a*a) = 4) from t
+ where b is false;
+
+select assert_true(sum(a*a) = 1*1 + 3*3) from t
+ where b is not false;
+
+select assert_true(sum(a*a) = 2*2) from t
+ where (v>0 and v<2) is true;
+
+select assert_true(sum(a*a) = 2*2) from t
+ where (v<2) is true;
+
+select NULL is true,
+ NULL is not true,
+ NULL is false,
+ NULL is not false
+from t;
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/test/results/clientpositive/show_functions.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/show_functions.q.out b/ql/src/test/results/clientpositive/show_functions.q.out
index e638638..31653a6 100644
--- a/ql/src/test/results/clientpositive/show_functions.q.out
+++ b/ql/src/test/results/clientpositive/show_functions.q.out
@@ -121,8 +121,12 @@ initcap
inline
instr
internal_interval
+isfalse
+isnotfalse
isnotnull
+isnottrue
isnull
+istrue
java_method
json_tuple
lag
@@ -327,6 +331,10 @@ floor_minute
from_unixtime
in_file
inline
+isfalse
+isnotfalse
+isnottrue
+istrue
json_tuple
last_value
lcase
http://git-wip-us.apache.org/repos/asf/hive/blob/54dbca69/ql/src/test/results/clientpositive/udf_isops.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/udf_isops.q.out b/ql/src/test/results/clientpositive/udf_isops.q.out
new file mode 100644
index 0000000..0b6b35e
--- /dev/null
+++ b/ql/src/test/results/clientpositive/udf_isops.q.out
@@ -0,0 +1,146 @@
+PREHOOK: query: drop table if exists t
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table if exists t
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: create table t (a int,v int, b boolean)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@t
+POSTHOOK: query: create table t (a int,v int, b boolean)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@t
+PREHOOK: query: insert into t values (1,null, true)
+PREHOOK: type: QUERY
+PREHOOK: Output: default@t
+POSTHOOK: query: insert into t values (1,null, true)
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@t
+POSTHOOK: Lineage: t.a EXPRESSION [(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col1, type:string, comment:), ]
+POSTHOOK: Lineage: t.b EXPRESSION [(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col3, type:string, comment:), ]
+POSTHOOK: Lineage: t.v EXPRESSION [(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col2, type:string, comment:), ]
+PREHOOK: query: insert into t values (2,1, false)
+PREHOOK: type: QUERY
+PREHOOK: Output: default@t
+POSTHOOK: query: insert into t values (2,1, false)
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@t
+POSTHOOK: Lineage: t.a EXPRESSION [(values__tmp__table__2)values__tmp__table__2.FieldSchema(name:tmp_values_col1, type:string, comment:), ]
+POSTHOOK: Lineage: t.b EXPRESSION [(values__tmp__table__2)values__tmp__table__2.FieldSchema(name:tmp_values_col3, type:string, comment:), ]
+POSTHOOK: Lineage: t.v EXPRESSION [(values__tmp__table__2)values__tmp__table__2.FieldSchema(name:tmp_values_col2, type:string, comment:), ]
+PREHOOK: query: insert into t values (3,2, null)
+PREHOOK: type: QUERY
+PREHOOK: Output: default@t
+POSTHOOK: query: insert into t values (3,2, null)
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@t
+POSTHOOK: Lineage: t.a EXPRESSION [(values__tmp__table__3)values__tmp__table__3.FieldSchema(name:tmp_values_col1, type:string, comment:), ]
+POSTHOOK: Lineage: t.b EXPRESSION [(values__tmp__table__3)values__tmp__table__3.FieldSchema(name:tmp_values_col3, type:string, comment:), ]
+POSTHOOK: Lineage: t.v EXPRESSION [(values__tmp__table__3)values__tmp__table__3.FieldSchema(name:tmp_values_col2, type:string, comment:), ]
+PREHOOK: query: select assert_true(sum(a*a) = 1) from t
+ where v is null
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select assert_true(sum(a*a) = 1) from t
+ where v is null
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: select assert_true(sum(a*a) = 2*2+3*3) from t
+ where v is not null
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select assert_true(sum(a*a) = 2*2+3*3) from t
+ where v is not null
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: select assert_true(sum(a*a) = 1) from t
+ where b is true
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select assert_true(sum(a*a) = 1) from t
+ where b is true
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: select assert_true(sum(a*a) = 2*2 + 3*3) from t
+ where b is not true
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select assert_true(sum(a*a) = 2*2 + 3*3) from t
+ where b is not true
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: select assert_true(sum(a*a) = 4) from t
+ where b is false
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select assert_true(sum(a*a) = 4) from t
+ where b is false
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: select assert_true(sum(a*a) = 1*1 + 3*3) from t
+ where b is not false
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select assert_true(sum(a*a) = 1*1 + 3*3) from t
+ where b is not false
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: select assert_true(sum(a*a) = 2*2) from t
+ where (v>0 and v<2) is true
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select assert_true(sum(a*a) = 2*2) from t
+ where (v>0 and v<2) is true
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: select assert_true(sum(a*a) = 2*2) from t
+ where (v<2) is true
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select assert_true(sum(a*a) = 2*2) from t
+ where (v<2) is true
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: select NULL is true,
+ NULL is not true,
+ NULL is false,
+ NULL is not false
+from t
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t
+#### A masked pattern was here ####
+POSTHOOK: query: select NULL is true,
+ NULL is not true,
+ NULL is false,
+ NULL is not false
+from t
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t
+#### A masked pattern was here ####
+false true false true
+false true false true
+false true false true