Skip to content

Commit

Permalink
fix: cleaning vector module v4
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed Sep 12, 2024
1 parent a99a701 commit f8bc623
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,8 @@ public TypeEqualsVisitor(ValueVector right, boolean checkName, boolean checkMeta
}

/** Check type equals without passing IN param in VectorVisitor. */
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ValueVector)) {
return false;
}
ValueVector left = (ValueVector) obj;
@SuppressWarnings("NonOverridingEquals")
public boolean equals(ValueVector left) {
return left.accept(this, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ public ValueVector visit(BaseVariableWidthViewVector left, Void value) {
}

@Override
@SuppressWarnings("EqualsIncompatibleType")
public ValueVector visit(ListVector deltaVector, Void value) {
Preconditions.checkArgument(
typeVisitor.equals(deltaVector),
Expand Down Expand Up @@ -322,7 +321,6 @@ public ValueVector visit(ListVector deltaVector, Void value) {
}

@Override
@SuppressWarnings("EqualsIncompatibleType")
public ValueVector visit(LargeListVector deltaVector, Void value) {
Preconditions.checkArgument(
typeVisitor.equals(deltaVector),
Expand Down Expand Up @@ -394,7 +392,6 @@ public ValueVector visit(LargeListVector deltaVector, Void value) {
}

@Override
@SuppressWarnings("EqualsIncompatibleType")
public ValueVector visit(FixedSizeListVector deltaVector, Void value) {
Preconditions.checkArgument(
typeVisitor.equals(deltaVector),
Expand Down Expand Up @@ -441,7 +438,6 @@ public ValueVector visit(FixedSizeListVector deltaVector, Void value) {
}

@Override
@SuppressWarnings("EqualsIncompatibleType")
public ValueVector visit(NonNullableStructVector deltaVector, Void value) {
Preconditions.checkArgument(
typeVisitor.equals(deltaVector),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ public void testToISO8601IntervalString() {
new PeriodDuration(Period.ZERO, Duration.ofNanos(123)).toISO8601IntervalString());
assertEquals(
"PT1.000000123S",
new PeriodDuration(Period.ZERO, Duration.ofSeconds(1).withNanos(123))
new PeriodDuration(Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(1).getSeconds(), 123))
.toISO8601IntervalString());
assertEquals(
"PT1H1.000000123S",
new PeriodDuration(Period.ZERO, Duration.ofSeconds(3601).withNanos(123))
new PeriodDuration(Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(3601).getSeconds(), 123))
.toISO8601IntervalString());
assertEquals(
"PT24H1M1.000000123S",
new PeriodDuration(Period.ZERO, Duration.ofSeconds(86461).withNanos(123))
new PeriodDuration(Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123))
.toISO8601IntervalString());
assertEquals(
"P1Y2M3DT24H1M1.000000123S",
new PeriodDuration(Period.of(1, 2, 3), Duration.ofSeconds(86461).withNanos(123))
new PeriodDuration(Period.of(1, 2, 3), Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123))
.toISO8601IntervalString());

assertEquals(
Expand All @@ -77,11 +77,11 @@ public void testToISO8601IntervalString() {
new PeriodDuration(Period.ZERO, Duration.ofNanos(-123)).toISO8601IntervalString());
assertEquals(
"PT-24H-1M-0.999999877S",
new PeriodDuration(Period.ZERO, Duration.ofSeconds(-86461).withNanos(123))
new PeriodDuration(Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(-86461).getSeconds(), 123))
.toISO8601IntervalString());
assertEquals(
"P-1Y-2M-3DT-0.999999877S",
new PeriodDuration(Period.of(-1, -2, -3), Duration.ofSeconds(-1).withNanos(123))
new PeriodDuration(Period.of(-1, -2, -3), Duration.ofSeconds(Duration.ofSeconds(-1).getSeconds(), 123))
.toISO8601IntervalString());
}

Expand All @@ -95,8 +95,7 @@ public void testTemporalAccessor() {
PeriodDuration pd2 = new PeriodDuration(Period.ZERO, Duration.ofMinutes(1));
assertEquals(LocalDateTime.of(2024, 1, 2, 3, 3), pd2.subtractFrom(dateTime));

PeriodDuration pd3 =
new PeriodDuration(Period.of(1, 2, 3), Duration.ofSeconds(86461).withNanos(123));
PeriodDuration pd3 = new PeriodDuration(Period.of(1, 2, 3), Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123));
assertEquals(pd3.get(ChronoUnit.YEARS), 1);
assertEquals(pd3.get(ChronoUnit.MONTHS), 2);
assertEquals(pd3.get(ChronoUnit.DAYS), 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.nio.charset.StandardCharsets;
import java.util.Random;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
Expand Down Expand Up @@ -175,12 +176,12 @@ public void testTypeBufferCountInVectorsWithVariadicBuffers() {
try (ViewVarCharVector viewVarCharVector = new ViewVarCharVector("myvector", allocator)) {
viewVarCharVector.allocateNew(32, 6);

viewVarCharVector.setSafe(0, generateRandomString(8).getBytes());
viewVarCharVector.setSafe(1, generateRandomString(12).getBytes());
viewVarCharVector.setSafe(2, generateRandomString(14).getBytes());
viewVarCharVector.setSafe(3, generateRandomString(18).getBytes());
viewVarCharVector.setSafe(4, generateRandomString(22).getBytes());
viewVarCharVector.setSafe(5, generateRandomString(24).getBytes());
viewVarCharVector.setSafe(0, generateRandomString(8).getBytes(StandardCharsets.UTF_8));
viewVarCharVector.setSafe(1, generateRandomString(12).getBytes(StandardCharsets.UTF_8));
viewVarCharVector.setSafe(2, generateRandomString(14).getBytes(StandardCharsets.UTF_8));
viewVarCharVector.setSafe(3, generateRandomString(18).getBytes(StandardCharsets.UTF_8));
viewVarCharVector.setSafe(4, generateRandomString(22).getBytes(StandardCharsets.UTF_8));
viewVarCharVector.setSafe(5, generateRandomString(24).getBytes(StandardCharsets.UTF_8));

viewVarCharVector.setValueCount(6);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ public void testSplitAndTransferWithMixedVectors() throws Exception {
}

@Test
@SuppressWarnings("EnumOrdinal")
public void testGetFieldTypeInfo() throws Exception {
Map<String, String> metadata = new HashMap<>();
metadata.put("key1", "value1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ public void testSetSafeWithArrowBufNoExcessAllocs() {
}
fromVector.setValueCount(numValues);
ArrowBuf fromDataBuffer = fromVector.getDataBuffer();
assertTrue(numValues * valueBytesLength <= fromDataBuffer.capacity());
assertTrue((long) numValues * valueBytesLength <= fromDataBuffer.capacity());

/*
* Copy the entries one-by-one from 'fromVector' to 'toVector', but use the setSafe with
Expand Down Expand Up @@ -2398,11 +2398,11 @@ public void testMultipleClose() {
*/
public static void setBytes(int index, byte[] bytes, VarCharVector vector) {
final int currentOffset =
vector.offsetBuffer.getInt(index * BaseVariableWidthVector.OFFSET_WIDTH);
vector.offsetBuffer.getInt((long) index * BaseVariableWidthVector.OFFSET_WIDTH);

BitVectorHelper.setBit(vector.validityBuffer, index);
vector.offsetBuffer.setInt(
(index + 1) * BaseVariableWidthVector.OFFSET_WIDTH, currentOffset + bytes.length);
(long) (index + 1) * BaseVariableWidthVector.OFFSET_WIDTH, currentOffset + bytes.length);
vector.valueBuffer.setBytes(currentOffset, bytes, 0, bytes.length);
}

Expand Down Expand Up @@ -2669,8 +2669,8 @@ public void testGetPointerVariableWidth() {

try (VarCharVector vec1 = new VarCharVector("vec1", allocator);
VarCharVector vec2 = new VarCharVector("vec2", allocator)) {
vec1.allocateNew(sampleData.length * 10, sampleData.length);
vec2.allocateNew(sampleData.length * 10, sampleData.length);
vec1.allocateNew(sampleData.length * 10L, sampleData.length);
vec2.allocateNew(sampleData.length * 10L, sampleData.length);

for (int i = 0; i < sampleData.length; i++) {
String str = sampleData[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void testDurationVectorIterable() {
durationVector.setSafe(2, 555);
durationVector.setValueCount(3);

final Duration value1 = Duration.ofMillis(30000);
final Duration value1 = Duration.ofSeconds(30);
final Duration value3 = Duration.ofMillis(555);
assertThat(
durationVector.getValueIterable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public void testSetSafeWithArrowBufNoExcessAllocs() {
}
fromVector.setValueCount(numValues);
ArrowBuf fromDataBuffer = fromVector.getDataBuffer();
assertTrue(numValues * valueBytesLength <= fromDataBuffer.capacity());
assertTrue((long) numValues * valueBytesLength <= fromDataBuffer.capacity());

/*
* Copy the entries one-by-one from 'fromVector' to 'toVector', but use the setSafe with
Expand Down Expand Up @@ -1668,20 +1668,20 @@ static Stream<Arguments> vectorCreatorProvider() {
return Stream.of(
Arguments.of(
(Function<BufferAllocator, BaseVariableWidthViewVector>)
(allocator ->
allocator ->
newVector(
ViewVarBinaryVector.class,
EMPTY_SCHEMA_PATH,
Types.MinorType.VIEWVARBINARY,
allocator))),
allocator)),
Arguments.of(
(Function<BufferAllocator, BaseVariableWidthViewVector>)
(allocator ->
allocator ->
newVector(
ViewVarCharVector.class,
EMPTY_SCHEMA_PATH,
Types.MinorType.VIEWVARCHAR,
allocator))));
allocator)));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void testLoadValidityBuffer() throws IOException {
ArrowBuf[] values = new ArrowBuf[4];
for (int i = 0; i < 4; i += 2) {
ArrowBuf buf1 = allocator.buffer(BitVectorHelper.getValidityBufferSize(count));
ArrowBuf buf2 = allocator.buffer(count * 4); // integers
ArrowBuf buf2 = allocator.buffer(count * 4L); // integers
buf1.setZero(0, buf1.capacity());
buf2.setZero(0, buf2.capacity());
values[i] = buf1;
Expand All @@ -228,10 +228,10 @@ public void testLoadValidityBuffer() throws IOException {
BitVectorHelper.setBit(buf1, j);
}

buf2.setInt(j * 4, j);
buf2.setInt(j * 4L, j);
}
buf1.writerIndex((int) Math.ceil(count / 8));
buf2.writerIndex(count * 4);
buf1.writerIndex((int) Math.ceil(count / 8.0));
buf2.writerIndex(count * 4L);
}

/*
Expand Down

0 comments on commit f8bc623

Please sign in to comment.