okumin commented on code in PR #4612:
URL: https://github.com/apache/hive/pull/4612#discussion_r1299358143


##########
ql/src/test/queries/clientpositive/udf_array_remove.q:
##########
@@ -0,0 +1,40 @@
+--! qt:dataset:src
+
+-- SORT_QUERY_RESULTS
+
+set hive.fetch.task.conversion=more;
+
+DESCRIBE FUNCTION array_remove;
+DESCRIBE FUNCTION EXTENDED array_remove;
+
+-- evaluates function for array of primitives

Review Comment:
   It could be nice if we have a test case where the second argument is NULL.



##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFArrayRemove.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.UDFArgumentTypeException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * GenericUDFArrayRemove.
+ */
+@Description(name = "array_remove", value = "_FUNC_(array, element) - Removes 
all occurrences of element from array.",
+    extended = "Example:\n" + "  > SELECT _FUNC_(array(1, 2, 3,4,2), 2) FROM 
src;\n"
+    + "  [1,3,4]")
+public class GenericUDFArrayRemove extends AbstractGenericUDFArrayBase {
+  private static final String FUNC_NAME = "ARRAY_REMOVE";
+  private static final int VALUE_IDX = 1;
+
+  public GenericUDFArrayRemove() {
+    super(FUNC_NAME, 2, 2, ObjectInspector.Category.LIST);
+  }
+
+  @Override
+  public ObjectInspector initialize(ObjectInspector[] arguments) throws 
UDFArgumentException {
+    ObjectInspector defaultOI = super.initialize(arguments);
+    ObjectInspector arrayElementOI = arrayOI.getListElementObjectInspector();
+
+    ObjectInspector valueOI = arguments[VALUE_IDX];
+
+    // Check if list element and value are of same type
+    if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
+      throw new UDFArgumentTypeException(VALUE_IDX,
+          String.format("%s expected at function %s, but %s is found", 
arrayElementOI.getTypeName(), FUNC_NAME,

Review Comment:
   It could be kinder if we add more information. `int expected at function 
array_remove, but double is found` might be confusing because it might not be 
obvious which `array_remove(array<int>, double)` or 
`array_remove(array<double>, int)` is invoked unless checking this file.



##########
ql/src/test/results/clientpositive/llap/udf_array_remove.q.out:
##########
@@ -0,0 +1,123 @@
+PREHOOK: query: DESCRIBE FUNCTION array_remove

Review Comment:
   I double checked the behavior using Spark 3.4.1



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to