This is an automated email from the ASF dual-hosted git repository.

gsaihemanth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new f4e4114b337 HIVE-27663 - implement array_position UDF in Hive (#4653) 
(Taraka Rama Rao Lethavadla, Reviewed by Okumin, Sai Hemanth Gantasala)
f4e4114b337 is described below

commit f4e4114b337597913ecf836248f274cb7141d7e5
Author: tarak271 <[email protected]>
AuthorDate: Thu Mar 7 04:47:31 2024 +0530

    HIVE-27663 - implement array_position UDF in Hive (#4653) (Taraka Rama Rao 
Lethavadla, Reviewed by Okumin, Sai Hemanth Gantasala)
---
 .../hadoop/hive/ql/exec/FunctionRegistry.java      |   1 +
 .../udf/generic/AbstractGenericUDFArrayBase.java   |  14 ++
 .../ql/udf/generic/GenericUDFArrayPosition.java    |  68 ++++++++
 .../udf/generic/TestGenericUDFArrayPosition.java   | 158 +++++++++++++++++++
 .../queries/clientpositive/udf_array_position.q    |  50 ++++++
 .../clientpositive/llap/show_functions.q.out       |   2 +
 .../clientpositive/llap/udf_array_position.q.out   | 172 +++++++++++++++++++++
 7 files changed, 465 insertions(+)

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 6c1c5fb0113..e97b56b4dca 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
@@ -615,6 +615,7 @@ public final class FunctionRegistry {
     system.registerGenericUDF("array_intersect", 
GenericUDFArrayIntersect.class);
     system.registerGenericUDF("array_union", GenericUDFArrayUnion.class);
     system.registerGenericUDF("array_remove", GenericUDFArrayRemove.class);
+    system.registerGenericUDF("array_position", GenericUDFArrayPosition.class);
     system.registerGenericUDF("deserialize", GenericUDFDeserialize.class);
     system.registerGenericUDF("sentences", GenericUDFSentences.class);
     system.registerGenericUDF("map_keys", GenericUDFMapKeys.class);
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.java
index 22ad5b8aa6e..a21cc4e5f96 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/AbstractGenericUDFArrayBase.java
@@ -26,6 +26,7 @@ import 
org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
 import 
org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
 
 /**
  * Abstract GenericUDF for array functions
@@ -44,6 +45,8 @@ public abstract class AbstractGenericUDFArrayBase extends 
GenericUDF {
     transient ListObjectInspector arrayOI;
     transient ObjectInspector[] argumentOIs;
 
+    transient ObjectInspector arrayElementOI;
+
     transient Converter converter;
 
     protected AbstractGenericUDFArrayBase(String functionName, int 
minArgCount, int maxArgCount, ObjectInspector.Category outputCategory) {
@@ -67,6 +70,7 @@ public abstract class AbstractGenericUDFArrayBase extends 
GenericUDF {
         //return ObjectInspectors based on expected output type
         arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
         argumentOIs = arguments;
+        arrayElementOI = arrayOI.getListElementObjectInspector();
         if (outputCategory == ObjectInspector.Category.LIST) {
             return initListOI(arguments);
         } else {
@@ -123,4 +127,14 @@ public abstract class AbstractGenericUDFArrayBase extends 
GenericUDF {
         return 
ObjectInspectorFactory.getStandardListObjectInspector(initOI(arguments));
     }
 
+    void checkValueAndListElementTypes(ObjectInspector arrayElementOI, String 
functionName, ObjectInspector valueOI,
+        int elementIndex) throws UDFArgumentTypeException {
+        // Check if list element and value are of same type
+        if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
+            throw new UDFArgumentTypeException(elementIndex,
+                String.format("%s type element is expected at function 
%s(array<%s>,%s), but %s is found",
+                    arrayElementOI.getTypeName(), functionName, 
arrayElementOI.getTypeName(),
+                    arrayElementOI.getTypeName(), valueOI.getTypeName()));
+        }
+    }
 }
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFArrayPosition.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFArrayPosition.java
new file mode 100644
index 00000000000..fadad42d9cc
--- /dev/null
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFArrayPosition.java
@@ -0,0 +1,68 @@
+/*
+ * 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.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.IntWritable;
+
+/**
+ * GenericUDFArrayPosition.
+ */
+@Description(name = "array_position", value = "_FUNC_(array, element) - 
Returns the position of the first occurrence of "
+    + "element in array. Array indexing starts at 1. If the element value is 
NULL, a NULL is returned.", extended =
+    "Example:\n" + "  > SELECT _FUNC_(array(1, 2, 3,4,2), 2) FROM src;\n" + "  
2")
+public class GenericUDFArrayPosition extends AbstractGenericUDFArrayBase {
+  static final String FUNC_NAME = "ARRAY_POSITION";
+  private static final int ELEMENT_IDX = 1;
+
+  private transient ObjectInspector valueOI;
+
+  public GenericUDFArrayPosition() {
+    super(FUNC_NAME, 2, 2, ObjectInspector.Category.PRIMITIVE);
+  }
+
+  @Override
+  public ObjectInspector initialize(ObjectInspector[] arguments) throws 
UDFArgumentException {
+    super.initialize(arguments);
+    valueOI = arguments[ELEMENT_IDX];
+    checkValueAndListElementTypes(arrayElementOI, FUNC_NAME, 
valueOI,ELEMENT_IDX);
+    return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
+  }
+
+  @Override
+  public Object evaluate(DeferredObject[] arguments) throws HiveException {
+    Object array = arguments[ARRAY_IDX].get();
+    Object value = arguments[ELEMENT_IDX].get();
+    int arrayLength = arrayOI.getListLength(array);
+    if (arrayLength < 0 || value == null) {
+      return null;
+    }
+
+    for (int index = 0; index < arrayLength; ++index) {
+      if (ObjectInspectorUtils.compare(value, valueOI, 
arrayOI.getListElement(array, index), arrayElementOI) == 0) {
+          return new IntWritable(index + 1);
+      }
+    }
+    return new IntWritable(0);
+  }
+}
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFArrayPosition.java
 
b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFArrayPosition.java
new file mode 100644
index 00000000000..615f1f4b3c6
--- /dev/null
+++ 
b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFArrayPosition.java
@@ -0,0 +1,158 @@
+/*
+ * 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.common.type.Date;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.io.DateWritableV2;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.FloatWritable;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.Text;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Arrays.asList;
+
+public class TestGenericUDFArrayPosition {
+  private final GenericUDFArrayPosition udf = new GenericUDFArrayPosition();
+
+  @Test public void testPrimitive() throws HiveException {
+    ObjectInspector[] inputOIs = { 
ObjectInspectorFactory.getStandardListObjectInspector(
+        PrimitiveObjectInspectorFactory.writableIntObjectInspector),
+        PrimitiveObjectInspectorFactory.writableIntObjectInspector };
+    udf.initialize(inputOIs);
+
+    Object i1 = new IntWritable(3);
+    Object i2 = new IntWritable(1);
+    Object i3 = new IntWritable(2);
+    Object i4 = new IntWritable(1);
+    Object i5 = new IntWritable(5);
+
+    runAndVerify(asList(i1, i2, i3, i4), i2, 2);
+    runAndVerify(asList(i1, i2, i3, i4), i5, 0);
+
+    ObjectInspector[] inputOIfs = { 
ObjectInspectorFactory.getStandardListObjectInspector(
+        PrimitiveObjectInspectorFactory.writableFloatObjectInspector),
+        PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
+    udf.initialize(inputOIfs);
+
+    i1 = new FloatWritable(3.3f);
+    i2 = new FloatWritable(1.1f);
+    i3 = new FloatWritable(3.3f);
+    i4 = new FloatWritable(2.20f);
+    runAndVerify(asList(i1, i2, i3, i4), i1, 1);
+    runAndVerify(asList(i1, i2, i3, i4),null,null); //Test null element
+  }
+
+  @Test public void testList() throws HiveException {
+    ObjectInspector[] inputOIs = { 
ObjectInspectorFactory.getStandardListObjectInspector(
+        ObjectInspectorFactory.getStandardListObjectInspector(
+            PrimitiveObjectInspectorFactory.writableStringObjectInspector)),
+        ObjectInspectorFactory.getStandardListObjectInspector(
+            PrimitiveObjectInspectorFactory.writableStringObjectInspector) };
+    udf.initialize(inputOIs);
+
+    Object i1 = asList(new Text("aa1"), new Text("dd"), new Text("cc"), new 
Text("bb"));
+    Object i2 = asList(new Text("aa2"), new Text("cc"), new Text("ba"), new 
Text("dd"));
+    Object i3 = asList(new Text("aa3"), new Text("cc"), new Text("dd"), new 
Text("ee"), new Text("bb"));
+    Object i4 = asList(new Text("aa4"), new Text("cc"), new Text("ddd"), new 
Text("bb"));
+    runAndVerify(asList(i1, i2, i2, i3, i4, i4), i2, 2);
+  }
+
+  @Test public void testStruct() throws HiveException {
+    ObjectInspector[] inputOIs = { 
ObjectInspectorFactory.getStandardListObjectInspector(
+        ObjectInspectorFactory.getStandardStructObjectInspector(asList("f1", 
"f2", "f3", "f4"),
+            
asList(PrimitiveObjectInspectorFactory.writableStringObjectInspector,
+                PrimitiveObjectInspectorFactory.writableDoubleObjectInspector,
+                PrimitiveObjectInspectorFactory.writableDateObjectInspector,
+                ObjectInspectorFactory.getStandardListObjectInspector(
+                    
PrimitiveObjectInspectorFactory.writableIntObjectInspector)))),
+        ObjectInspectorFactory.getStandardStructObjectInspector(asList("f1", 
"f2", "f3", "f4"),
+            
asList(PrimitiveObjectInspectorFactory.writableStringObjectInspector,
+                PrimitiveObjectInspectorFactory.writableDoubleObjectInspector,
+                PrimitiveObjectInspectorFactory.writableDateObjectInspector,
+                ObjectInspectorFactory.getStandardListObjectInspector(
+                    
PrimitiveObjectInspectorFactory.writableIntObjectInspector))) };
+    udf.initialize(inputOIs);
+
+    Object i1 = asList(new Text("a"), new DoubleWritable(3.1415), new 
DateWritableV2(Date.of(2015, 5, 26)),
+        asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new 
IntWritable(4)));
+
+    Object i2 = asList(new Text("b"), new DoubleWritable(3.14), new 
DateWritableV2(Date.of(2015, 5, 26)),
+        asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new 
IntWritable(4)));
+
+    Object i3 = asList(new Text("a"), new DoubleWritable(3.1415), new 
DateWritableV2(Date.of(2015, 5, 25)),
+        asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new 
IntWritable(5)));
+
+    Object i4 = asList(new Text("a"), new DoubleWritable(3.1415), new 
DateWritableV2(Date.of(2015, 5, 25)),
+        asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new 
IntWritable(4)));
+
+    runAndVerify(asList(i1, i3, i2, i3, i4, i2), i2, 3);
+  }
+
+  @Test public void testMap() throws HiveException {
+    ObjectInspector[] inputOIs = { 
ObjectInspectorFactory.getStandardListObjectInspector(
+        ObjectInspectorFactory.getStandardMapObjectInspector(
+            PrimitiveObjectInspectorFactory.writableStringObjectInspector,
+            PrimitiveObjectInspectorFactory.writableIntObjectInspector)),
+        ObjectInspectorFactory.getStandardMapObjectInspector(
+            PrimitiveObjectInspectorFactory.writableStringObjectInspector,
+            PrimitiveObjectInspectorFactory.writableIntObjectInspector) };
+    udf.initialize(inputOIs);
+
+    Map<Text, IntWritable> m1 = new HashMap<>();
+    m1.put(new Text("a"), new IntWritable(4));
+    m1.put(new Text("b"), new IntWritable(3));
+    m1.put(new Text("c"), new IntWritable(1));
+    m1.put(new Text("d"), new IntWritable(2));
+
+    Map<Text, IntWritable> m2 = new HashMap<>();
+    m2.put(new Text("d"), new IntWritable(4));
+    m2.put(new Text("b"), new IntWritable(3));
+    m2.put(new Text("a"), new IntWritable(1));
+    m2.put(new Text("c"), new IntWritable(2));
+
+    Map<Text, IntWritable> m3 = new HashMap<>();
+    m3.put(new Text("d"), new IntWritable(4));
+    m3.put(new Text("b"), new IntWritable(3));
+    m3.put(new Text("a"), new IntWritable(1));
+
+    runAndVerify(asList(m1, m3, m2, m3, m1), m1, 1);
+  }
+
+  private void runAndVerify(List<Object> actual, Object element, Object 
expected)
+      throws HiveException {
+    GenericUDF.DeferredJavaObject[] args = { new 
GenericUDF.DeferredJavaObject(actual), new 
GenericUDF.DeferredJavaObject(element) };
+    Object result = udf.evaluate(args);
+    if(expected == null){
+      Assert.assertNull(result);
+    }
+    else {
+      Assert.assertEquals("index value", expected, 
((IntWritable)result).get());
+    }
+  }
+}
diff --git a/ql/src/test/queries/clientpositive/udf_array_position.q 
b/ql/src/test/queries/clientpositive/udf_array_position.q
new file mode 100644
index 00000000000..aa82679cb67
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/udf_array_position.q
@@ -0,0 +1,50 @@
+--! qt:dataset:src
+
+-- SORT_QUERY_RESULTS
+
+set hive.fetch.task.conversion=more;
+
+DESCRIBE FUNCTION array_position;
+DESCRIBE FUNCTION EXTENDED array_position;
+
+-- evaluates function for array of primitives
+SELECT array_position(array(1, 2, 3, null,3,4), 3);
+
+SELECT array_position(array(1.12, 2.23, 3.34, null,1.11,1.12,2.9),1.12);
+
+SELECT array(1,2,3),array_position(array(1, 2, 3),3);
+
+SELECT array(1,2,3),array_position(array(1, 2, 3),5);
+
+SELECT array_position(array(1, 2, 3), CAST(null AS int));
+
+SELECT array_position(array(1.1234567890, 2.234567890, 3.34567890, null, 
3.3456789, 2.234567,1.1234567890),1.1234567890);
+
+SELECT array_position(array(11234567890, 2234567890, 334567890, null, 
11234567890, 2234567890, 334567890, null),11234567890);
+
+SELECT 
array_position(array(array("a","b","c","d"),array("a","b","c","d"),array("a","b","c","d","e"),null,array("e","a","b","c","d")),array("a","b","c","d"));
+
+SELECT array_position(array("aa","bb","cc"),"cc");
+
+create table test as select array('a', 'b', 'c', 'b') as a union all select 
array('a', 'c', 'd') as a;
+
+select * from test;
+
+select a, array_position(a, 'b') from test;
+
+# handle null array cases
+
+dfs ${system:test.dfs.mkdir} ${system:test.tmp.dir}/test_null_array;
+
+dfs -copyFromLocal ../../data/files/test_null_array.csv 
${system:test.tmp.dir}/test_null_array/;
+
+create external table test_null_array (id string, value Array<String>) ROW 
FORMAT DELIMITED
+ FIELDS TERMINATED BY ':' collection items terminated by ',' location 
'${system:test.tmp.dir}/test_null_array';
+
+select id,value from test_null_array;
+
+select id,array_position(value,id) from test_null_array;
+
+select value, array_position(value,id) from test_null_array;
+
+dfs -rm -r ${system:test.tmp.dir}/test_null_array;
\ No newline at end of file
diff --git a/ql/src/test/results/clientpositive/llap/show_functions.q.out 
b/ql/src/test/results/clientpositive/llap/show_functions.q.out
index 9642bfbd8b0..24105d06010 100644
--- a/ql/src/test/results/clientpositive/llap/show_functions.q.out
+++ b/ql/src/test/results/clientpositive/llap/show_functions.q.out
@@ -53,6 +53,7 @@ array_intersect
 array_join
 array_max
 array_min
+array_position
 array_remove
 array_slice
 array_union
@@ -681,6 +682,7 @@ array_intersect
 array_join
 array_max
 array_min
+array_position
 array_remove
 array_slice
 array_union
diff --git a/ql/src/test/results/clientpositive/llap/udf_array_position.q.out 
b/ql/src/test/results/clientpositive/llap/udf_array_position.q.out
new file mode 100644
index 00000000000..ed185418b70
--- /dev/null
+++ b/ql/src/test/results/clientpositive/llap/udf_array_position.q.out
@@ -0,0 +1,172 @@
+PREHOOK: query: DESCRIBE FUNCTION array_position
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION array_position
+POSTHOOK: type: DESCFUNCTION
+array_position(array, element) - Returns the position of the first occurrence 
of element in array. Array indexing starts at 1. If the element value is NULL, 
a NULL is returned.
+PREHOOK: query: DESCRIBE FUNCTION EXTENDED array_position
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION EXTENDED array_position
+POSTHOOK: type: DESCFUNCTION
+array_position(array, element) - Returns the position of the first occurrence 
of element in array. Array indexing starts at 1. If the element value is NULL, 
a NULL is returned.
+Example:
+  > SELECT array_position(array(1, 2, 3,4,2), 2) FROM src;
+  2
+Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFArrayPosition
+Function type:BUILTIN
+PREHOOK: query: SELECT array_position(array(1, 2, 3, null,3,4), 3)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT array_position(array(1, 2, 3, null,3,4), 3)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+3
+PREHOOK: query: SELECT array_position(array(1.12, 2.23, 3.34, 
null,1.11,1.12,2.9),1.12)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT array_position(array(1.12, 2.23, 3.34, 
null,1.11,1.12,2.9),1.12)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+1
+PREHOOK: query: SELECT array(1,2,3),array_position(array(1, 2, 3),3)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT array(1,2,3),array_position(array(1, 2, 3),3)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+[1,2,3]        3
+PREHOOK: query: SELECT array(1,2,3),array_position(array(1, 2, 3),5)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT array(1,2,3),array_position(array(1, 2, 3),5)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+[1,2,3]        0
+PREHOOK: query: SELECT array_position(array(1, 2, 3), CAST(null AS int))
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT array_position(array(1, 2, 3), CAST(null AS int))
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+NULL
+PREHOOK: query: SELECT array_position(array(1.1234567890, 2.234567890, 
3.34567890, null, 3.3456789, 2.234567,1.1234567890),1.1234567890)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT array_position(array(1.1234567890, 2.234567890, 
3.34567890, null, 3.3456789, 2.234567,1.1234567890),1.1234567890)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+1
+PREHOOK: query: SELECT array_position(array(11234567890, 2234567890, 
334567890, null, 11234567890, 2234567890, 334567890, null),11234567890)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT array_position(array(11234567890, 2234567890, 
334567890, null, 11234567890, 2234567890, 334567890, null),11234567890)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+1
+PREHOOK: query: SELECT 
array_position(array(array("a","b","c","d"),array("a","b","c","d"),array("a","b","c","d","e"),null,array("e","a","b","c","d")),array("a","b","c","d"))
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT 
array_position(array(array("a","b","c","d"),array("a","b","c","d"),array("a","b","c","d","e"),null,array("e","a","b","c","d")),array("a","b","c","d"))
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+1
+PREHOOK: query: SELECT array_position(array("aa","bb","cc"),"cc")
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT array_position(array("aa","bb","cc"),"cc")
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+3
+PREHOOK: query: create table test as select array('a', 'b', 'c', 'b') as a 
union all select array('a', 'c', 'd') as a
+PREHOOK: type: CREATETABLE_AS_SELECT
+PREHOOK: Input: _dummy_database@_dummy_table
+PREHOOK: Output: database:default
+PREHOOK: Output: default@test
+POSTHOOK: query: create table test as select array('a', 'b', 'c', 'b') as a 
union all select array('a', 'c', 'd') as a
+POSTHOOK: type: CREATETABLE_AS_SELECT
+POSTHOOK: Input: _dummy_database@_dummy_table
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@test
+POSTHOOK: Lineage: test.a SCRIPT []
+PREHOOK: query: select * from test
+PREHOOK: type: QUERY
+PREHOOK: Input: default@test
+#### A masked pattern was here ####
+POSTHOOK: query: select * from test
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@test
+#### A masked pattern was here ####
+["a","b","c","b"]
+["a","c","d"]
+PREHOOK: query: select a, array_position(a, 'b') from test
+PREHOOK: type: QUERY
+PREHOOK: Input: default@test
+#### A masked pattern was here ####
+POSTHOOK: query: select a, array_position(a, 'b') from test
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@test
+#### A masked pattern was here ####
+["a","b","c","b"]      2
+["a","c","d"]  0
+PREHOOK: query: create external table test_null_array (id string, value 
Array<String>) ROW FORMAT DELIMITED
+#### A masked pattern was here ####
+PREHOOK: type: CREATETABLE
+#### A masked pattern was here ####
+PREHOOK: Output: database:default
+PREHOOK: Output: default@test_null_array
+POSTHOOK: query: create external table test_null_array (id string, value 
Array<String>) ROW FORMAT DELIMITED
+#### A masked pattern was here ####
+POSTHOOK: type: CREATETABLE
+#### A masked pattern was here ####
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@test_null_array
+PREHOOK: query: select id,value from test_null_array
+PREHOOK: type: QUERY
+PREHOOK: Input: default@test_null_array
+#### A masked pattern was here ####
+POSTHOOK: query: select id,value from test_null_array
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@test_null_array
+#### A masked pattern was here ####
+1      []
+2      ["NULL"]
+3      ["null","null"]
+PREHOOK: query: select id,array_position(value,id) from test_null_array
+PREHOOK: type: QUERY
+PREHOOK: Input: default@test_null_array
+#### A masked pattern was here ####
+POSTHOOK: query: select id,array_position(value,id) from test_null_array
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@test_null_array
+#### A masked pattern was here ####
+1      0
+2      0
+3      0
+PREHOOK: query: select value, array_position(value,id) from test_null_array
+PREHOOK: type: QUERY
+PREHOOK: Input: default@test_null_array
+#### A masked pattern was here ####
+POSTHOOK: query: select value, array_position(value,id) from test_null_array
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@test_null_array
+#### A masked pattern was here ####
+["NULL"]       0
+["null","null"]        0
+[]     0

Reply via email to