prestodb/presto · error · OrcCorruptionException
Flat map reader does not support nesting
Error message
Flat map reader does not support nesting
What it means
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.
Source
Thrown at presto-orc/src/main/java/com/facebook/presto/orc/reader/MapSelectiveStreamReader.java:89
// When sequence id is not DEFAULT_SEQUENCE_ID, this map is inside a flat map.
// Flat maps can't be nested within another flat map.
flatReader = null;
}
}
@Override
public void startStripe(ZoneId timezone, Stripe stripe)
throws IOException
{
ColumnEncodingKind kind = stripe.getColumnEncodings().get(streamDescriptor.getStreamId())
.getColumnEncoding(streamDescriptor.getSequence())
.getColumnEncodingKind();
if (kind == DIRECT || kind == DIRECT_V2 || kind == DWRF_DIRECT) {
currentReader = directReader;
}
else if (kind == DWRF_MAP_FLAT) {
if (flatReader == null) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Flat map reader does not support nesting " + streamDescriptor);
}
currentReader = flatReader;
}
else {
throw new IllegalArgumentException("Unsupported encoding " + kind);
}
currentReader.startStripe(timezone, stripe);
}
@Override
public void startRowGroup(InputStreamSources dataStreamSources)
throws IOException
{
currentReader.startRowGroup(dataStreamSources);
}
@OverrideView on GitHub (pinned to 55bb57d202)
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
Example fix
// before: throw at runtime
if (flatReader == null) { throw new OrcCorruptionException(...); }
// after: reject at construction
checkState(encodingKind != DWRF_MAP_FLAT || supportsFlat, "DWRF_MAP_FLAT not supported for nested stream: %s", streamDescriptor); Defensive patterns
Strategy: validation
Validate before calling
if (encodingKind == ColumnEncodingKind.DWRF_MAP_FLAT && isNested) { throw new IllegalArgumentException("DWRF_MAP_FLAT is not supported for nested map columns"); } Type guard
null
Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Stripe encryption keys are missing, but file is encrypted
- Number of stripe encryption keys did not match number of enc
- Unsupported flat map key type:
- HIVE_INVALID_METADATA
- HIVE_CURSOR_ERROR
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/ed3b227e97c81215.
Report an issue: GitHub.