apache/iceberg · error · IllegalArgumentException

Invalid precision:

Error message

Invalid precision: 

What it means

GenericOrcWriters.decimal(precision, scale) only supports BigDecimal precision up to 38 (18 -> long-backed writer, 38 -> second writer). A precision above 38 cannot be represented by the ORC decimal writers, so IllegalArgumentException("Invalid precision: N") is thrown.

Source

Thrown at orc/src/main/java/org/apache/iceberg/data/orc/GenericOrcWriters.java:146

  public static OrcValueWriter<LocalDateTime> timestamp() {
    return TimestampWriter.INSTANCE;
  }

  public static OrcValueWriter<OffsetDateTime> timestampTzNanos() {
    return TimestampTzNanoWriter.INSTANCE;
  }

  public static OrcValueWriter<LocalDateTime> timestampNanos() {
    return TimestampNanoWriter.INSTANCE;
  }

  public static OrcValueWriter<BigDecimal> decimal(int precision, int scale) {
    if (precision <= 18) {
      return new Decimal18Writer(precision, scale);
    } else if (precision <= 38) {
      return new Decimal38Writer(precision, scale);
    } else {
      throw new IllegalArgumentException("Invalid precision: " + precision);
    }
  }

  public static OrcValueWriter<Variant> variants() {
    return VariantWriter.INSTANCE;
  }

  public static <T> OrcValueWriter<List<T>> list(OrcValueWriter<T> element) {
    return new ListWriter<>(element);
  }

  public static <K, V> OrcValueWriter<Map<K, V>> map(
      OrcValueWriter<K> key, OrcValueWriter<V> value) {
    return new MapWriter<>(key, value);
  }

  public static <T> OrcRowWriter<PositionDelete<T>> positionDelete(
      OrcRowWriter<T> writer, Function<CharSequence, ?> pathTransformFunc) {

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Reduce the column precision to <= 38 in the table schema.
  2. Use STRING (or DOUBLE) if you truly need more range/precision.
  3. Validate schema precision before creating ORC tables.
  4. Fix the DDL/source that generated the oversized decimal type.

Example fix

// before
Types.DecimalType.of(50, 10) // precision 50 > 38 -> IllegalArgumentException
// after
Types.DecimalType.of(38, 10) // max supported precision
Defensive patterns

Strategy: validation

Validate before calling

// check precision before creating/writing
Types.DecimalType dt = (Types.DecimalType) type;
if (dt.precision() > 38) throw new IllegalArgumentException("ORC decimal precision must be <= 38, got " + dt.precision());

Type guard

boolean decimalSupported = t instanceof Types.DecimalType && ((Types.DecimalType) t).precision() <= 38;

Try / catch

try { write(...); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Invalid precision")) { /* fix schema to precision<=38 */ } throw e; }

Prevention

When it happens

Trigger: Creating/writing an Iceberg ORC table whose decimal column declares precision > 38.

Common situations: Hand-written schemas with overly large decimal precision; DDL copied from other engines allowing bigger precision; misconfigured type conversion.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/6a8dfbf856285ab5. Report an issue: GitHub.