{"record":{"id":"4cf31b3a3ce31bab","repo":"prestodb/presto","slug":"cannot-unnest-type","errorCode":null,"errorMessage":"Cannot unnest type: ","messagePattern":"Cannot unnest type: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/unnest/UnnestOperator.java","lineNumber":226,"sourceCode":"    }\n\n    private static Unnester createUnnester(Type nestedType, boolean isLegacyUnnest)\n    {\n        if (nestedType instanceof ArrayType) {\n            Type elementType = ((ArrayType) nestedType).getElementType();\n\n            if (!isLegacyUnnest && elementType instanceof RowType) {\n                return new ArrayOfRowsUnnester(elementType.getTypeParameters().size());\n            }\n            else {\n                return new ArrayUnnester();\n            }\n        }\n        else if (nestedType instanceof MapType) {\n            return new MapUnnester();\n        }\n        else {\n            throw new IllegalArgumentException(\"Cannot unnest type: \" + nestedType);\n        }\n    }\n\n    private void resetBlockBuilders()\n    {\n        for (int i = 0; i < replicateTypes.size(); i++) {\n            Block newInputBlock = currentPage.getBlock(replicateChannels.get(i));\n            replicatedBlockBuilders.get(i).resetInputBlock(newInputBlock);\n        }\n\n        int positionCount = currentPage.getPositionCount();\n        maxLengths = ensureCapacity(maxLengths, positionCount, SMALL, INITIALIZE);\n\n        for (int i = 0; i < unnestTypes.size(); i++) {\n            int inputChannel = unnestChannels.get(i);\n            Block unnestChannelInputBlock = currentPage.getBlock(inputChannel);\n            Unnester unnester = unnesters.get(i);\n","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/unnest/UnnestOperator.java#L208-L244","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nUnnestOperator with nestedType = VARCHAR (scalar)\n// after\nWrap scalar in an array in SQL: SELECT ... FROM t CROSS JOIN UNNEST(ARRAY[scalar_col]) AS u(x)","handlingStrategy":"try-catch","validationCode":"-- only unnest supported types in SQL; wrap scalars:\nSELECT ... FROM t CROSS JOIN UNNEST(ARRAY[scalar_col]) AS u(x)","typeGuard":null,"tryCatchPattern":"try {\n    runUnnestQuery();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Cannot unnest type:\")) {\n        throw new QueryValidationError(\"Column passed to UNNEST must be array, map, or row type\");\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["unnest","internal-error","type-system"],"backgroundTag":"unsupported-type-unnest","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}