From cec11bbf03c97f832a34782f944230bb5d3bbfcf Mon Sep 17 00:00:00 2001 From: Anthony Louis Date: Fri, 26 Mar 2021 16:07:12 -0300 Subject: [PATCH] Add tests to check Java compatibility --- .../gandiva/evaluator/ProjectorTest.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorTest.java index aa8cf7d37fc3f..edbc0603a6b07 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorTest.java @@ -1193,7 +1193,7 @@ public void testInExpr() throws GandivaException, Exception { Field c1 = Field.nullable("c1", int32); TreeNode inExpr = - TreeBuilder.makeInExpressionInt32(TreeBuilder.makeField(c1), Sets.newHashSet(1, 2, 3, 4, 5, 15, 16)); + TreeBuilder.makeInExpressionInt32(TreeBuilder.makeField(c1), Sets.newHashSet(1, 2, 3, 4, 5, 15, 16)); ExpressionTree expr = TreeBuilder.makeExpression(inExpr, Field.nullable("result", boolType)); Schema schema = new Schema(Lists.newArrayList(c1)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); @@ -1208,10 +1208,10 @@ public void testInExpr() throws GandivaException, Exception { 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); @@ -1297,7 +1297,7 @@ public void testInExprStrings() throws GandivaException, Exception { List args = Lists.newArrayList(TreeBuilder.makeField(c1), l1, l2); TreeNode substr = TreeBuilder.makeFunction("substr", args, new ArrowType.Utf8()); TreeNode inExpr = - TreeBuilder.makeInExpressionString(substr, Sets.newHashSet("one", "two", "thr", "fou")); + TreeBuilder.makeInExpressionString(substr, Sets.newHashSet("one", "two", "thr", "fou")); ExpressionTree expr = TreeBuilder.makeExpression(inExpr, Field.nullable("result", boolType)); Schema schema = new Schema(Lists.newArrayList(c1)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); @@ -1305,8 +1305,8 @@ public void testInExprStrings() throws GandivaException, Exception { int numRows = 16; byte[] validity = new byte[]{(byte) 255, 0}; String[] c1Values = new String[]{"one", "two", "three", "four", "five", "six", "seven", - "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", - "sixteen"}; + "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", + "sixteen"}; ArrowBuf c1Validity = buf(validity); List dataBufsX = stringBufs(c1Values); @@ -1314,10 +1314,10 @@ public void testInExprStrings() throws GandivaException, Exception { ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode, fieldNode), - Lists.newArrayList(c1Validity, dataBufsX.get(0), dataBufsX.get(1), c2Validity)); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode, fieldNode), + Lists.newArrayList(c1Validity, dataBufsX.get(0), dataBufsX.get(1), c2Validity)); BitVector bitVector = new BitVector(EMPTY_SCHEMA_PATH, allocator); bitVector.allocateNew(numRows); @@ -1509,9 +1509,9 @@ public void testDateTrunc() throws Exception { Field resultField = Field.nullable("result", date64); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(dateToYear, resultField), - TreeBuilder.makeExpression(dateToMonth, resultField)); + Lists.newArrayList( + TreeBuilder.makeExpression(dateToYear, resultField), + TreeBuilder.makeExpression(dateToMonth, resultField)); Schema schema = new Schema(Lists.newArrayList(dateField)); Projector eval = Projector.make(schema, exprs); @@ -1544,10 +1544,10 @@ public void testDateTrunc() throws Exception { ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode), - Lists.newArrayList(bufValidity, millisData)); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode), + Lists.newArrayList(bufValidity, millisData)); List output = new ArrayList(); for (int i = 0; i < exprs.size(); i++) { @@ -2151,26 +2151,28 @@ public void testCastVarcharFromFloat() throws Exception { 1.0, 0.001, 0.0009, + 0.00099893, 999999.9999, 10000000.0, + 23943410000000.343434, 23.45, 23.45, -23.45, }; long[] lenValues = new long[] { - 6L, 6L, 6L, 6L, 10L, 15L, 15L, + 6L, 6L, 6L, 6L, 10L, 15L, 15L, 15L, 30L, 0L, 6L, 6L }; /*The Java real numbers are represented in two ways and Gandiva must - * follow the same rules: - * - If the number is greater or equals than 10^7 and less than 10^(-3) - * it will be represented using scientific notation, e.g: - * - 0.000012 -> 1.2E-5 - * - 10000002.3 -> 1.00000023E7 - * - If the numbers are between that interval above, they are showed as is. - * - The "0.0" and "-0.0" must be represented as the same number: "0.0"*/ + * follow the same rules: + * - If the number is greater or equals than 10^7 and less than 10^(-3) + * it will be represented using scientific notation, e.g: + * - 0.000012 -> 1.2E-5 + * - 10000002.3 -> 1.00000023E7 + * - If the numbers are between that interval above, they are showed as is. + * */ String[] expValues = new String[] { Double.toString(0.0), // must be cast to -> "0.0" @@ -2178,8 +2180,10 @@ public void testCastVarcharFromFloat() throws Exception { Double.toString(1.0), // must be cast to -> "1.0" Double.toString(0.001), // must be cast to -> "0.001" Double.toString(0.0009), // must be cast to -> "9E-4" + Double.toString(0.00099893), // must be cast to -> "9E-4" Double.toString(999999.9999), // must be cast to -> "999999.9999" Double.toString(10000000.0), // must be cast to 1E7 + Double.toString(23943410000000.343434), "", Double.toString(23.45), Double.toString(-23.45)