{"record":{"id":"ed3b227e97c81215","repo":"prestodb/presto","slug":"flat-map-reader-does-not-support-nesting","errorCode":null,"errorMessage":"Flat map reader does not support nesting ","messagePattern":"Flat map reader does not support nesting ","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/reader/MapSelectiveStreamReader.java","lineNumber":89,"sourceCode":"            // When sequence id is not DEFAULT_SEQUENCE_ID, this map is inside a flat map.\n            // Flat maps can't be nested within another flat map.\n            flatReader = null;\n        }\n    }\n\n    @Override\n    public void startStripe(ZoneId timezone, Stripe stripe)\n            throws IOException\n    {\n        ColumnEncodingKind kind = stripe.getColumnEncodings().get(streamDescriptor.getStreamId())\n                .getColumnEncoding(streamDescriptor.getSequence())\n                .getColumnEncodingKind();\n        if (kind == DIRECT || kind == DIRECT_V2 || kind == DWRF_DIRECT) {\n            currentReader = directReader;\n        }\n        else if (kind == DWRF_MAP_FLAT) {\n            if (flatReader == null) {\n                throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), \"Flat map reader does not support nesting \" + streamDescriptor);\n            }\n            currentReader = flatReader;\n        }\n        else {\n            throw new IllegalArgumentException(\"Unsupported encoding \" + kind);\n        }\n\n        currentReader.startStripe(timezone, stripe);\n    }\n\n    @Override\n    public void startRowGroup(InputStreamSources dataStreamSources)\n            throws IOException\n    {\n        currentReader.startRowGroup(dataStreamSources);\n    }\n\n    @Override","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/reader/MapSelectiveStreamReader.java#L71-L107","documentation":"MapSelectiveStreamReader.startStripe dispatches to a direct or flat reader based on the stripe's column encoding. A DWRF_MAP_FLAT encoding requires a flat reader to have been created; if flatReader is null (e.g., flat map encountered in a nested context that wasn't set up), it throws OrcCorruptionException. Flat map readers cannot be instantiated for nested positions.","triggerScenarios":"A stripe whose map column encoding kind is DWRF_MAP_FLAT but the reader was constructed without a flat reader (flat maps not supported at nested/inner levels of a schema).","commonSituations":"Reading a file where flat-map encoding is applied to nested maps (map inside map/struct/array); writer emitted flat encoding where only direct is legal for nested columns.","solutions":["Rewrite the file so nested maps use DIRECT/DWRF_DIRECT encoding","Read the top-level map without the nested subfield pruning that creates nested readers","Upgrade Presto so flat-map nesting is supported or rejected earlier with a clearer message","Validate file encoding with a metadata scan before query"],"exampleFix":"// before: throw at runtime\nif (flatReader == null) { throw new OrcCorruptionException(...); }\n// after: reject at construction\ncheckState(encodingKind != DWRF_MAP_FLAT || supportsFlat, \"DWRF_MAP_FLAT not supported for nested stream: %s\", streamDescriptor);","handlingStrategy":"validation","validationCode":"if (encodingKind == ColumnEncodingKind.DWRF_MAP_FLAT && isNested) { throw new IllegalArgumentException(\"DWRF_MAP_FLAT is not supported for nested map columns\"); }","typeGuard":"null","tryCatchPattern":"try { reader.startStripe(timezone, stripe); } catch (OrcCorruptionException e) { if (e.getMessage().contains(\"Flat map reader does not support nesting\")) { throw new UnsupportedFileFormatException(e); } throw e; }","preventionTips":["Do not enable flat-map encoding for nested maps at write time","Scan stripe column encodings before querying files with nested maps","Prefer DIRECT/DWRF_DIRECT for map-in-map/map-in-struct schemas","Keep writer/reader versions aligned on flat-map nesting rules"],"tags":["orc","dwrf","flat-map","nested-schema","corruption"],"backgroundTag":"unsupported-orc-encoding","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"}