prestodb/presto · error · BigQueryException

BIGQUERY_UNSUPPORTED_TYPE_FOR_LONG

BIGQUERY_UNSUPPORTED_TYPE_FOR_LONG

Error message

Unhandled type for %s: %s

What it means

This error is thrown by BigQueryResultPageSource.writeLong when converting an Avro value into a Presto column whose Type expects a long (e.g. BIGINT, timestamps), but the column's Presto type is none of the supported timestamp types handled above the throw. It indicates a mapping gap between BigQuery/Avro schema types and Presto types in the bigquery plugin.

Source

Thrown at presto-bigquery/src/main/java/com/facebook/presto/plugin/bigquery/BigQueryResultPageSource.java:212

    private void writeLong(Type type, Object value, BlockBuilder output, Class<?> javaType)
    {
        if (type.equals(BIGINT)) {
            type.writeLong(output, ((Number) value).longValue());
        }
        else if (type.equals(INTEGER)) {
            type.writeLong(output, ((Number) value).intValue());
        }
        else if (type.equals(DATE)) {
            type.writeLong(output, ((Number) value).intValue());
        }
        else if (type.equals(TIMESTAMP)) {
            type.writeLong(output, BigQueryType.toPrestoTimestamp(((org.apache.avro.util.Utf8) value).toString()));
        }
        else if (type.equals(TIME_WITH_TIME_ZONE) || type.equals(TIMESTAMP_WITH_TIME_ZONE)) {
            type.writeLong(output, DateTimeEncoding.packDateTimeWithZone(((Long) value).longValue() / 1000, TimeZoneKey.UTC_KEY));
        }
        else {
            throw new BigQueryException(BIGQUERY_UNSUPPORTED_TYPE_FOR_LONG, format("Unhandled type for %s: %s", javaType.getSimpleName(), type));
        }
    }

    private void writeSlice(BlockBuilder output, Type type, Object value)
    {
        if (type instanceof VarcharType) {
            type.writeSlice(output, utf8Slice(((Utf8) value).toString()));
        }
        else if (type instanceof DecimalType) {
            BigDecimal bdValue = DECIMAL_CONVERTER.convert(value);
            type.writeSlice(output, Decimals.encodeScaledValue(bdValue, NUMERIC_DATA_TYPE_SCALE));
        }
        else if (type instanceof VarbinaryType) {
            if (value instanceof ByteBuffer) {
                type.writeSlice(output, Slices.wrappedBuffer((ByteBuffer) value));
            }
            else {
                throw new BigQueryException(BIGQUERY_UNSUPPORTED_TYPE_FOR_VARBINARY, "Unhandled type for VarBinaryType: " + value.getClass());

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Inspect the Presto type and the Avro value class named in the message and add an explicit mapping branch in writeLong for that type
  2. Upgrade the presto-bigquery plugin to a version that supports the BigQuery type
  3. Cast or exclude the offending column in the query (e.g. CAST to a supported type or select only supported columns)
  4. File/track a plugin issue for the unsupported type combination

Example fix

// before
else {
    throw new BigQueryException(BIGQUERY_UNSUPPORTED_TYPE_FOR_LONG, format("Unhandled type for %s: %s", javaType.getSimpleName(), type));
}
// after
else if (type.equals(BIGINT)) {
    type.writeLong(output, ((Number) value).longValue());
}
else {
    throw new BigQueryException(BIGQUERY_UNSUPPORTED_TYPE_FOR_LONG, format("Unhandled type for %s: %s", javaType.getSimpleName(), type));
}
Defensive patterns

Strategy: type-guard

Validate before calling

// before querying, check column types against supported set
for (ColumnMetadata col : connectorTable.getColumns()) {
    Type t = col.getType();
    if (!(t.equals(TIME_WITH_TIME_ZONE) || t.equals(TIMESTAMP_WITH_TIME_ZONE) || t.equals(BIGINT))) {
        throw new IllegalStateException("Column " + col.getName() + " has unsupported type " + t);
    }
}

Type guard

boolean isSupportedLongType(Type type) {
    return type.equals(TIME_WITH_TIME_ZONE)
        || type.equals(TIMESTAMP_WITH_TIME_ZONE)
        || type.equals(BIGINT);
}

Try / catch

try {
    pageSource.getNextPage(...);
} catch (BigQueryException e) {
    if (e.getErrorCode().getCode() == BIGQUERY_UNSUPPORTED_TYPE_FOR_LONG.getCode()) {
        // fall back: cast column in SQL or drop it from the select list
    } else { throw e; }
}

Prevention

When it happens

Trigger: Reading BigQuery rows via a page source where appendTo dispatches to writeLong with a Presto type that is not TIME_WITH_TIME_ZONE, TIMESTAMP_WITH_TIME_ZONE (nor the other handled timestamp variants), e.g. an unexpected type signature reaching the long-writing branch.

Common situations: BigQuery schema changes adding column types not covered by the plugin's type mapping; custom/aliased timestamp types; plugin version older than a newly supported BigQuery type.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/a36e22146e053ee0. Report an issue: GitHub.