{"record":{"id":"bf75b9fecde11aa3","repo":"prestodb/presto","slug":"hive-invalid-metadata-bf75b9","errorCode":"HIVE_INVALID_METADATA","errorMessage":"Table '%s' is flattened, but flat map writer is not enabled for this session.","messagePattern":"Table '(.+?)' is flattened, but flat map writer is not enabled for this session\\.","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/OrcFileWriterFactory.java","lineNumber":408,"sourceCode":"    }\n\n    private Set<Integer> getFlattenedColumns(Properties schema, ConnectorSession session)\n    {\n        boolean flatMapsEnabled = parseBoolean(schema.getProperty(ORC_FLAT_MAP_WRITER_ENABLED_KEY, \"false\"));\n        ImmutableSet.Builder<Integer> flattenedColumnsBuilder = ImmutableSet.builder();\n        if (flatMapsEnabled) {\n            String columnsValue = schema.getProperty(ORC_FLAT_MAP_COLUMN_NUMBERS_KEY, \"\");\n            FLAT_MAP_COLUMN_NUMBERS_SPLITTER.splitToList(columnsValue).stream()\n                    .map(Integer::valueOf)\n                    .forEach(flattenedColumnsBuilder::add);\n        }\n        Set<Integer> flattenedColumns = flattenedColumnsBuilder.build();\n\n        // fail if flat maps are enabled for the table, but flat map writer is not enabled in the session\n        boolean flatMapWriterEnabled = isFlatMapWriterEnabled(session);\n        if (!flattenedColumns.isEmpty() && !flatMapWriterEnabled) {\n            String tableName = schema.getProperty(META_TABLE_NAME);\n            throw new PrestoException(\n                    HIVE_INVALID_METADATA,\n                    format(\"Table '%s' is flattened, but flat map writer is not enabled for this session.\", tableName));\n        }\n\n        return flattenedColumns;\n    }\n\n    private boolean isMapStatisticsEnabled(Properties schema)\n    {\n        return parseBoolean(schema.getProperty(ORC_MAP_STATISTICS_KEY, \"false\"));\n    }\n\n    private int getFlatMapKeyLimit(Properties properties)\n    {\n        String defaultValue = Integer.toString(DEFAULT_MAX_FLATTENED_MAP_KEY_COUNT);\n        String value = properties.getProperty(ORC_FLAT_MAP_KEY_LIMIT_KEY, defaultValue).trim();\n        return Integer.parseInt(value);\n    }","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/OrcFileWriterFactory.java#L390-L426","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["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).","Ensure the client/BI tool or scheduler that runs the INSERT sets that session property.","If flat maps are not actually needed, rewrite the table without flat map (flattened) column configuration.","Verify the table's flattened column metadata is intentional and matches the writer capability of your Presto version."],"exampleFix":"// before\nINSERT INTO hive.flat_map_table SELECT * FROM src;\n// after\nSET SESSION hive.orc_flat_map_writer_enabled = true;\nINSERT INTO hive.flat_map_table SELECT * FROM src;","handlingStrategy":"validation","validationCode":"// Before writing to a table known to use flat maps, set the session property:\nSET SESSION hive.orc_flat_map_writer_enabled = true;","typeGuard":null,"tryCatchPattern":"try {\n    insertFuture = prestoExecutor.submit(insert);\n} catch (PrestoException e) {\n    if (e.getErrorCode() == StandardErrorCode.INVALID_METADATA.toErrorCode().getId()) {\n        // enable flat map writer session property and retry once\n    }\n}","preventionTips":["Enable the flat map writer session property in every session/tool that writes to flat-map tables.","Configure BI tools and schedulers to pass the required session properties.","Keep table flat-map settings in sync with the writer capabilities of your Presto build."],"tags":["hive","orc","flat-map","session-property","metadata"],"backgroundTag":"flat-map-writer-disabled","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"}