This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-java.git
The following commit(s) were added to refs/heads/main by this push:
new 2f3562708 MINOR: Fix validation of decimals at their declared
precision (#1342)
2f3562708 is described below
commit 2f35627084d27e06fcaca800bc05c772e3fc1113
Author: Robert Kruszewski <[email protected]>
AuthorDate: Fri Oct 30 09:24:48 2026 +0000
MINOR: Fix validation of decimals at their declared precision (#1342)
DecimalUtilityl#checkPrecisionAndScaleNoThrow used to reject value
precision that was equal to the vector precision, it should not.
---
.../apache/arrow/vector/util/DecimalUtility.java | 2 +-
.../arrow/vector/TestDecimalPrecisionBoundary.java | 53 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git
a/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
b/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
index 31b79fe53..647e460e4 100644
--- a/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
+++ b/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
@@ -118,7 +118,7 @@ public class DecimalUtility {
*/
public static boolean checkPrecisionAndScaleNoThrow(
BigDecimal value, int vectorPrecision, int vectorScale) {
- return value.scale() == vectorScale && value.precision() < vectorPrecision;
+ return value.scale() == vectorScale && value.precision() <=
vectorPrecision;
}
/**
diff --git
a/vector/src/test/java/org/apache/arrow/vector/TestDecimalPrecisionBoundary.java
b/vector/src/test/java/org/apache/arrow/vector/TestDecimalPrecisionBoundary.java
new file mode 100644
index 000000000..c7b4ee5bb
--- /dev/null
+++
b/vector/src/test/java/org/apache/arrow/vector/TestDecimalPrecisionBoundary.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.vector;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.math.BigDecimal;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.util.DecimalUtility;
+import org.apache.arrow.vector.validate.ValidateUtil.ValidateException;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+public class TestDecimalPrecisionBoundary {
+ @ParameterizedTest
+ @ValueSource(ints = {128, 256})
+ public void testValidateScalarsAtDeclaredPrecision(int bitWidth) {
+ try (BufferAllocator allocator = new RootAllocator();
+ BaseFixedWidthVector vector =
+ bitWidth == 128
+ ? new DecimalVector("decimal", allocator, 5, 2)
+ : new Decimal256Vector("decimal", allocator, 5, 2)) {
+ vector.allocateNew(2);
+ DecimalUtility.writeBigDecimalToArrowBuf(
+ new BigDecimal("999.99"), vector.getDataBuffer(), 0, bitWidth / 8);
+ DecimalUtility.writeBigDecimalToArrowBuf(
+ new BigDecimal("-999.99"), vector.getDataBuffer(), 1, bitWidth / 8);
+ vector.setIndexDefined(0);
+ vector.setIndexDefined(1);
+ vector.setValueCount(2);
+ vector.validateScalars();
+ // Values beyond the declared precision must still be rejected.
+ DecimalUtility.writeBigDecimalToArrowBuf(
+ new BigDecimal("1000.00"), vector.getDataBuffer(), 0, bitWidth / 8);
+ assertThrows(ValidateException.class, vector::validateScalars);
+ }
+ }
+}