soumyakanti3578 commented on code in PR #6486:
URL: https://github.com/apache/hive/pull/6486#discussion_r3277782818
##########
storage-api/src/test/org/apache/hadoop/hive/ql/exec/vector/TestBytesColumnVector.java:
##########
@@ -220,4 +222,21 @@ private static byte[] writeToBytesColumnVector(int rowIdx,
BytesColumnVector col
col.setValPreallocated(rowIdx, writeSize);
return bytes;
}
+
+ @Test
+ public void testClearValue() {
+ BytesColumnVector cv = new BytesColumnVector(4);
+ byte[] data = "hello".getBytes(StandardCharsets.UTF_8);
+ cv.vector[0] = data;
+ cv.start[0] = 1;
+ cv.length[0] = 3;
+
+ cv.clearValue(0);
+
+ assertTrue(cv.isNull[0]);
+ assertFalse(cv.noNulls);
+ assertNull(cv.vector[0]);
+ assertEquals(0, cv.start[0]);
+ assertEquals(0, cv.length[0]);
+ }
Review Comment:
Neighbor slot was not tested here, whereas it has been tested for other
column vectors. Please add it wherever it makes sense.
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/mapjoin/TestVectorMapJoinOuterGenerateResultOperator.java:
##########
@@ -0,0 +1,264 @@
+/*
+ * 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.exec.vector.mapjoin;
+
+import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
+import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.VoidColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * HIVE-29598: verifies {@link VectorMapJoinOuterGenerateResultOperator} clears
+ * every small-table slot for unmatched rows, so stale values cannot carry over
+ * past the null marking.
+ */
+class TestVectorMapJoinOuterGenerateResultOperator {
+
+ /** Concrete subclass that exposes the generateOuterNulls* methods to tests.
*/
+ private static final class TestableOuterOp extends
VectorMapJoinOuterGenerateResultOperator {
+ @Override
+ protected String getLoggingPrefix() {
+ return "test";
+ }
+
+ @Override
+ public void processBatch(VectorizedRowBatch batch) {
+ }
+ }
+
+ /**
+ * Records {@code clearSlotValue} invocations to verify the operator
dispatches
+ * through {@code clearValue}, not just produces the slot-clearing side
effect.
+ */
+ private static class TrackingLongColumnVector extends LongColumnVector {
+ final List<Integer> clearedIndices = new ArrayList<>();
+
+ TrackingLongColumnVector(int size) {
+ super(size);
+ }
+
+ @Override
+ protected void clearSlotValue(int elementNum) {
+ super.clearSlotValue(elementNum);
+ clearedIndices.add(elementNum);
+ }
+ }
+
+ @Test
+ void
generateOuterNullsCallsClearValueOnEachMappedColumnForEachUnmatchedRow() throws
HiveException, IOException {
+ TestableOuterOp op = new TestableOuterOp();
+ op.outerSmallTableKeyColumnMap = new int[] {0};
+ op.smallTableValueColumnMap = new int[] {1, 2};
+
+ VectorizedRowBatch batch = new VectorizedRowBatch(3, 4);
+ TrackingLongColumnVector keyCol = new TrackingLongColumnVector(4);
+ TrackingLongColumnVector valCol1 = new TrackingLongColumnVector(4);
+ TrackingLongColumnVector valCol2 = new TrackingLongColumnVector(4);
+ keyCol.vector[1] = 99L;
+ valCol1.vector[1] = 88L;
+ valCol2.vector[3] = 77L;
+ batch.cols[0] = keyCol;
+ batch.cols[1] = valCol1;
+ batch.cols[2] = valCol2;
+
+ int[] noMatchs = new int[] {1, 3};
+ op.generateOuterNulls(batch, noMatchs, noMatchs.length);
+
+ assertEquals(Arrays.asList(1, 3), keyCol.clearedIndices);
+ assertEquals(Arrays.asList(1, 3), valCol1.clearedIndices);
+ assertEquals(Arrays.asList(1, 3), valCol2.clearedIndices);
+
+ assertFalse(keyCol.noNulls);
+ assertTrue(keyCol.isNull[1]);
+ assertTrue(keyCol.isNull[3]);
+ assertFalse(keyCol.isNull[0]);
+ assertFalse(keyCol.isNull[2]);
+
+ assertEquals(0L, keyCol.vector[1]);
+ assertEquals(0L, valCol1.vector[1]);
+ assertEquals(0L, valCol2.vector[3]);
+ }
+
+ @Test
+ void
generateOuterNullsRepeatedAllCallsClearValueAtIndexZeroForEachMappedColumn()
throws HiveException {
+ TestableOuterOp op = new TestableOuterOp();
+ op.outerSmallTableKeyColumnMap = new int[] {0};
+ op.smallTableValueColumnMap = new int[] {1};
+
+ VectorizedRowBatch batch = new VectorizedRowBatch(2, 4);
+ TrackingLongColumnVector keyCol = new TrackingLongColumnVector(4);
+ TrackingLongColumnVector valCol = new TrackingLongColumnVector(4);
+ keyCol.vector[0] = 42L;
+ valCol.vector[0] = 84L;
+ batch.cols[0] = keyCol;
+ batch.cols[1] = valCol;
+
+ op.generateOuterNullsRepeatedAll(batch);
+
+ assertEquals(Arrays.asList(0), keyCol.clearedIndices);
+ assertEquals(Arrays.asList(0), valCol.clearedIndices);
+
+ // isRepeating is set by the operator, not by clearValue.
+ assertFalse(keyCol.noNulls);
+ assertTrue(keyCol.isNull[0]);
+ assertTrue(keyCol.isRepeating);
+ assertFalse(valCol.noNulls);
+ assertTrue(valCol.isNull[0]);
+ assertTrue(valCol.isRepeating);
+
+ assertEquals(0L, keyCol.vector[0]);
+ assertEquals(0L, valCol.vector[0]);
+ }
+
+ @Test
+ void generateOuterNullsSetsBookkeepingOnTypeWithNoClearSlotValueOverride()
throws HiveException, IOException {
+ // VoidColumnVector inherits the base no-op clearSlotValue — verifies the
+ // operator still drives the null-marking through clearValue() on a type
+ // without a per-slot value to zero.
+ TestableOuterOp op = new TestableOuterOp();
+ op.outerSmallTableKeyColumnMap = new int[] {};
+ op.smallTableValueColumnMap = new int[] {0};
+
+ VectorizedRowBatch batch = new VectorizedRowBatch(1, 4);
+ VoidColumnVector voidCol = new VoidColumnVector(4);
+ batch.cols[0] = voidCol;
+
+ int[] noMatchs = new int[] {1, 3};
+ op.generateOuterNulls(batch, noMatchs, noMatchs.length);
+
+ assertFalse(voidCol.noNulls);
+ assertTrue(voidCol.isNull[1]);
+ assertTrue(voidCol.isNull[3]);
+ assertFalse(voidCol.isNull[0]);
+ assertFalse(voidCol.isNull[2]);
+ }
+
+ /**
+ * For each {@link ColumnVector} subclass whose {@code clearSlotValue} is
+ * overridden, verifies the operator's call through {@code clearValue}
reaches
+ * the override and clears the slot to the type's cleared state.
+ */
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("modifiedColumnVectorTypes")
+ void generateOuterNullsClearsSlotForEachModifiedType(
+ String typeName,
+ ColumnVector cv,
+ Runnable preLoad,
+ Runnable assertSlotCleared) throws HiveException, IOException {
+
+ TestableOuterOp op = new TestableOuterOp();
+ op.outerSmallTableKeyColumnMap = new int[] {};
+ op.smallTableValueColumnMap = new int[] {0};
+
+ VectorizedRowBatch batch = new VectorizedRowBatch(1, 4);
+ preLoad.run();
+ batch.cols[0] = cv;
+
+ int[] noMatchs = new int[] {2};
+ op.generateOuterNulls(batch, noMatchs, noMatchs.length);
+
+ assertTrue(cv.isNull[2]);
+ assertFalse(cv.noNulls);
+ assertSlotCleared.run();
+ }
+
+ static Stream<Arguments> modifiedColumnVectorTypes() {
+ final LongColumnVector longCv = new LongColumnVector(4);
+ final DoubleColumnVector doubleCv = new DoubleColumnVector(4);
+ final BytesColumnVector bytesCv = new BytesColumnVector(4);
+ final DecimalColumnVector decCv = new DecimalColumnVector(4, 18, 4);
+ final TimestampColumnVector tsCv = new TimestampColumnVector(4);
+ final IntervalDayTimeColumnVector ivCv = new
IntervalDayTimeColumnVector(4);
+
Review Comment:
I saw that there's also the `Decimal64ColumnVector` class. Maybe we need to
include it here and other places where it makes sense?
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/mapjoin/TestVectorMapJoinOuterGenerateResultOperator.java:
##########
@@ -0,0 +1,264 @@
+/*
+ * 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.exec.vector.mapjoin;
+
+import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
+import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.VoidColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * HIVE-29598: verifies {@link VectorMapJoinOuterGenerateResultOperator} clears
+ * every small-table slot for unmatched rows, so stale values cannot carry over
+ * past the null marking.
+ */
+class TestVectorMapJoinOuterGenerateResultOperator {
+
+ /** Concrete subclass that exposes the generateOuterNulls* methods to tests.
*/
+ private static final class TestableOuterOp extends
VectorMapJoinOuterGenerateResultOperator {
+ @Override
+ protected String getLoggingPrefix() {
+ return "test";
+ }
+
+ @Override
+ public void processBatch(VectorizedRowBatch batch) {
+ }
+ }
+
+ /**
+ * Records {@code clearSlotValue} invocations to verify the operator
dispatches
+ * through {@code clearValue}, not just produces the slot-clearing side
effect.
+ */
+ private static class TrackingLongColumnVector extends LongColumnVector {
+ final List<Integer> clearedIndices = new ArrayList<>();
+
+ TrackingLongColumnVector(int size) {
+ super(size);
+ }
+
+ @Override
+ protected void clearSlotValue(int elementNum) {
+ super.clearSlotValue(elementNum);
+ clearedIndices.add(elementNum);
+ }
+ }
+
+ @Test
+ void
generateOuterNullsCallsClearValueOnEachMappedColumnForEachUnmatchedRow() throws
HiveException, IOException {
+ TestableOuterOp op = new TestableOuterOp();
+ op.outerSmallTableKeyColumnMap = new int[] {0};
+ op.smallTableValueColumnMap = new int[] {1, 2};
+
+ VectorizedRowBatch batch = new VectorizedRowBatch(3, 4);
+ TrackingLongColumnVector keyCol = new TrackingLongColumnVector(4);
+ TrackingLongColumnVector valCol1 = new TrackingLongColumnVector(4);
+ TrackingLongColumnVector valCol2 = new TrackingLongColumnVector(4);
+ keyCol.vector[1] = 99L;
+ valCol1.vector[1] = 88L;
+ valCol2.vector[3] = 77L;
+ batch.cols[0] = keyCol;
+ batch.cols[1] = valCol1;
+ batch.cols[2] = valCol2;
+
+ int[] noMatchs = new int[] {1, 3};
+ op.generateOuterNulls(batch, noMatchs, noMatchs.length);
+
+ assertEquals(Arrays.asList(1, 3), keyCol.clearedIndices);
+ assertEquals(Arrays.asList(1, 3), valCol1.clearedIndices);
+ assertEquals(Arrays.asList(1, 3), valCol2.clearedIndices);
+
+ assertFalse(keyCol.noNulls);
+ assertTrue(keyCol.isNull[1]);
+ assertTrue(keyCol.isNull[3]);
+ assertFalse(keyCol.isNull[0]);
+ assertFalse(keyCol.isNull[2]);
+
+ assertEquals(0L, keyCol.vector[1]);
+ assertEquals(0L, valCol1.vector[1]);
+ assertEquals(0L, valCol2.vector[3]);
+ }
+
+ @Test
+ void
generateOuterNullsRepeatedAllCallsClearValueAtIndexZeroForEachMappedColumn()
throws HiveException {
+ TestableOuterOp op = new TestableOuterOp();
+ op.outerSmallTableKeyColumnMap = new int[] {0};
+ op.smallTableValueColumnMap = new int[] {1};
+
+ VectorizedRowBatch batch = new VectorizedRowBatch(2, 4);
+ TrackingLongColumnVector keyCol = new TrackingLongColumnVector(4);
+ TrackingLongColumnVector valCol = new TrackingLongColumnVector(4);
+ keyCol.vector[0] = 42L;
+ valCol.vector[0] = 84L;
+ batch.cols[0] = keyCol;
+ batch.cols[1] = valCol;
+
+ op.generateOuterNullsRepeatedAll(batch);
+
+ assertEquals(Arrays.asList(0), keyCol.clearedIndices);
+ assertEquals(Arrays.asList(0), valCol.clearedIndices);
+
+ // isRepeating is set by the operator, not by clearValue.
+ assertFalse(keyCol.noNulls);
+ assertTrue(keyCol.isNull[0]);
+ assertTrue(keyCol.isRepeating);
+ assertFalse(valCol.noNulls);
+ assertTrue(valCol.isNull[0]);
+ assertTrue(valCol.isRepeating);
+
+ assertEquals(0L, keyCol.vector[0]);
+ assertEquals(0L, valCol.vector[0]);
+ }
+
+ @Test
+ void generateOuterNullsSetsBookkeepingOnTypeWithNoClearSlotValueOverride()
throws HiveException, IOException {
+ // VoidColumnVector inherits the base no-op clearSlotValue — verifies the
+ // operator still drives the null-marking through clearValue() on a type
+ // without a per-slot value to zero.
+ TestableOuterOp op = new TestableOuterOp();
+ op.outerSmallTableKeyColumnMap = new int[] {};
+ op.smallTableValueColumnMap = new int[] {0};
+
+ VectorizedRowBatch batch = new VectorizedRowBatch(1, 4);
+ VoidColumnVector voidCol = new VoidColumnVector(4);
+ batch.cols[0] = voidCol;
+
+ int[] noMatchs = new int[] {1, 3};
+ op.generateOuterNulls(batch, noMatchs, noMatchs.length);
+
+ assertFalse(voidCol.noNulls);
+ assertTrue(voidCol.isNull[1]);
+ assertTrue(voidCol.isNull[3]);
+ assertFalse(voidCol.isNull[0]);
+ assertFalse(voidCol.isNull[2]);
+ }
+
+ /**
+ * For each {@link ColumnVector} subclass whose {@code clearSlotValue} is
+ * overridden, verifies the operator's call through {@code clearValue}
reaches
+ * the override and clears the slot to the type's cleared state.
+ */
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("modifiedColumnVectorTypes")
+ void generateOuterNullsClearsSlotForEachModifiedType(
+ String typeName,
+ ColumnVector cv,
+ Runnable preLoad,
+ Runnable assertSlotCleared) throws HiveException, IOException {
+
+ TestableOuterOp op = new TestableOuterOp();
+ op.outerSmallTableKeyColumnMap = new int[] {};
+ op.smallTableValueColumnMap = new int[] {0};
+
+ VectorizedRowBatch batch = new VectorizedRowBatch(1, 4);
+ preLoad.run();
+ batch.cols[0] = cv;
+
+ int[] noMatchs = new int[] {2};
+ op.generateOuterNulls(batch, noMatchs, noMatchs.length);
Review Comment:
I think we need a similar parameterized test for
`generateOuterNullsRepeatedAll`?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]