apache/iceberg · error

apply(value) is deprecated, use bind(Type).apply(value)

Error message

apply(value) is deprecated, use bind(Type).apply(value)

What it means

Truncate explicitly overrides the deprecated Transform.apply(value) to throw UnsupportedOperationException with the migration message. Like all transforms, Truncate must be bound to a concrete type via bind(Type) so the correct truncation function (int, long, decimal, string, or ByteBuffer) is selected; the unbound apply() cannot know how to truncate.

Source

Thrown at api/src/main/java/org/apache/iceberg/transforms/Truncate.java:83

      default:
        throw new UnsupportedOperationException("Cannot truncate type: " + type);
    }
  }

  @SuppressWarnings("checkstyle:VisibilityModifier")
  protected final int width;

  Truncate(int width) {
    this.width = width;
  }

  public Integer width() {
    return width;
  }

  @Override
  public T apply(T value) {
    throw new UnsupportedOperationException(
        "apply(value) is deprecated, use bind(Type).apply(value)");
  }

  @Override
  public SerializableFunction<T, T> bind(Type type) {
    Preconditions.checkArgument(canTransform(type), "Cannot bind to unsupported type: %s", type);
    return (SerializableFunction<T, T>) get(type, width);
  }

  @Override
  public boolean canTransform(Type type) {
    switch (type.typeId()) {
      case INTEGER:
      case LONG:
      case STRING:
      case BINARY:
      case DECIMAL:
        return true;

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Replace apply(value) with bind(type).apply(value), where type is the column's Iceberg Type
  2. Use canTransform(type) to verify the type is truncatable before binding
  3. Audit and update deprecated Transform.apply call sites when upgrading Iceberg

Example fix

// before
Integer truncated = Truncate.of(10).apply(value);
// after
Integer truncated = Truncate.of(10).bind(IntegerType.get()).apply(value);
Defensive patterns

Strategy: type-guard

Validate before calling

// migrate: use the bound function
SerializableFunction<Integer, Integer> fn = Truncate.of(10).bind(IntegerType.get());
Integer truncated = fn.apply(value);

Type guard

static <S, T> SerializableFunction<S, T> boundFn(Transform<S, T> t, Type type) { return t.bind(type); }

Try / catch

try { return truncate.bind(type).apply(value); } catch (UnsupportedOperationException e) { throw new IllegalStateException("Deprecated unbound Truncate.apply used; bind first", e); }

Prevention

When it happens

Trigger: Directly calling Truncate.of(width).apply(value) instead of Truncate.of(width).bind(type).apply(value) — e.g. legacy partitioning code or the testDeprecatedTruncateInteger path.

Common situations: Code written before the bind() API that was upgraded; examples/tutorial code using the deprecated unbound call on truncate transforms.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


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