orc icon indicating copy to clipboard operation
orc copied to clipboard

Incorrect error message in TypeDescription.withPrecision: misleading "precision X is out of range 1 .. Y" when scale > precision

Open wgzhao opened this issue 5 months ago • 0 comments

Hi,
I encountered a confusing error message when using ORC decimal types in CDH 6.2. Here is the log:

2025-09-30 10:24:41.701 [       job-0] ERROR Engine               - com.wgzhao.addax.core.exception.AddaxException: java.lang.IllegalArgumentException: precision 5 is out of range 1 .. 10
        at org.apache.orc.TypeDescription.withPrecision(TypeDescription.java:219)
        at com.wgzhao.addax.plugin.writer.hdfswriter.OrcWriter.buildOrcSchema(OrcWriter.java:344)
        at com.wgzhao.addax.plugin.writer.hdfswriter.OrcWriter.write(OrcWriter.java:294)
        at com.wgzhao.addax.plugin.writer.hdfswriter.HdfsWriter$Task.startWrite(HdfsWriter.java:473)
        at com.wgzhao.addax.core.taskgroup.runner.WriterRunner.run(WriterRunner.java:74)
        at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.IllegalArgumentException: precision 5 is out of range 1 .. 10
        at org.apache.orc.TypeDescription.withPrecision(TypeDescription.java:219)
        ...

After checking the source code, I found that in TypeDescription.withPrecision(int precision), the exception message is constructed as:

throw new IllegalArgumentException("precision " + precision + " is out of range 1 .. " + this.scale);

This is misleading, because this.scale is not the upper bound for precision. In my case, precision=5 and scale=10 (default), so the error message says "precision 5 is out of range 1 .. 10", which is not correct. The real problem is that scale cannot be greater than precision.

Expected behavior:
The error message should clearly indicate the actual constraint, e.g.

  • "precision must be between 1 and 38, and scale must be less than or equal to precision"
  • Or, if the check fails because scale > precision, the message should reflect that.

Suggestion:
Update the exception message in withPrecision to avoid using this.scale as the upper bound, and clarify the real constraint.

Environment:

  • ORC 1.9.5
  • Java 17

Thanks!

wgzhao avatar Sep 30 '25 02:09 wgzhao