Skip to content

Commit

Permalink
ARROW-12838: [Java][Gandiva] Fix JNI CI test
Browse files Browse the repository at this point in the history
Fix checkstyle error in JNI CI build

Closes #10367 from jvictorhuguenin/fix-ci-checkstyle-error

Authored-by: frank400 <j.victorhuguenin2018@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
jvictorhuguenin authored and kou committed May 25, 2021
1 parent 233a76c commit 5380a4d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,51 @@ private InNode(Set<Integer> values, Set<Long> longValues, Set<String> stringValu
this.input = node;
}

/**
* Makes an IN node for int values.
*
* @param node Node with the 'IN' clause.
* @param intValues Int values to build the IN node.
* @retur InNode referring to tree node.
*/
public static InNode makeIntInExpr(TreeNode node, Set<Integer> intValues) {
return new InNode(intValues,
null, null, null, null, null, null, null,
null, node);
}

/**
* Makes an IN node for long values.
*
* @param node Node with the 'IN' clause.
* @param longValues Long values to build the IN node.
* @retur InNode referring to tree node.
*/
public static InNode makeLongInExpr(TreeNode node, Set<Long> longValues) {
return new InNode(null, longValues,
null, null, null, null, null, null,
null, node);
}

/**
* Makes an IN node for float values.
*
* @param node Node with the 'IN' clause.
* @param floatValues Float values to build the IN node.
* @retur InNode referring to tree node.
*/
public static InNode makeFloatInExpr(TreeNode node, Set<Float> floatValues) {
return new InNode(null, null, null, null, null, null,
null, floatValues, null, node);
}

