This is an automated email from the ASF dual-hosted git repository.
ffacs pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/main by this push:
new b11fa74cc ORC-2038: Improve error message in
TypeDescription.withPrecision()
b11fa74cc is described below
commit b11fa74ccc6c2b77b38fd4c446e19db6d4a2604a
Author: wgzhao <[email protected]>
AuthorDate: Mon Dec 22 14:28:48 2025 +0800
ORC-2038: Improve error message in TypeDescription.withPrecision()
### What changes were proposed in this pull request?
This PR improves the error message in the
`TypeDescription.withPrecision(int precision)` method. The previous error
message incorrectly stated `precision {value} is out of range 1 .. {scale}`
when the scale was greater than precision, which was misleading because it
suggested the scale value was the upper bound for precision.
The new error message clearly states: `the scale {scale} must be less than
or equal to precision {precision}`, which accurately describes the actual
constraint violation.
### Why are the changes needed?
The previous error message was confusing and misleading. When users
encountered a case where scale > precision (e.g., precision=5, scale=10), the
error message "precision 5 is out of range 1 .. 10" incorrectly suggested that
precision must be between 1 and 10, when the real issue was that scale (10)
cannot be greater than precision (5).
This improvement enhances the developer experience by providing a clear,
accurate error message that directly points to the actual problem, making it
easier to diagnose and fix the issue without needing to examine the source code.
### How was this patch tested?
The existing test suite should validate this change. The modification only
affects the error message text and does not change the validation logic itself.
The same conditions that trigger the exception will continue to do so, but with
a clearer message.
To verify the change manually:
1. Create a TypeDescription with decimal type
2. Set scale to a value (e.g., 10)
3. Attempt to set precision to a value less than scale (e.g., 5)
4. Verify the new error message is clear and accurate
### Was this patch authored or co-authored using generative AI tooling?
No
Try to address the issue #2430
Closes #2462 from wgzhao/improve_exception_message.
Lead-authored-by: wgzhao <[email protected]>
Co-authored-by: Steven Zhao <[email protected]>
Signed-off-by: ffacs <[email protected]>
---
java/core/src/java/org/apache/orc/TypeDescription.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/java/core/src/java/org/apache/orc/TypeDescription.java
b/java/core/src/java/org/apache/orc/TypeDescription.java
index c5ef48b04..9e130e81d 100644
--- a/java/core/src/java/org/apache/orc/TypeDescription.java
+++ b/java/core/src/java/org/apache/orc/TypeDescription.java
@@ -241,10 +241,14 @@ public class TypeDescription
public TypeDescription withPrecision(int precision) {
if (category != Category.DECIMAL) {
throw new IllegalArgumentException("precision is only allowed on
decimal"+
- " and not " + category.name);
- } else if (precision < 1 || precision > MAX_PRECISION || scale >
precision){
- throw new IllegalArgumentException("precision " + precision +
- " is out of range 1 .. " + scale);
+ " and not " + category.name);
+ } else if (precision < 1 || precision > MAX_PRECISION) {
+ throw new IllegalArgumentException(
+ "precision " + precision + " must be between 1 and " + MAX_PRECISION
+ );
+ } else if (scale > precision) {
+ throw new IllegalArgumentException("scale " + scale +
+ " must be less than or equal to precision " + precision);
}
this.precision = precision;
return this;