{"record":{"id":"e434958ec106039f","repo":"apache/iceberg","slug":"unsupported-type-interval-e43495","errorCode":null,"errorMessage":"Unsupported type: interval","messagePattern":"Unsupported type: interval","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java","lineNumber":206,"sourceCode":"  }\n\n  private byte[] getBinaryInternal(int ordinal) {\n    Object bytes = struct.get(ordinal, Object.class);\n\n    // should only be either ByteBuffer or byte[]\n    if (bytes instanceof ByteBuffer) {\n      return ByteBuffers.toByteArray((ByteBuffer) bytes);\n    } else if (bytes instanceof byte[]) {\n      return (byte[]) bytes;\n    } else {\n      throw new IllegalStateException(\n          \"Unknown type for binary field. Type name: \" + bytes.getClass().getName());\n    }\n  }\n\n  @Override\n  public CalendarInterval getInterval(int ordinal) {\n    throw new UnsupportedOperationException(\"Unsupported type: interval\");\n  }\n\n  @Override\n  public InternalRow getStruct(int ordinal, int numFields) {\n    return isNullAt(ordinal) ? null : getStructInternal(ordinal);\n  }\n\n  private InternalRow getStructInternal(int ordinal) {\n    return new StructInternalRow(\n        type.fields().get(ordinal).type().asStructType(), struct.get(ordinal, StructLike.class));\n  }\n\n  @Override\n  public ArrayData getArray(int ordinal) {\n    return isNullAt(ordinal) ? null : getArrayInternal(ordinal);\n  }\n\n  private ArrayData getArrayInternal(int ordinal) {","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java#L188-L224","documentation":"Iceberg's StructInternalRow does not support Spark's CalendarInterval type; getInterval unconditionally throws UnsupportedOperationException. The Iceberg type system has no interval type, so interval values cannot be represented in an Iceberg-backed InternalRow.","triggerScenarios":"Calling getInterval(ordinal) on a StructInternalRow — e.g. a Spark query materializing an interval-typed field against an Iceberg table, or attempting to write computed CalendarInterval columns into an Iceberg table.","commonSituations":"Queries that add interval columns (e.g. via expr(\"interval 3 days\") or date arithmetic) and then write to Iceberg; schema evolution or views introducing interval columns over Iceberg sources; UDFs returning intervals read through the Iceberg scan path.","solutions":["Remove or transform interval columns before they reach Iceberg — intervals are not part of the Iceberg spec.","Convert the interval to a supported type, e.g. store the amount as an integer/long (days, months, or seconds).","Cast derived intervals upstream to a duration representation before reading/writing via Iceberg.","Do not attempt catch-and-recover: the type is fundamentally unsupported for Iceberg rows."],"exampleFix":"// before\ndf.withColumn(\"iv\", expr(\"interval 3 days\")).writeTo(table).create();\n// after\ndf.withColumn(\"interval_days\", lit(3)).writeTo(table).create();","handlingStrategy":"validation","validationCode":"for (StructField f : df.schema().fields()) {\n  if (f.dataType() instanceof CalendarIntervalType) {\n    throw new IllegalArgumentException(\"Iceberg does not support interval column: \" + f.name());\n  }\n}","typeGuard":"static boolean isIntervalColumn(StructField f) {\n  return f.dataType() instanceof CalendarIntervalType;\n}","tryCatchPattern":"try {\n  df.writeTo(table).create();\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"interval\")) {\n    // drop/transform the interval column and retry\n  } else throw e;\n}","preventionTips":["Never persist CalendarInterval columns into Iceberg tables; use numeric durations.","Validate DataFrames against the Iceberg-supported schema before writeTo/load.","Pin shared ETL schemas to Iceberg-spec-supported types."],"tags":["spark","unsupported-type","interval","iceberg-spec"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}