Skip to content

Commit

Permalink
fix: updating test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed May 13, 2024
1 parent f759755 commit 46dc10a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public abstract class BaseVariableWidthViewVector extends BaseValueVector implem
*
* */
// 12 byte unsigned int to track inline views
protected static final int INLINE_SIZE = 12;
public static final int INLINE_SIZE = 12;
// The first 4 bytes of view are allocated for length
public static final int LENGTH_WIDTH = 4;
// The second 4 bytes of view are allocated for prefix width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public Boolean visit(BaseVariableWidthViewVector left, Range range) {
if (!validate(left)) {
return false;
}
return compareBaseLargeVariableWidthViewVectors(range);
return compareBaseVariableWidthViewVectors(range);
}

@Override
Expand Down Expand Up @@ -454,13 +454,10 @@ protected boolean compareBaseLargeVariableWidthVectors(Range range) {
return true;
}

protected boolean compareBaseLargeVariableWidthViewVectors(Range range) {
protected boolean compareBaseVariableWidthViewVectors(Range range) {
BaseVariableWidthViewVector leftVector = (BaseVariableWidthViewVector) left;
BaseVariableWidthViewVector rightVector = (BaseVariableWidthViewVector) right;

List<ArrowBuf> leftDataBuffers = leftVector.getDataBuffers();
List<ArrowBuf> rightDataBuffers = rightVector.getDataBuffers();

final ArrowBuf leftViewBuffer = leftVector.getDataBuffer();
final ArrowBuf rightViewBuffer = rightVector.getDataBuffer();

Expand All @@ -484,35 +481,45 @@ protected boolean compareBaseLargeVariableWidthViewVectors(Range range) {
int startIndexRight = rightIndex * elementSize;
int endIndexRight = (rightIndex + 1) * elementSize;

// check equality in the view
int retView = ByteFunctionHelpers.equal(leftVector.getDataBuffer(), startIndexLeft, endIndexLeft,
rightVector.getDataBuffer(), startIndexRight, endIndexRight);
// check equality of the view
int retView = ByteFunctionHelpers.equal(leftViewBuffer, startIndexLeft, endIndexLeft,
rightViewBuffer, startIndexRight, endIndexRight);

if (retView == 0) {
return false;
}

int leftDataBufferIndex = leftViewBuffer.getInt(startIndexLeft + lengthWidth + prefixWidth);
int rightDataBufferIndex = rightViewBuffer.getInt(startIndexRight + lengthWidth + prefixWidth);
int leftDataBufferValueLength = leftVector.getValueLength(leftIndex);
int rightDataBufferValueLength = rightVector.getValueLength(rightIndex);

int leftDataBufferValueLength = leftVector.getValueLength(startIndexLeft);
int rightDataBufferValueLength = rightVector.getValueLength(startIndexRight);
if (leftDataBufferValueLength != rightDataBufferValueLength) {
return false;
}

final int leftDataOffset =
leftViewBuffer.getInt(startIndexLeft + lengthWidth + prefixWidth + bufIndexWidth);
final int rightDataOffset =
rightViewBuffer.getInt(startIndexRight + lengthWidth + prefixWidth + bufIndexWidth);
// if the value is stored in the dataBuffers
if (leftDataBufferValueLength > BaseVariableWidthViewVector.INLINE_SIZE) {
int leftDataBufferIndex = leftViewBuffer.getInt(startIndexLeft + lengthWidth + prefixWidth);
int rightDataBufferIndex = rightViewBuffer.getInt(startIndexRight + lengthWidth + prefixWidth);

ArrowBuf leftDataBuffer = leftDataBuffers.get(leftDataBufferIndex);
ArrowBuf rightDataBuffer = rightDataBuffers.get(rightDataBufferIndex);
List<ArrowBuf> leftDataBuffers = leftVector.getDataBuffers();
List<ArrowBuf> rightDataBuffers = rightVector.getDataBuffers();

// check equality in the dataBuf
int retDataBuf = ByteFunctionHelpers.equal(
leftDataBuffer, leftDataOffset, leftDataOffset + leftDataBufferValueLength,
rightDataBuffer, rightDataOffset, rightDataOffset + rightDataBufferValueLength);
final int leftDataOffset =
leftViewBuffer.getInt(startIndexLeft + lengthWidth + prefixWidth + bufIndexWidth);
final int rightDataOffset =
rightViewBuffer.getInt(startIndexRight + lengthWidth + prefixWidth + bufIndexWidth);

if (retDataBuf == 0) {
return false;
ArrowBuf leftDataBuffer = leftDataBuffers.get(leftDataBufferIndex);
ArrowBuf rightDataBuffer = rightDataBuffers.get(rightDataBufferIndex);

// check equality in the considered string stored in the dataBuffers
int retDataBuf = ByteFunctionHelpers.equal(
leftDataBuffer, leftDataOffset, leftDataOffset + leftDataBufferValueLength,
rightDataBuffer, rightDataOffset, rightDataOffset + rightDataBufferValueLength);

if (retDataBuf == 0) {
return false;
}
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.arrow.vector.compare;

import static org.apache.arrow.vector.testing.ValueVectorDataPopulator.setVector;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.charset.Charset;
import java.util.Arrays;
Expand Down Expand Up @@ -54,16 +54,16 @@
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class TestRangeEqualsVisitor {

private BufferAllocator allocator;

@Before
@BeforeEach
public void init() {
allocator = new RootAllocator(Long.MAX_VALUE);
}
Expand All @@ -72,8 +72,11 @@ public void init() {
private static final byte[] STR1 = "AAAAA1".getBytes(utf8Charset);
private static final byte[] STR2 = "BBBBBBBBB2".getBytes(utf8Charset);
private static final byte[] STR3 = "CCCC3".getBytes(utf8Charset);
private static final byte[] STR4 = "12345678901234A".getBytes(utf8Charset);
private static final byte[] STR5 = "A2345678901234ABC".getBytes(utf8Charset);
private static final byte[] STR6 = "AB45678901234ABCD".getBytes(utf8Charset);

@After
@AfterEach
public void terminate() throws Exception {
allocator.close();
}
Expand Down Expand Up @@ -138,11 +141,16 @@ public void testBaseVariableViewVectorRangeEquals() {
try (final ViewVarCharVector vector1 = new ViewVarCharVector("varchar", allocator);
final ViewVarCharVector vector2 = new ViewVarCharVector("varchar", allocator)) {

setVector(vector1, STR1, STR2, STR3, STR2, STR1);
setVector(vector2, STR1, STR2, STR3, STR2, STR1);
setVector(vector1, STR1, STR2, STR4, STR3, STR2, STR5, STR1, STR6);
setVector(vector2, STR1, STR2, STR4, STR3, STR2, STR5, STR1, STR6);

RangeEqualsVisitor visitor = new RangeEqualsVisitor(vector1, vector2);
// inclusion of long string in the middle
assertTrue(visitor.rangeEquals(new Range(1, 1, 3)));
// inclusion of long string at the start
assertTrue(visitor.rangeEquals(new Range(2, 2, 4)));
// inclusion of long string at the end
assertTrue(visitor.rangeEquals(new Range(4, 4, 4)));
}
}

Expand Down Expand Up @@ -490,7 +498,7 @@ public void testDenseUnionVectorEquals() {
}
}

@Ignore
@Disabled
@Test
public void testEqualsWithOutTypeCheck() {
try (final IntVector intVector = new IntVector("int", allocator);
Expand Down

0 comments on commit 46dc10a

Please sign in to comment.