prestodb/presto · error · IllegalArgumentException
Cannot unnest type:
Error message
Cannot unnest type:
What it means
UNNEST expands arrays, maps, and rows into separate columns/rows. During operator setup, createUnnester maps each nested column type to an Unnester implementation; only ArrayType, MapType, and RowType are supported. Any other type reaching this switch is a planner bug or misuse and throws IllegalArgumentException.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/unnest/UnnestOperator.java:226
}
private static Unnester createUnnester(Type nestedType, boolean isLegacyUnnest)
{
if (nestedType instanceof ArrayType) {
Type elementType = ((ArrayType) nestedType).getElementType();
if (!isLegacyUnnest && elementType instanceof RowType) {
return new ArrayOfRowsUnnester(elementType.getTypeParameters().size());
}
else {
return new ArrayUnnester();
}
}
else if (nestedType instanceof MapType) {
return new MapUnnester();
}
else {
throw new IllegalArgumentException("Cannot unnest type: " + nestedType);
}
}
private void resetBlockBuilders()
{
for (int i = 0; i < replicateTypes.size(); i++) {
Block newInputBlock = currentPage.getBlock(replicateChannels.get(i));
replicatedBlockBuilders.get(i).resetInputBlock(newInputBlock);
}
int positionCount = currentPage.getPositionCount();
maxLengths = ensureCapacity(maxLengths, positionCount, SMALL, INITIALIZE);
for (int i = 0; i < unnestTypes.size(); i++) {
int inputChannel = unnestChannels.get(i);
Block unnestChannelInputBlock = currentPage.getBlock(inputChannel);
Unnester unnester = unnesters.get(i);
View on GitHub (pinned to 55bb57d202)
Solutions
- Check the query: only UNNEST array/map/row-typed columns; wrap scalars in an array first, e.g. UNNEST(ARRAY[col]).
- If triggered from custom operator construction, verify nestedType instanceof ArrayType || MapType || RowType before calling createUnnester.
- If reproducible with a plain query against stock types, report it as a planner bug with the query and EXPLAIN plan.
Example fix
// before UnnestOperator with nestedType = VARCHAR (scalar) // after Wrap scalar in an array in SQL: SELECT ... FROM t CROSS JOIN UNNEST(ARRAY[scalar_col]) AS u(x)
Defensive patterns
Strategy: try-catch
Validate before calling
-- only unnest supported types in SQL; wrap scalars: SELECT ... FROM t CROSS JOIN UNNEST(ARRAY[scalar_col]) AS u(x)
Try / catch
try {
runUnnestQuery();
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Cannot unnest type:")) {
throw new QueryValidationError("Column passed to UNNEST must be array, map, or row type");
}
throw e;
} Prevention
- Only UNNEST array, map, or row typed expressions.
- Inspect column types with DESCRIBE before unnesting dynamic inputs.
- If building plans programmatically, assert types before constructing UnnestOperator.
When it happens
Trigger: An UNNEST query where the replicated/unnested input column type is not an array, map, or row — typically caused by a type change in the plan that the planner failed to catch, or by custom code constructing an UnnestOperator directly with an unsupported type.
Common situations: Custom connectors/plugins feeding unexpected types into unnest; internal bugs after type-system changes; passing a scalar (e.g. VARCHAR) column to UNNEST through a plugin-generated plan.
Related errors
- Unsupported java type %s
- BIGQUERY_UNSUPPORTED_COLUMN_TYPE
- CLICKHOUSE_QUERY_GENERATOR_FAILURE
- CHAR length scale must be in range [0, %s]
- Enum definition expected, got %s
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/4cf31b3a3ce31bab.
Report an issue: GitHub.