{"record":{"id":"34d801a056960b0b","repo":"prestodb/presto","slug":"invalid-table-property-34d801","errorCode":"INVALID_TABLE_PROPERTY","errorMessage":"%s may be specified only when %s is specified","messagePattern":"(.+?) may be specified only when (.+?) is specified","errorType":"validation","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveTableProperties.java","lineNumber":221,"sourceCode":"    {\n        return (HiveStorageFormat) tableProperties.get(STORAGE_FORMAT_PROPERTY);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static List<String> getPartitionedBy(Map<String, Object> tableProperties)\n    {\n        List<String> partitionedBy = (List<String>) tableProperties.get(PARTITIONED_BY_PROPERTY);\n        return partitionedBy == null ? ImmutableList.of() : ImmutableList.copyOf(partitionedBy);\n    }\n\n    public static Optional<HiveBucketProperty> getBucketProperty(Map<String, Object> tableProperties)\n    {\n        List<String> bucketedBy = getBucketedBy(tableProperties);\n        List<SortingColumn> sortedBy = getSortedBy(tableProperties);\n        int bucketCount = (Integer) tableProperties.get(BUCKET_COUNT_PROPERTY);\n        if ((bucketedBy.isEmpty()) && (bucketCount == 0)) {\n            if (!sortedBy.isEmpty()) {\n                throw new PrestoException(INVALID_TABLE_PROPERTY, format(\"%s may be specified only when %s is specified\", SORTED_BY_PROPERTY, BUCKETED_BY_PROPERTY));\n            }\n            return Optional.empty();\n        }\n        if (bucketCount < 0) {\n            throw new PrestoException(INVALID_TABLE_PROPERTY, format(\"%s must be greater than zero\", BUCKET_COUNT_PROPERTY));\n        }\n        if (bucketCount > 1_000_000) {\n            throw new PrestoException(INVALID_TABLE_PROPERTY, format(\"%s should be no more than 1000000\", BUCKET_COUNT_PROPERTY));\n        }\n        if (bucketedBy.isEmpty() || bucketCount == 0) {\n            throw new PrestoException(INVALID_TABLE_PROPERTY, format(\"%s and %s must be specified together\", BUCKETED_BY_PROPERTY, BUCKET_COUNT_PROPERTY));\n        }\n        return Optional.of(new HiveBucketProperty(bucketedBy, bucketCount, sortedBy, HIVE_COMPATIBLE, Optional.empty()));\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private static List<String> getBucketedBy(Map<String, Object> tableProperties)\n    {","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveTableProperties.java#L203-L239","documentation":"HiveTableProperties.getBucketProperty validates CREATE TABLE bucketing properties. SORTED_BY (sorted_by) is only meaningful together with bucketing, so specifying sorted_by without bucketed_by/bucket_count raises INVALID_TABLE_PROPERTY.","triggerScenarios":"CREATE TABLE ... WITH (sorted_by = ARRAY['col ASC']) without bucketed_by or bucket_count (or when both are absent/empty), as seen in getBucketProperty when bucketedBy.isEmpty() && bucketCount == 0 but sortedBy is non-empty.","commonSituations":"Typos or misunderstanding that sorted_by requires bucketing; copying sorted_by clause from a bucketed table while dropping bucket clauses; connectors' schema generators emitting sorted_by alone.","solutions":["Add bucketed_by and bucket_count alongside sorted_by in the WITH clause.","Remove the sorted_by property if you don't need bucketed, sorted tables.","Note: bucket_count == 0 with bucketed_by also counts as 'not specified', so ensure both are present and positive."],"exampleFix":"// before\nCREATE TABLE t (a bigint) WITH (sorted_by = ARRAY['a ASC']);\n// after\nCREATE TABLE t (a bigint) WITH (bucketed_by = ARRAY['a'], bucket_count = 32, sorted_by = ARRAY['a ASC']);","handlingStrategy":"validation","validationCode":"// validate DDL properties before CREATE TABLE\nMap<String,Object> props = parseWithClause(withClause);\nboolean hasSorted = props.containsKey(\"sorted_by\");\nboolean hasBuckets = props.containsKey(\"bucketed_by\") && props.containsKey(\"bucket_count\");\nif (hasSorted && !hasBuckets) throw new IllegalArgumentException(\"sorted_by requires bucketed_by and bucket_count\");","typeGuard":null,"tryCatchPattern":"try { createTable(ddl); } catch (PrestoException e) {\n    if (INVALID_TABLE_PROPERTY.toErrorCode().getCode() == e.getErrorCode().getCode()) {\n        throw new IllegalArgumentException(\"Fix bucketing properties: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Always pair sorted_by with bucketed_by + bucket_count","Validate DDL properties in your schema-management tooling","Run SHOW CREATE TABLE on reference tables to copy correct clause sets"],"tags":["ddl","table-properties","bucketing","validation"],"backgroundTag":"invalid-table-property","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"}