This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git

commit 8c3b8792ced981785e0efe1d973cf791aa975473
Author: praveenbingo <[email protected]>
AuthorDate: Mon Sep 17 16:19:12 2018 +0530

    [Gandiva] Fixed equality issue in validator.
    
    Fixed equality issue in validator.
---
 cpp/src/gandiva/expr_validator.cc                  | 16 +++---
 .../arrow/gandiva/evaluator/ProjectorTest.java     | 62 +++++++++++++++++++++-
 2 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/cpp/src/gandiva/expr_validator.cc 
b/cpp/src/gandiva/expr_validator.cc
index abcbe4c..ad6825e 100644
--- a/cpp/src/gandiva/expr_validator.cc
+++ b/cpp/src/gandiva/expr_validator.cc
@@ -102,17 +102,17 @@ Status ExprValidator::Visit(const IfNode& node) {
   auto then_node_ret_type = node.then_node()->return_type();
   auto else_node_ret_type = node.else_node()->return_type();
 
-  if (if_node_ret_type != then_node_ret_type) {
+  if (!if_node_ret_type->Equals(*then_node_ret_type)) {
     std::stringstream ss;
-    ss << "Return type of if " << *if_node_ret_type << " and then "
-       << then_node_ret_type->name() << " not matching.";
+    ss << "Return type of if " << *if_node_ret_type << " and then " << 
*then_node_ret_type
+       << " not matching.";
     return Status::ExpressionValidationError(ss.str());
   }
 
-  if (if_node_ret_type != else_node_ret_type) {
+  if (!if_node_ret_type->Equals(*else_node_ret_type)) {
     std::stringstream ss;
-    ss << "Return type of if " << *if_node_ret_type << " and else "
-       << else_node_ret_type->name() << " not matching.";
+    ss << "Return type of if " << *if_node_ret_type << " and else " << 
*else_node_ret_type
+       << " not matching.";
     return Status::ExpressionValidationError(ss.str());
   }
 
@@ -140,8 +140,8 @@ Status ExprValidator::Visit(const BooleanNode& node) {
     return Status::ExpressionValidationError(ss.str());
   }
 
-  for (auto& child : node.children()) {
-    if (child->return_type() != arrow::boolean()) {
+  for (auto &child : node.children()) {
+    if (!child->return_type()->Equals(arrow::boolean())) {
       std::stringstream ss;
       ss << "Boolean expression has a child with return type "
          << child->return_type()->name() << ", expected return type boolean";
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 9daec0e..5892b73 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
@@ -753,6 +753,67 @@ public class ProjectorTest extends BaseEvaluatorTest {
   }
 
   @Test
+  public void testGDV117() throws GandivaException, Exception {    /*
+   * when isnotnull(x) then x
+   * else y
+   */
+    Field x = Field.nullable("x", new ArrowType.Time(TimeUnit.MILLISECOND, 
32));
+    TreeNode x_node = TreeBuilder.makeField(x);
+
+    Field y = Field.nullable("y", new ArrowType.Time(TimeUnit.MILLISECOND, 
32));
+    TreeNode y_node = TreeBuilder.makeField(y);
+
+    // if isnotnull(x) then x else y
+    TreeNode condition = 
TreeBuilder.makeFunction("isnotnull",Lists.newArrayList(x_node) ,
+            boolType);
+    TreeNode if_coalesce = TreeBuilder.makeIf(
+            condition,
+            x_node,
+            y_node,
+            new ArrowType.Time(TimeUnit.MILLISECOND, 32));
+
+    ExpressionTree expr = TreeBuilder.makeExpression(if_coalesce, x);
+    Schema schema = new Schema(Lists.newArrayList(x, y));
+    Projector eval = Projector.make(schema, Lists.newArrayList(expr));
+
+    int numRows = 2;
+    byte[] validity = new byte[]{(byte) 1};
+    byte[] validity_y = new byte[]{(byte) 3};
+    int[] values_x = new int[]{5, 1};
+    int[] values_y = new int[]{10, 2};
+    int[] expected = new int[]{5, 2};
+
+    ArrowBuf validity_buf = buf(validity);
+    ArrowBuf data_x = intBuf(values_x);
+
+
+    ArrowBuf validity_buf_y = buf(validity_y);
+    ArrowBuf data_y = intBuf(values_y);
+
+    ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0);
+    ArrowRecordBatch batch = new ArrowRecordBatch(
+            numRows,
+            Lists.newArrayList(fieldNode),
+            Lists.newArrayList(validity_buf, data_x, validity_buf_y, data_y));
+
+    IntVector intVector = new IntVector(EMPTY_SCHEMA_PATH, allocator);
+    intVector.allocateNew(numRows);
+
+    List<ValueVector> output = new ArrayList<ValueVector>();
+    output.add(intVector);
+    eval.evaluate(batch, output);
+
+    // output should be 5 and 2
+    assertFalse(intVector.isNull(0));
+    assertEquals(expected[0], intVector.get(0));
+    assertEquals(expected[1], intVector.get(1));
+
+    releaseRecordBatch(batch);
+    releaseValueVectors(output);
+    eval.close();
+  }
+
+  @Test
   public void testIsNull() throws GandivaException, Exception {
     Field x = Field.nullable("x", float64);
 
@@ -1001,7 +1062,6 @@ public class ProjectorTest extends BaseEvaluatorTest {
     releaseValueVectors(output);
   }
 
-  // This test is ignored until the cpp layer handles errors gracefully
   @Test
   public void testUnknownFunction() {
     Field c1 = Field.nullable("c1", int8);

Reply via email to