apache/iceberg · error · UnsupportedOperationException

Spark does not support time fields

Error message

Spark does not support time fields

What it means

TypeToSparkType converts Iceberg primitive types to Spark types. Iceberg supports a TIME primitive but Spark's type system has no time-of-day type, so conversion throws UnsupportedOperationException. This is a fundamental engine limitation, not a configuration error.

Source

Thrown at spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java:131

  }

  @Override
  public DataType primitive(Type.PrimitiveType primitive) {
    switch (primitive.typeId()) {
      case BOOLEAN:
        return BooleanType$.MODULE$;
      case INTEGER:
        return IntegerType$.MODULE$;
      case LONG:
        return LongType$.MODULE$;
      case FLOAT:
        return FloatType$.MODULE$;
      case DOUBLE:
        return DoubleType$.MODULE$;
      case DATE:
        return DateType$.MODULE$;
      case TIME:
        throw new UnsupportedOperationException("Spark does not support time fields");
      case TIMESTAMP:
        Types.TimestampType ts = (Types.TimestampType) primitive;
        if (ts.shouldAdjustToUTC()) {
          return TimestampType$.MODULE$;
        } else {
          return TimestampNTZType$.MODULE$;
        }
      case STRING:
        return StringType$.MODULE$;
      case UUID:
        // use String
        return StringType$.MODULE$;
      case FIXED:
        return BinaryType$.MODULE$;
      case BINARY:
        return BinaryType$.MODULE$;
      case DECIMAL:
        Types.DecimalType decimal = (Types.DecimalType) primitive;

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Remove or change the TIME column in the Iceberg schema to a supported type (e.g. store as long millis or timestamp)
  2. Avoid reading the TIME column (project it out of the scan/schema)
  3. Read the table with an engine that supports time type (e.g. Flink)

Example fix

// before
Types.NestedField.of(5, false, "event_time", Types.TimeType.get());
// after
Types.NestedField.of(5, false, "event_time", Types.TimestampType.withZone());
Defensive patterns

Strategy: try-catch

Validate before calling

boolean hasTime = table.schema().columns().stream().anyMatch(c -> c.type().typeId() == Types.TimeType.get().typeId());
if (hasTime) { throw new IllegalArgumentException("Table contains TIME columns, unsupported in Spark"); }

Type guard

boolean isTimeType(org.apache.iceberg.types.Type t) { return t.typeId() == org.apache.iceberg.types.Type.TypeID.TIME; }

Try / catch

try { Schema sparkSchema = SparkSchemaUtil.convert(table.schema()); } catch (UnsupportedOperationException e) { LOG.error("Schema has Spark-unsupported types: {}", e.getMessage()); /* drop or remap the offending column */ }

Prevention

When it happens

Trigger: Any operation that converts an Iceberg schema containing a Types.TimeType field to a Spark schema: DataFrame reads, spark.table scans, CTAS/RTAS planning, or schema conversion via SparkSchemaUtil.

Common situations: A table created outside Spark (e.g. Flink, Java API) contains a TIME column and a Spark job tries to read or write it.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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