{"record":{"id":"e82f0f85e6eae836","repo":"prestodb/presto","slug":"hive-invalid-metadata-e82f0f","errorCode":"HIVE_INVALID_METADATA","errorMessage":"bucketed table %s should not specify preferred_ordering_columns","messagePattern":"bucketed table (.+?) should not specify preferred_ordering_columns","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java","lineNumber":759,"sourceCode":"                .map(Column::getName)\n                .collect(toList());\n        if (!partitionedBy.isEmpty()) {\n            properties.put(PARTITIONED_BY_PROPERTY, partitionedBy);\n        }\n\n        // Bucket properties\n        Optional<HiveBucketProperty> bucketProperty = table.get().getStorage().getBucketProperty();\n        table.get().getStorage().getBucketProperty().ifPresent(property -> {\n            properties.put(BUCKET_COUNT_PROPERTY, property.getBucketCount());\n            properties.put(BUCKETED_BY_PROPERTY, property.getBucketedBy());\n            properties.put(SORTED_BY_PROPERTY, property.getSortedBy());\n        });\n\n        // Preferred ordering columns\n        List<SortingColumn> preferredOrderingColumns = decodePreferredOrderingColumnsFromStorage(table.get().getStorage());\n        if (!preferredOrderingColumns.isEmpty()) {\n            if (bucketProperty.isPresent()) {\n                throw new PrestoException(HIVE_INVALID_METADATA, format(\"bucketed table %s should not specify preferred_ordering_columns\", tableName));\n            }\n            properties.put(PREFERRED_ORDERING_COLUMNS, preferredOrderingColumns);\n        }\n\n        // ORC format specific properties\n        String orcBloomFilterColumns = table.get().getParameters().get(ORC_BLOOM_FILTER_COLUMNS_KEY);\n        if (orcBloomFilterColumns != null) {\n            properties.put(ORC_BLOOM_FILTER_COLUMNS, Splitter.on(COMMA).trimResults().omitEmptyStrings().splitToList(orcBloomFilterColumns));\n        }\n        String orcBloomFilterFfp = table.get().getParameters().get(ORC_BLOOM_FILTER_FPP_KEY);\n        if (orcBloomFilterFfp != null) {\n            properties.put(ORC_BLOOM_FILTER_FPP, Double.parseDouble(orcBloomFilterFfp));\n        }\n\n        // Avro specific property\n        String avroSchemaUrl = table.get().getParameters().get(AVRO_SCHEMA_URL_KEY);\n        if (avroSchemaUrl != null) {\n            properties.put(AVRO_SCHEMA_URL, avroSchemaUrl);","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java#L741-L777","documentation":"A Hive table's storage may declare either bucketing (bucketed_by/sorted_by) or preferred ordering columns, not both. If decodePreferredOrderingColumnsFromStorage returns columns while the table also has a bucket property, getTableMetadata throws HIVE_INVALID_METADATA because the two ordering specifications conflict.","triggerScenarios":"Reading metadata for a table whose SerDe/storage properties contain both bucketing information and a preferred_ordering_columns property.","commonSituations":"Tables written by engines (e.g. Spark/Trino CTAS) whose metadata emitter set both properties; hand-edited table properties; version upgrades where a writer started adding preferred_ordering_columns to legacy bucketed tables.","solutions":["Recreate or ALTER the table to remove preferred_ordering_columns from its storage properties if bucketing is intended","Remove the bucketing property if ordering columns are intended instead","Fix the writing engine's table-property configuration so it emits only one of the two","Repair the metastore table properties directly (tblproperties/storage descriptor)"],"exampleFix":"-- before\nCREATE TABLE t (...) WITH (bucketed_by = ARRAY['id'], preferred_ordering_columns = ARRAY['id']);\n-- after\nCREATE TABLE t (...) WITH (bucketed_by = ARRAY['id']);","handlingStrategy":"validation","validationCode":"List<SortingColumn> ordering = decodePreferredOrderingColumnsFromStorage(table.getStorage());\nif (!ordering.isEmpty() && getBucketProperty(table.getStorage()).isPresent()) {\n    throw new IllegalStateException(\"Table cannot have both bucketing and preferred_ordering_columns\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    // read table metadata\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == HIVE_INVALID_METADATA.toErrorCode().getCode()) {\n        // inspect and fix tblproperties in the metastore\n    } else throw e;\n}","preventionTips":["Configure writer engines to emit either bucketing or preferred_ordering_columns, never both","Audit tblproperties on tables created by external engines before onboarding","Avoid hand-editing storage descriptor properties in the metastore"],"tags":["hive","metadata","bucketing","table-properties"],"backgroundTag":"conflicting-table-metadata","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"}