apache/iceberg · error · UnsupportedOperationException

Spark does not support time fields

Error message

Spark does not support time fields

What it means

Iceberg supports a TIME primitive type but Spark SQL has no corresponding time-of-day data type. TypeToSparkType (used when converting Iceberg schemas to Spark schemas for reads/writes) therefore throws UnsupportedOperationException when a schema contains a Types.TimeType field.

Source

Thrown at spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java:108

  }

  @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. Exclude or transform the TIME column before conversion: select all columns except the time field
  2. Cast/rewrite the time value as a string or as microseconds-since-midnight stored in a long/integer column
  3. Change the table schema to use TIMESTAMP or another Spark-compatible type

Example fix

// before
Dataset<Row> df = spark.read().load("tbl"); // fails on time_col
// after
Dataset<Row> df = spark.read().load("tbl").drop("time_col");
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

static boolean isSparkCompatible(Types.NestedField f) { return f.type().typeId() != Types.TimeType.get().typeId(); }

Try / catch

try { return TypeToSparkType.convert(schema); } catch (UnsupportedOperationException e) { throw new AnalysisException("Unsupported Iceberg type for Spark: " + e.getMessage(), e); }

Prevention

When it happens

Trigger: Reading or writing an Iceberg table whose schema contains a TIME-typed column via the Spark connector, e.g. spark.read().load("...") or a DataFrame write to an Iceberg table with a time field.

Common situations: Tables written by engines that do support TIME (e.g. Flink or custom writers) being consumed in Spark; schema evolved to add a time column; copying a schema from another catalog into Iceberg and querying it from Spark.

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