prestodb/presto · error · PrestoException

HIVE_INVALID_METADATA

HIVE_INVALID_METADATA

Error message

Table '%s' is flattened, but flat map writer is not enabled for this session.

What it means

ORC flat map support (writing map columns as flattened column groups) can be enabled on a table but requires the flat map writer to be enabled in the session via a session property. If Presto detects flattened columns for the table while the session-level flat map writer flag is off, writing would produce a file incompatible with the table's layout, so it fails with HIVE_INVALID_METADATA.

Source

Thrown at presto-hive/src/main/java/com/facebook/presto/hive/OrcFileWriterFactory.java:408

    }

    private Set<Integer> getFlattenedColumns(Properties schema, ConnectorSession session)
    {
        boolean flatMapsEnabled = parseBoolean(schema.getProperty(ORC_FLAT_MAP_WRITER_ENABLED_KEY, "false"));
        ImmutableSet.Builder<Integer> flattenedColumnsBuilder = ImmutableSet.builder();
        if (flatMapsEnabled) {
            String columnsValue = schema.getProperty(ORC_FLAT_MAP_COLUMN_NUMBERS_KEY, "");
            FLAT_MAP_COLUMN_NUMBERS_SPLITTER.splitToList(columnsValue).stream()
                    .map(Integer::valueOf)
                    .forEach(flattenedColumnsBuilder::add);
        }
        Set<Integer> flattenedColumns = flattenedColumnsBuilder.build();

        // fail if flat maps are enabled for the table, but flat map writer is not enabled in the session
        boolean flatMapWriterEnabled = isFlatMapWriterEnabled(session);
        if (!flattenedColumns.isEmpty() && !flatMapWriterEnabled) {
            String tableName = schema.getProperty(META_TABLE_NAME);
            throw new PrestoException(
                    HIVE_INVALID_METADATA,
                    format("Table '%s' is flattened, but flat map writer is not enabled for this session.", tableName));
        }

        return flattenedColumns;
    }

    private boolean isMapStatisticsEnabled(Properties schema)
    {
        return parseBoolean(schema.getProperty(ORC_MAP_STATISTICS_KEY, "false"));
    }

    private int getFlatMapKeyLimit(Properties properties)
    {
        String defaultValue = Integer.toString(DEFAULT_MAX_FLATTENED_MAP_KEY_COUNT);
        String value = properties.getProperty(ORC_FLAT_MAP_KEY_LIMIT_KEY, defaultValue).trim();
        return Integer.parseInt(value);
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Enable the flat map writer session property for the writing session (e.g. SET SESSION hive.orc_flat_map_writer_enabled = true; or the equivalent catalog property).
  2. Ensure the client/BI tool or scheduler that runs the INSERT sets that session property.
  3. If flat maps are not actually needed, rewrite the table without flat map (flattened) column configuration.
  4. Verify the table's flattened column metadata is intentional and matches the writer capability of your Presto version.

Example fix

// before
INSERT INTO hive.flat_map_table SELECT * FROM src;
// after
SET SESSION hive.orc_flat_map_writer_enabled = true;
INSERT INTO hive.flat_map_table SELECT * FROM src;
Defensive patterns

Strategy: validation

Validate before calling

// Before writing to a table known to use flat maps, set the session property:
SET SESSION hive.orc_flat_map_writer_enabled = true;

Try / catch

try {
    insertFuture = prestoExecutor.submit(insert);
} catch (PrestoException e) {
    if (e.getErrorCode() == StandardErrorCode.INVALID_METADATA.toErrorCode().getId()) {
        // enable flat map writer session property and retry once
    }
}

Prevention

When it happens

Trigger: INSERT/CREATE TABLE AS into a Hive table whose ORC schema contains flattened map columns while the session property enabling the flat map writer (e.g. hive.orc.flat-map.writer.enabled) is false (the default).

Common situations: Reading a flat-map-enabled table fine, then writing to it from a session/cluster where the flat map writer property was never enabled; running queries via BI tools or schedulers that open fresh sessions without the property; upgrading Presto where flat map properties exist on the table but session defaults changed.

Related errors


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