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

sankarh pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/branch-3 by this push:
     new 720a0f271ee HIVE-27255: Backport of HIVE-18786: NPE in Hive windowing 
functions (#4472)
720a0f271ee is described below

commit 720a0f271eee924d2d5c3fbd325bf38ce98fe948
Author: Aman Raj <[email protected]>
AuthorDate: Tue Jul 11 08:46:16 2023 +0530

    HIVE-27255: Backport of HIVE-18786: NPE in Hive windowing functions (#4472)
    
    * HIVE-18786: NPE in Hive windowing functions (Dongwook Kwon via Ashutosh 
Chauhan)
    
    Signed-off-by: Sankar Hariappan <[email protected]>
    Closes (#4472)
---
 .../hive/ql/udf/generic/GenericUDAFEvaluator.java  |  1 +
 .../ql/udf/generic/TestGenericUDAFEvaluator.java   | 79 ++++++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFEvaluator.java 
b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFEvaluator.java
index 09e25833632..960d8fdb894 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFEvaluator.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFEvaluator.java
@@ -149,6 +149,7 @@ public abstract class GenericUDAFEvaluator implements 
Closeable {
     // This function should be overriden in every sub class
     // And the sub class should call super.init(m, parameters) to get mode set.
     mode = m;
+    partitionEvaluator = null;
     return null;
   }
 
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDAFEvaluator.java
 
b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDAFEvaluator.java
new file mode 100644
index 00000000000..878733155ed
--- /dev/null
+++ 
b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDAFEvaluator.java
@@ -0,0 +1,79 @@
+/**
+ * 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.PTFPartition;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef;
+import org.apache.hadoop.hive.ql.plan.ptf.WindowFrameDef;
+import org.apache.hadoop.hive.ql.udf.ptf.BasePartitionEvaluator;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.util.Collections;
+import java.util.List;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestGenericUDAFEvaluator {
+
+  @Mock(answer = Answers.CALLS_REAL_METHODS)
+  private GenericUDAFEvaluator udafEvaluator;
+
+  @Mock
+  private WindowFrameDef winFrame;
+
+  @Mock
+  private PTFPartition partition1;
+
+  @Mock
+  private ObjectInspector outputOI;
+
+  private List<PTFExpressionDef> parameters = Collections.emptyList();
+
+  @Test
+  public void testGetPartitionWindowingEvaluatorWithoutInitCall() {
+    BasePartitionEvaluator partition1Evaluator1 = 
udafEvaluator.getPartitionWindowingEvaluator(
+        winFrame, partition1, parameters, outputOI, false);
+
+    BasePartitionEvaluator partition1Evaluator2 = 
udafEvaluator.getPartitionWindowingEvaluator(
+        winFrame, partition1, parameters, outputOI, false);
+
+    Assert.assertEquals(partition1Evaluator1, partition1Evaluator2);
+  }
+
+  @Test
+  public void testGetPartitionWindowingEvaluatorWithInitCall() throws 
HiveException {
+    BasePartitionEvaluator partition1Evaluator1 = 
udafEvaluator.getPartitionWindowingEvaluator(
+        winFrame, partition1, parameters, outputOI, false);
+
+    udafEvaluator.init(GenericUDAFEvaluator.Mode.COMPLETE, null);
+
+    BasePartitionEvaluator newPartitionEvaluator = 
udafEvaluator.getPartitionWindowingEvaluator(
+        winFrame, partition1, parameters, outputOI, false);
+
+    Assert.assertNotEquals(partition1Evaluator1, newPartitionEvaluator);
+  }
+
+}

Reply via email to