apache/iceberg · error · java.lang.IllegalArgumentException

Invalid precision: %s

Error message

Invalid precision: %s

What it means

FlinkOrcWriters.decimals() throws IllegalArgumentException 'Invalid precision: <p>' when writing an ORC decimal with precision > 38; only precision <= 18 and <= 38 writers exist, matching Iceberg's decimal limit.

Source

Thrown at flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/FlinkOrcWriters.java:87

  static OrcValueWriter<TimestampData> timestampTzs() {
    return TimestampTzWriter.INSTANCE;
  }

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

  static OrcValueWriter<TimestampData> timestampNanoTzs() {
    return TimestampNanoTzWriter.INSTANCE;
  }

  static OrcValueWriter<DecimalData> decimals(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);
    }
  }

  static <T> OrcValueWriter<ArrayData> list(
      OrcValueWriter<T> elementWriter, LogicalType elementType) {
    return new ListWriter<>(elementWriter, elementType);
  }

  static <K, V> OrcValueWriter<MapData> map(
      OrcValueWriter<K> keyWriter,
      OrcValueWriter<V> valueWriter,
      LogicalType keyType,
      LogicalType valueType) {
    return new MapWriter<>(keyWriter, valueWriter, keyType, valueType);
  }

  static OrcValueWriter<RowData> struct(List<OrcValueWriter<?>> writers, List<LogicalType> types) {
    int[] fieldIndexes = new int[writers.size()];

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Reduce the column precision to <= 38 in the schema.
  2. Validate decimal precision before writing (Precision/scale <= 38).
  3. Convert the column to string/bytes if wider precision must be preserved.

Example fix

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

Strategy: validation

Validate before calling

Types.DecimalType dt = (Types.DecimalType) fieldType;
Preconditions.checkArgument(dt.precision() <= 38,
    "ORC writer supports decimal precision <= 38, got %s", dt.precision());

Type guard

boolean writableDecimal(Types.DecimalType t) {
  return t.precision() <= 38;
}

Try / catch

try {
  writer.write(decimalData, ordinal);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Invalid precision")) {
    throw new IllegalStateException("Cannot write decimal with precision > 38: " + e.getMessage());
  }
  throw e;
}

Prevention

When it happens

Trigger: Writing ORC data for a DECIMAL column with declared precision above 38 (e.g. decimal(40, 2)).

Common situations: Schemas created programmatically with invalid precision; data from external engines allowing wider decimals.

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/16ca0d7f0a25b9f9. Report an issue: GitHub.