apache/iceberg · error · UnsupportedOperationException
Expected value to be date or timestamp: ${valueType.catalogS
Error message
Expected value to be date or timestamp: ${valueType.catalogString()} What it means
The days() SQL catalog function (year/month/day family — here DaysFunction) only accepts date or timestamp (incl. timestamp_ntz) values. Binding with any other value type throws UnsupportedOperationException including the actual type.
Source
Thrown at spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/functions/DaysFunction.java:46
import org.apache.spark.sql.types.TimestampType;
/**
* A Spark function implementation for the Iceberg day transform.
*
* <p>Example usage: {@code SELECT system.days('source_col')}.
*/
public class DaysFunction extends UnaryUnboundFunction {
@Override
protected BoundFunction doBind(DataType valueType) {
if (valueType instanceof DateType) {
return new DateToDaysFunction();
} else if (valueType instanceof TimestampType) {
return new TimestampToDaysFunction();
} else if (valueType instanceof TimestampNTZType) {
return new TimestampNtzToDaysFunction();
} else {
throw new UnsupportedOperationException(
"Expected value to be date or timestamp: " + valueType.catalogString());
}
}
@Override
public String description() {
return name()
+ "(col) - Call Iceberg's day transform\n"
+ " col :: source column (must be date or timestamp)";
}
@Override
public String name() {
return "days";
}
private abstract static class BaseToDaysFunction extends BaseScalarFunction<Integer> {
@OverrideView on GitHub (pinned to 86d9c8fc54)
Solutions
- Cast the value: system.days(CAST('2024-01-01' AS DATE)) or system.days(CAST(ts_str AS TIMESTAMP))
- Convert epoch numbers to a timestamp first (timestamp_millis(col)) before applying days()
- Use the matching function for the type (e.g. days for date/timestamp, not for strings)
Example fix
// before
spark.sql("SELECT system.days('2024-01-01')")
// after
spark.sql("SELECT system.days(CAST('2024-01-01' AS DATE))") Defensive patterns
Strategy: type-guard
Validate before calling
-- Cast non-temporal inputs first SELECT system.days(CAST(ts_str AS TIMESTAMP)) FROM tbl;
Type guard
boolean daysOk(DataType t) { return t instanceof DateType || t instanceof TimestampType || t instanceof TimestampNTZType; } Prevention
- Cast string datetimes explicitly before temporal transform functions
- Convert epoch numbers with timestamp_millis/timestamp_micros first
- Check column types with DESCRIBE before writing SQL
When it happens
Trigger: Calling system.days(ts) where ts is a string, long epoch, or other non-date/timestamp type.
Common situations: Passing string datetime literals ('2024-01-01') without a cast; passing epoch millis as bigint; mistakenly passing a date-typed column to hours() variant or vice versa.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Expected value to be timestamp: ${valueType.catalogString()}
- Expected value to be date or timestamp: ${valueType.catalogS
- Expected number of buckets to be tinyint, shortint or int
- Expected value to be date or timestamp: ${valueType.catalogS
- Expected value to be date or timestamp: ${valueType.catalogS
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/887b7863a9513f2d.
Report an issue: GitHub.