/**
* Makes an IN node for double values.
*
* @param node Node with the 'IN' clause.
* @param doubleValues Double values to build the IN node.
* @retur InNode referring to tree node.
*/
public static InNode makeDoubleInExpr(TreeNode node, Set<Double> doubleValues) {
return new InNode(null, null, null, null, null,
null, null, null, doubleValues, node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,10 +1220,10 @@ public void testInExpr() throws GandivaException, Exception {
output.add(bitVector);
eval.evaluate(batch, output);

for (int i = 0; i < 4; i++) {
for (int i = 0; i < 5; i++) {
assertTrue(bitVector.getObject(i).booleanValue());
}
for (int i = 4; i < 16; i++) {
for (int i = 5; i < 16; i++) {
assertFalse(bitVector.getObject(i).booleanValue());
}

Expand All @@ -1245,31 +1245,29 @@ public void testInExprDecimal() throws GandivaException, Exception {
decimalSet.add(new BigDecimal(Long.MAX_VALUE));
decimalSet.add(new BigDecimal(Long.MIN_VALUE));
TreeNode inExpr =
TreeBuilder.makeInExpressionDecimal(TreeBuilder.makeField(c1),
decimalSet, precision, scale);
TreeBuilder.makeInExpressionDecimal(TreeBuilder.makeField(c1),
decimalSet, precision, scale);
ExpressionTree expr = TreeBuilder.makeExpression(inExpr,
Field.nullable("result", boolType));
Field.nullable("result", boolType));
Schema schema = new Schema(Lists.newArrayList(c1));
Projector eval = Projector.make(schema, Lists.newArrayList(expr));

// Create a row-batch with some sample data to look for
int numRows = 16;
// Only the first 8 values will be valid.
byte[] validity = new byte[]{(byte) 255, 0};
String[] c1Values =
new String[]{"1", "2", "3", "4", "-0.0", "6", "7", "8", "9", "10", "11", "12", "13", "14",
String.valueOf(Long.MAX_VALUE),
String.valueOf(Long.MIN_VALUE)};
new String[]{"1", "2", "3", "4", "-0.0", "6", "7", "8", "9", "10", "11", "12", "13", "14",
String.valueOf(Long.MAX_VALUE),
String.valueOf(Long.MIN_VALUE)};

DecimalVector c1Data = decimalVector(c1Values, precision, scale);
ArrowBuf c1Validity = buf(validity);

ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0);
ArrowRecordBatch batch =
new ArrowRecordBatch(
numRows,
Lists.newArrayList(fieldNode, fieldNode),
Lists.newArrayList(c1Validity, c1Data.getDataBuffer(), c1Data.getValidityBuffer()));
new ArrowRecordBatch(
numRows,
Lists.newArrayList(fieldNode, fieldNode),
Lists.newArrayList(c1Validity, c1Data.getDataBuffer(), c1Data.getValidityBuffer()));

BitVector bitVector = new BitVector(EMPTY_SCHEMA_PATH, allocator);
bitVector.allocateNew(numRows);
Expand All @@ -1278,11 +1276,10 @@ public void testInExprDecimal() throws GandivaException, Exception {
output.add(bitVector);
eval.evaluate(batch, output);

// The first four values in the vector must match the expression, but not the other ones.
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 5; i++) {
assertTrue(bitVector.getObject(i).booleanValue());
}
for (int i = 4; i < 16; i++) {
for (int i = 5; i < 16; i++) {
assertFalse(bitVector.getObject(i).booleanValue());
}

Expand All @@ -1296,9 +1293,9 @@ public void testInExprDouble() throws GandivaException, Exception {
Field c1 = Field.nullable("c1", float64);

TreeNode inExpr =
TreeBuilder.makeInExpressionDouble(TreeBuilder.makeField(c1),
Sets.newHashSet(1.0, -0.0, 3.0, 4.0, Double.NaN,
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY));
TreeBuilder.makeInExpressionDouble(TreeBuilder.makeField(c1),
Sets.newHashSet(1.0, -0.0, 3.0, 4.0, Double.NaN,
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY));
ExpressionTree expr = TreeBuilder.makeExpression(inExpr, Field.nullable("result", boolType));
Schema schema = new Schema(Lists.newArrayList(c1));
Projector eval = Projector.make(schema, Lists.newArrayList(expr));
Expand All @@ -1307,19 +1304,19 @@ public void testInExprDouble() throws GandivaException, Exception {
int numRows = 16;
// Only the first 8 values will be valid.
byte[] validity = new byte[]{(byte) 255, 0};
double[] c1Values = new double[]{1, -0.0, Double.NEGATIVE_INFINITY , Double.POSITIVE_INFINITY, Double.NaN,
6, 7, 8, 9, 10, 11, 12, 13, 14, 4 , 3};
double[] c1Values = new double[]{1, -0.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN,
6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 3};

ArrowBuf c1Validity = buf(validity);
ArrowBuf c1Data = doubleBuf(c1Values);
ArrowBuf c2Validity = buf(validity);

ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0);
ArrowRecordBatch batch =
new ArrowRecordBatch(
numRows,
Lists.newArrayList(fieldNode, fieldNode),
Lists.newArrayList(c1Validity, c1Data, c2Validity));
new ArrowRecordBatch(
numRows,
Lists.newArrayList(fieldNode, fieldNode),
Lists.newArrayList(c1Validity, c1Data, c2Validity));

BitVector bitVector = new BitVector(EMPTY_SCHEMA_PATH, allocator);
bitVector.allocateNew(numRows);
Expand All @@ -1328,11 +1325,11 @@ public void testInExprDouble() throws GandivaException, Exception {
output.add(bitVector);
eval.evaluate(batch, output);

// The first five values in the vector must match the expression, but not the other ones.
for (int i = 1; i < 5; i++) {
// The first four values in the vector must match the expression, but not the other ones.
for (int i = 0; i < 4; i++) {
assertTrue(bitVector.getObject(i).booleanValue());
}
for (int i = 5; i < 16; i++) {
for (int i = 4; i < 16; i++) {
assertFalse(bitVector.getObject(i).booleanValue());
}

Expand Down

0 comments on commit 5380a4d

Please sign in to comment.