apache/iceberg · error · UnsupportedOperationException

Cannot serialize unsupported view representation: %s

Error message

Cannot serialize unsupported view representation: %s

What it means

ViewRepresentationParser.toJson only knows how to serialize SQL view representations. If a ViewRepresentation has any other type (e.g. a future or custom dialect type), serialization throws UnsupportedOperationException — the parser version predates the representation type.

Source

Thrown at core/src/main/java/org/apache/iceberg/view/ViewRepresentationParser.java:42

import java.util.Locale;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.util.JsonUtil;

class ViewRepresentationParser {
  static final String TYPE = "type";

  private ViewRepresentationParser() {}

  static void toJson(ViewRepresentation representation, JsonGenerator generator)
      throws IOException {
    Preconditions.checkArgument(representation != null, "Invalid view representation: null");
    switch (representation.type().toLowerCase(Locale.ROOT)) {
      case ViewRepresentation.Type.SQL:
        SQLViewRepresentationParser.toJson((SQLViewRepresentation) representation, generator);
        break;

      default:
        throw new UnsupportedOperationException(
            String.format(
                "Cannot serialize unsupported view representation: %s", representation.type()));
    }
  }

  static String toJson(ViewRepresentation entry) {
    return JsonUtil.generate(gen -> toJson(entry, gen), false);
  }

  static ViewRepresentation fromJson(String json) {
    return JsonUtil.parse(json, ViewRepresentationParser::fromJson);
  }

  static ViewRepresentation fromJson(JsonNode node) {
    Preconditions.checkArgument(node != null, "Cannot parse view representation from null object");
    Preconditions.checkArgument(
        node.isObject(), "Cannot parse view representation from non-object: %s", node);
    String type = JsonUtil.getString(TYPE, node).toLowerCase(Locale.ROOT);

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Upgrade Iceberg to a version whose parser supports the representation type
  2. Inspect the view metadata JSON to identify the unknown representation type
  3. Remove or rewrite the unsupported representation if possible
  4. Report/patch the parser if a custom representation type must round-trip

Example fix

// before
String json = ViewRepresentationParser.toJson(representation, generator);
// after
if (!"sql".equalsIgnoreCase(representation.type())) {
  throw new UnsupportedOperationException("Unsupported type: " + representation.type());
}
ViewRepresentationParser.toJson(representation, generator);
Defensive patterns

Strategy: try-catch

Validate before calling

boolean supported = "sql".equalsIgnoreCase(representation.type());

Type guard

if (!(representation instanceof SQLViewRepresentation)) { throw new UnsupportedOperationException("only SQL representations supported"); }

Try / catch

try { parser.toJson(rep, gen); } catch (UnsupportedOperationException e) { // upgrade parser or skip unsupported representation }

Prevention

When it happens

Trigger: Serializing a ViewRepresentation whose type() is not "sql" — typically a view metadata file produced by a newer Iceberg version or an extension adding a non-SQL representation.

Common situations: Downgraded Iceberg version reading metadata written by a newer release; custom view representations from vendor extensions; corrupted type strings that fail the lowercase SQL match.

Related errors


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