apache/iceberg · error · IllegalArgumentException

Invalid precision:

Error message

Invalid precision: 

What it means

FlinkOrcWriters.decimals() mirrors the reader: precision <= 18 yields Decimal18Writer, 19-38 yields Decimal38Writer, and anything above 38 throws IllegalArgumentException 'Invalid precision: <p>'. ORC decimal writers in Iceberg's Flink integration cannot represent precision beyond 38, so the library fails fast instead of writing corrupt data.

Source

Thrown at flink/v2.2/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 Iceberg schema and Flink DDL
  2. Use DECIMAL(38, scale) as the maximum supported precision
  3. Validate user-supplied precision before calling decimals()

Example fix

// before
.writer(FlinkOrcWriters.decimals(40, 2)) // throws
// after
.writer(FlinkOrcWriters.decimals(38, 2))
Defensive patterns

Strategy: validation

Validate before calling

Preconditions.checkArgument(precision >= 1 && precision <= 38,
    "Decimal precision must be within [1, 38], got: " + precision);
OrcValueWriter<DecimalData> w = FlinkOrcWriters.decimals(precision, scale);

Try / catch

try {
  writer = FlinkOrcWriters.decimals(precision, scale);
} catch (IllegalArgumentException e) {
  logger.error("Decimal precision {} out of range for ORC write", precision, e);
  throw e;
}

Prevention

When it happens

Trigger: Calling FlinkOrcWriters.decimals(precision, scale) with precision > 38, usually from FlinkOrcWriters when writing an Iceberg DecimalType column with out-of-range precision.

Common situations: Flink DECIMAL type with precision above 38 declared in a sink DDL, an Iceberg schema edited to an invalid precision, or generic code that forwards user-supplied precision without bounds checking.

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