Skip to content

Commit

Permalink
fix: addressing reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed May 22, 2024
1 parent e33deb6 commit 4b71621
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1323,24 +1323,21 @@ protected final void handleSafe(int index, int dataLength) {
/**
* Copy a cell value from a particular index in source vector to a particular position in this
* vector.
* TODO: Improve functionality to support copying views.
* <a href="https://github.com/apache/arrow/issues/40933">Enhance CopyFrom</a>
*
* @param fromIndex position to copy from in source vector
* @param thisIndex position to copy to in this vector
* @param from source vector
*/
@Override
public void copyFrom(int fromIndex, int thisIndex, ValueVector from) {
Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
Preconditions.checkArgument(getMinorType() == from.getMinorType());
if (from.isNull(fromIndex)) {
BitVectorHelper.unsetBit(this.validityBuffer, thisIndex);
BitVectorHelper.unsetBit(validityBuffer, thisIndex);
} else {
final int viewLength = from.getDataBuffer().getInt((long) fromIndex * ELEMENT_SIZE);
BitVectorHelper.setBit(this.validityBuffer, thisIndex);
BitVectorHelper.setBit(validityBuffer, thisIndex);
final int start = thisIndex * ELEMENT_SIZE;
final int copyStart = fromIndex * ELEMENT_SIZE;
from.getDataBuffer().getBytes(start, this.viewBuffer, copyStart, ELEMENT_SIZE);
from.getDataBuffer().getBytes(start, viewBuffer, copyStart, ELEMENT_SIZE);
if (viewLength > INLINE_SIZE) {
final int bufIndex = from.getDataBuffer().getInt(((long) fromIndex * ELEMENT_SIZE) +
LENGTH_WIDTH + PREFIX_WIDTH);
Expand All @@ -1358,25 +1355,23 @@ public void copyFrom(int fromIndex, int thisIndex, ValueVector from) {
/**
* Same as {@link #copyFrom(int, int, ValueVector)} except that it handles the case when the
* capacity of the vector needs to be expanded before copy.
* TODO: Improve functionality to support copying views.
* <a href="https://github.com/apache/arrow/issues/40933">Enhance CopyFrom</a>
* @param fromIndex position to copy from in source vector
* @param thisIndex position to copy to in this vector
* @param from source vector
*/
@Override
public void copyFromSafe(int fromIndex, int thisIndex, ValueVector from) {
Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
Preconditions.checkArgument(getMinorType() == from.getMinorType());
if (from.isNull(fromIndex)) {
handleSafe(thisIndex, 0);
BitVectorHelper.unsetBit(this.validityBuffer, thisIndex);
BitVectorHelper.unsetBit(validityBuffer, thisIndex);
} else {
final int viewLength = from.getDataBuffer().getInt((long) fromIndex * ELEMENT_SIZE);
handleSafe(thisIndex, viewLength);
BitVectorHelper.setBit(this.validityBuffer, thisIndex);
BitVectorHelper.setBit(validityBuffer, thisIndex);
final int start = thisIndex * ELEMENT_SIZE;
final int copyStart = fromIndex * ELEMENT_SIZE;
from.getDataBuffer().getBytes(start, this.viewBuffer, copyStart, ELEMENT_SIZE);
from.getDataBuffer().getBytes(start, viewBuffer, copyStart, ELEMENT_SIZE);
if (viewLength > INLINE_SIZE) {
final int bufIndex = from.getDataBuffer().getInt(((long) fromIndex * ELEMENT_SIZE) +
LENGTH_WIDTH + PREFIX_WIDTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public FieldWriter getNewFieldWriter(ValueVector vector) {
return new VarBinaryWriterImpl((VarBinaryVector) vector);
}
},
VIEWVARBINARY(Binary.INSTANCE) {
VIEWVARBINARY(BinaryView.INSTANCE) {
@Override
public FieldVector getNewVector(
Field field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
Expand All @@ -51,6 +50,7 @@
import org.junit.jupiter.api.BeforeEach;
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;


Expand Down Expand Up @@ -1455,21 +1455,21 @@ public void testSafeOverwriteLongFromALongerLongString() {
}
}

static Stream<Class<? extends BaseVariableWidthViewVector>> vectorProvider() {
static Stream<Arguments> vectorTypeAndClassProvider() {
return Stream.of(
ViewVarCharVector.class,
ViewVarBinaryVector.class
Arguments.of(Types.MinorType.VIEWVARBINARY, ViewVarBinaryVector.class),
Arguments.of(Types.MinorType.VIEWVARCHAR, ViewVarCharVector.class)
);
}

@ParameterizedTest
@MethodSource("vectorProvider")
public void testCopyFromWithNulls(Class<? extends BaseVariableWidthViewVector> vectorClass)
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
try (final BaseVariableWidthViewVector vector = vectorClass.getConstructor(String.class, BufferAllocator.class)
.newInstance(EMPTY_SCHEMA_PATH, allocator);
final BaseVariableWidthViewVector vector2 = vectorClass.getConstructor(String.class, BufferAllocator.class)
.newInstance(EMPTY_SCHEMA_PATH, allocator)) {
@MethodSource({"vectorTypeAndClassProvider"})
public void testCopyFromWithNulls(Types.MinorType type,
Class<? extends BaseVariableWidthViewVector> vectorClass) {
try (final BaseVariableWidthViewVector vector = newVector(vectorClass, EMPTY_SCHEMA_PATH,
type, allocator);
final BaseVariableWidthViewVector vector2 = newVector(vectorClass, EMPTY_SCHEMA_PATH,
type, allocator)) {
final int initialCapacity = 1024;
vector.setInitialCapacity(initialCapacity);
vector.allocateNew();
Expand Down Expand Up @@ -1556,13 +1556,13 @@ public void testCopyFromWithNulls(Class<? extends BaseVariableWidthViewVector> v
}

@ParameterizedTest
@MethodSource("vectorProvider")
public void testCopyFromSafeWithNulls(Class<? extends BaseVariableWidthViewVector> vectorClass)
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
try (final BaseVariableWidthViewVector vector = vectorClass.getConstructor(String.class, BufferAllocator.class)
.newInstance(EMPTY_SCHEMA_PATH, allocator);
final BaseVariableWidthViewVector vector2 = vectorClass.getConstructor(String.class, BufferAllocator.class)
.newInstance(EMPTY_SCHEMA_PATH, allocator)) {
@MethodSource("vectorTypeAndClassProvider")
public void testCopyFromSafeWithNulls(Types.MinorType type,
Class<? extends BaseVariableWidthViewVector> vectorClass) {
try (final BaseVariableWidthViewVector vector = newVector(vectorClass, EMPTY_SCHEMA_PATH,
type, allocator);
final BaseVariableWidthViewVector vector2 = newVector(vectorClass, EMPTY_SCHEMA_PATH,
type, allocator)) {

final int initialCapacity = 4096;
vector.setInitialCapacity(initialCapacity);
Expand Down

0 comments on commit 4b71621

Please sign in to comment.