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

dongjoon pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new c9b0f7bf3 ORC-1588: Fix incorrect `Decimal` assert in 
`LeafFilterFactory`
c9b0f7bf3 is described below

commit c9b0f7bf3e6fc5bb268dbb150b0d861eef300835
Author: sychen <[email protected]>
AuthorDate: Wed Jan 17 12:11:55 2024 -0800

    ORC-1588: Fix incorrect `Decimal` assert in `LeafFilterFactory`
    
    ### What changes were proposed in this pull request?
    
    This PR aims to fix incorrect Decimal assert in LeafFilterFactory.
    
    ### Why are the changes needed?
    
    Due to the wrong assertion, `ArrayIndexOutOfBoundsException` happens.
    ```
    Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds 
for length 19
            at 
org.apache.hadoop.hive.common.type.FastHiveDecimalImpl.fastSerialize64(FastHiveDecimalImpl.java:2205)
            at 
org.apache.hadoop.hive.common.type.FastHiveDecimal.fastSerialize64(FastHiveDecimal.java:290)
            at 
org.apache.hadoop.hive.serde2.io.HiveDecimalWritable.serialize64(HiveDecimalWritable.java:537)
            at 
org.apache.orc.impl.filter.leaf.LeafFilterFactory.createBetweenFilter(LeafFilterFactory.java:165)
    ```
    
    ### How was this patch tested?
    
    UT & GA
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No
    
    Closes #1752 from cxzl25/ORC-1588.
    
    Authored-by: sychen <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
    (cherry picked from commit 4795165f6caf7c61d7b229c2efd7d04201dd3917)
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 .../org/apache/orc/impl/filter/leaf/LeafFilterFactory.java   |  2 +-
 .../src/test/org/apache/orc/impl/filter/TestConvFilter.java  | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git 
a/java/core/src/java/org/apache/orc/impl/filter/leaf/LeafFilterFactory.java 
b/java/core/src/java/org/apache/orc/impl/filter/leaf/LeafFilterFactory.java
index 1ff22e70e..c97e72cb7 100644
--- a/java/core/src/java/org/apache/orc/impl/filter/leaf/LeafFilterFactory.java
+++ b/java/core/src/java/org/apache/orc/impl/filter/leaf/LeafFilterFactory.java
@@ -159,7 +159,7 @@ public class LeafFilterFactory {
       case DECIMAL:
         HiveDecimalWritable dLow = (HiveDecimalWritable) low;
         HiveDecimalWritable dHigh = (HiveDecimalWritable) high;
-        assert dLow.scale() <= colType.getScale() && dLow.scale() <= 
colType.getScale();
+        assert dLow.scale() <= colType.getScale() && dHigh.getScale() <= 
colType.getScale();
         if (isDecimalAsLong(version, colType.getPrecision())) {
           return new LongFilters.LongBetween(colName, 
dLow.serialize64(colType.getScale()),
                                              
dHigh.serialize64(colType.getScale()), negated);
diff --git a/java/core/src/test/org/apache/orc/impl/filter/TestConvFilter.java 
b/java/core/src/test/org/apache/orc/impl/filter/TestConvFilter.java
index d95b8db69..6f5b19e20 100644
--- a/java/core/src/test/org/apache/orc/impl/filter/TestConvFilter.java
+++ b/java/core/src/test/org/apache/orc/impl/filter/TestConvFilter.java
@@ -34,6 +34,8 @@ import java.sql.Date;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 public class TestConvFilter {
   private final int scale = 4;
   private final TypeDescription schema = TypeDescription.createStruct()
@@ -152,6 +154,16 @@ public class TestConvFilter {
 
     FilterUtils.createVectorFilter(sArg, schema).accept(fc);
     ATestFilter.validateSelected(fc, 1, 2, 3);
+
+    SearchArgument sArg2 = SearchArgumentFactory.newBuilder()
+      .startOr()
+      .between("f3", PredicateLeaf.Type.DECIMAL, decimal(0),
+         new HiveDecimalWritable(HiveDecimal.create(Long.MAX_VALUE / 18, scale 
+ scale)))
+      .end()
+      .build();
+    assertThrows(AssertionError.class, () -> {
+      FilterUtils.createVectorFilter(sArg2, schema).accept(fc);
+    });
   }
 
   protected void setBatch(Boolean[] f1Values, Date[] f2Values, 
HiveDecimalWritable[] f3Values) {

Reply via email to