Skip to content

Commit ad5e7cf

Browse files
wgzhaoffacs
authored andcommitted
ORC-2430: 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 <wgzhao@gmail.com> Co-authored-by: Steven Zhao <wgzhao@gmail.com> Signed-off-by: ffacs <ffacs520@gmail.com>
1 parent 80b17fd commit ad5e7cf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

java/core/src/java/org/apache/orc/TypeDescription.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,14 @@ public static TypeDescription fromString(String typeName) {
241241
public TypeDescription withPrecision(int precision) {
242242
if (category != Category.DECIMAL) {
243243
throw new IllegalArgumentException("precision is only allowed on decimal"+
244-
" and not " + category.name);
245-
} else if (precision < 1 || precision > MAX_PRECISION || scale > precision){
246-
throw new IllegalArgumentException("precision " + precision +
247-
" is out of range 1 .. " + scale);
244+
" and not " + category.name);
245+
} else if (precision < 1 || precision > MAX_PRECISION) {
246+
throw new IllegalArgumentException(
247+
"precision " + precision + " must be between 1 and " + MAX_PRECISION
248+
);
249+
} else if (scale > precision) {
250+
throw new IllegalArgumentException("scale " + scale +
251+
" must be less than or equal to precision " + precision);
248252
}
249253
this.precision = precision;
250254
return this;

0 commit comments

Comments
 (0)