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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7417f37  ARROW-5900: [Java] Bounds check for decimal args.
7417f37 is described below

commit 7417f37bb02e440c19730db4f9d91052e4ccb260
Author: Praveen <prav...@dremio.com>
AuthorDate: Wed Jul 10 23:52:02 2019 +0530

    ARROW-5900: [Java] Bounds check for decimal args.
    
    Add bounds checks on decimal data types.
    
    Author: Praveen <prav...@dremio.com>
    
    Closes #4845 from praveenbingo/ARROW-5900 and squashes the following 
commits:
    
    ade411246 <Praveen> Fix check.
    e8d6d0b67 <Praveen> ARROW-5900:  Bounds check for decimal args.
---
 .../arrow/gandiva/expression/ArrowTypeHelper.java  |  4 +++
 .../gandiva/evaluator/ProjectorDecimalTest.java    | 42 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git 
a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ArrowTypeHelper.java
 
b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ArrowTypeHelper.java
index 47d4eb7..c37a190 100644
--- 
a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ArrowTypeHelper.java
+++ 
b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ArrowTypeHelper.java
@@ -23,6 +23,7 @@ import org.apache.arrow.flatbuf.Type;
 import org.apache.arrow.gandiva.exceptions.GandivaException;
 import org.apache.arrow.gandiva.exceptions.UnsupportedTypeException;
 import org.apache.arrow.gandiva.ipc.GandivaTypes;
+import org.apache.arrow.util.Preconditions;
 import org.apache.arrow.vector.types.pojo.ArrowType;
 import org.apache.arrow.vector.types.pojo.Field;
 import org.apache.arrow.vector.types.pojo.Schema;
@@ -114,6 +115,9 @@ public class ArrowTypeHelper {
 
   private static void initArrowTypeDecimal(ArrowType.Decimal decimalType,
                                            GandivaTypes.ExtGandivaType.Builder 
builder) {
+    Preconditions.checkArgument(decimalType.getPrecision() > 0 &&
+            decimalType.getPrecision() <= 38, "Gandiva only supports decimals 
of upto 38 " +
+            "precision. Input precision : " + decimalType.getPrecision());
     builder.setPrecision(decimalType.getPrecision());
     builder.setScale(decimalType.getScale());
     builder.setType(GandivaTypes.GandivaType.DECIMAL);
diff --git 
a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorDecimalTest.java
 
b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorDecimalTest.java
index c5cb8f7..8b38edb 100644
--- 
a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorDecimalTest.java
+++ 
b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorDecimalTest.java
@@ -42,11 +42,15 @@ import org.apache.arrow.vector.types.pojo.ArrowType;
 import org.apache.arrow.vector.types.pojo.ArrowType.Decimal;
 import org.apache.arrow.vector.types.pojo.Field;
 import org.apache.arrow.vector.types.pojo.Schema;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import com.google.common.collect.Lists;
 
 public class ProjectorDecimalTest extends 
org.apache.arrow.gandiva.evaluator.BaseEvaluatorTest {
+  @Rule
+  public ExpectedException exception = ExpectedException.none();
 
   @Test
   public void test_add() throws GandivaException {
@@ -751,5 +755,43 @@ public class ProjectorDecimalTest extends 
org.apache.arrow.gandiva.evaluator.Bas
       eval.close();
     }
   }
+
+  @Test
+  public void testInvalidDecimal() throws GandivaException {
+    exception.expect(IllegalArgumentException.class);
+    exception.expectMessage("Gandiva only supports decimals of upto 38 
precision. Input precision" +
+            " : 0");
+    Decimal decimalType = new Decimal(0, 0);
+    Field int64f = Field.nullable("int64", int64);
+
+    Schema schema = new Schema(Lists.newArrayList(int64f));
+    Projector eval = Projector.make(schema,
+            Lists.newArrayList(
+                    TreeBuilder.makeExpression("castDECIMAL",
+                            Lists.newArrayList(int64f),
+                            Field.nullable("invalid_dec", decimalType)
+                    )
+            )
+    );
+  }
+
+  @Test
+  public void testInvalidDecimalGt38() throws GandivaException {
+    exception.expect(IllegalArgumentException.class);
+    exception.expectMessage("Gandiva only supports decimals of upto 38 
precision. Input precision" +
+            " : 42");
+    Decimal decimalType = new Decimal(42, 0);
+    Field int64f = Field.nullable("int64", int64);
+
+    Schema schema = new Schema(Lists.newArrayList(int64f));
+    Projector eval = Projector.make(schema,
+            Lists.newArrayList(
+                    TreeBuilder.makeExpression("castDECIMAL",
+                            Lists.newArrayList(int64f),
+                            Field.nullable("invalid_dec", decimalType)
+                    )
+            )
+    );
+  }
 }
 

Reply via email to