apache/iceberg · error · IllegalArgumentException

Invalid precision: {precision}

Error message

Invalid precision: {precision}

What it means

SparkOrcValueReaders.decimals(precision, scale) selects a Decimal18Reader or Decimal38Reader based on precision. Iceberg decimals are limited to precision <= 38; anything greater cannot be represented, so the factory throws IllegalArgumentException immediately rather than producing a corrupt reader.

Source

Thrown at spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcValueReaders.java:69

  public static OrcValueReader<UTF8String> utf8String() {
    return StringReader.INSTANCE;
  }

  public static OrcValueReader<UTF8String> uuids() {
    return UUIDReader.INSTANCE;
  }

  public static OrcValueReader<Long> timestampTzs() {
    return TimestampTzReader.INSTANCE;
  }

  public static OrcValueReader<Decimal> decimals(int precision, int scale) {
    if (precision <= Decimal.MAX_LONG_DIGITS()) {
      return new SparkOrcValueReaders.Decimal18Reader(precision, scale);
    } else if (precision <= 38) {
      return new SparkOrcValueReaders.Decimal38Reader(precision, scale);
    } else {
      throw new IllegalArgumentException("Invalid precision: " + precision);
    }
  }

  static OrcValueReader<?> struct(
      TypeDescription record,
      List<OrcValueReader<?>> readers,
      Types.StructType struct,
      Map<Integer, ?> idToConstant) {
    return new StructReader(record, readers, struct, idToConstant);
  }

  static OrcValueReader<?> array(OrcValueReader<?> elementReader) {
    return new ArrayReader(elementReader);
  }

  static OrcValueReader<?> map(OrcValueReader<?> keyReader, OrcValueReader<?> valueReader) {
    return new MapReader(keyReader, valueReader);
  }

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Fix the schema so decimal precision is <= 38 per the Iceberg spec
  2. Reduce precision (e.g. DECIMAL(38,x)) and rewrite the data
  3. Validate table schemas with Schema validation before writing ORC files
  4. Check the producing system for precision-scaling bugs

Example fix

// before
Types.DecimalType.of(40, 5)
// after
Types.DecimalType.of(38, 5)
Defensive patterns

Strategy: validation

Validate before calling

Types.DecimalType t = (Types.DecimalType) type;
if (t.precision() > 38) {
  throw new IllegalArgumentException("Decimal precision exceeds Iceberg max (38): " + t.precision());
}

Type guard

boolean isValidDecimal(Type t) {
  return t instanceof Types.DecimalType && ((Types.DecimalType) t).precision() <= 38;
}

Try / catch

try {
  OrcValueReader<?> r = SparkOrcValueReaders.decimals(precision, scale);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Invalid precision")) { /* fix schema precision */ }
  else throw e;
}

Prevention

When it happens

Trigger: Constructing an ORC reader/writer mapping for a decimal column whose precision exceeds 38, usually from a schema that violates the Iceberg spec (max precision 38).

Common situations: Tables created by non-Iceberg tools with oversized decimals; schema conversion bugs; spec-violating metadata injected into ORC files.

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/6aca12f58a314720. Report an issue: GitHub.