{"record":{"id":"27b70979194bfd5d","repo":"prestodb/presto","slug":"invalid-table-property-27b709","errorCode":"INVALID_TABLE_PROPERTY","errorMessage":"Invalid sorted_by definition","messagePattern":"Invalid sorted_by definition","errorType":"validation","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/SortFieldUtils.java","lineNumber":60,"sourceCode":"{\n    private SortFieldUtils() {}\n\n    private static final Pattern PATTERN = Pattern.compile(\n            \"\\\\s*(?<identifier>\" + PartitionFields.IDENTIFIER + \")\"\n                    + \"(?i:\\\\s+(?<ordering>ASC|DESC))?\"\n                    + \"(?i:\\\\s+NULLS\\\\s+(?<nullOrder>FIRST|LAST))?\"\n                    + \"\\\\s*\");\n\n    public static SortOrder parseSortFields(Schema schema, List<String> fields)\n    {\n        SortOrder.Builder builder = SortOrder.builderFor(schema);\n        parseSortFields(builder, fields);\n        SortOrder sortOrder;\n        try {\n            sortOrder = builder.build();\n        }\n        catch (RuntimeException e) {\n            throw new PrestoException(INVALID_TABLE_PROPERTY, \"Invalid \" + SORTED_BY_PROPERTY + \" definition\", e);\n        }\n\n        Set<Integer> baseColumnFieldIds = schema.columns().stream()\n                .map(Types.NestedField::fieldId)\n                .collect(toImmutableSet());\n        for (SortField field : sortOrder.fields()) {\n            if (!baseColumnFieldIds.contains(field.sourceId())) {\n                throw new PrestoException(COLUMN_NOT_FOUND, \"Column not found: \" + schema.findColumnName(field.sourceId()));\n            }\n        }\n\n        return sortOrder;\n    }\n\n    public static void parseSortFields(SortOrderBuilder<?> sortOrderBuilder, List<String> fields)\n    {\n        fields.forEach(field -> parseSortField(sortOrderBuilder, field));\n    }","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/SortFieldUtils.java#L42-L78","documentation":"parseSortFields validates the sorted_by table property and builds an Iceberg SortOrder. If the builder fails (duplicate fields, invalid transform/direction pairs, bad structure), the RuntimeException is wrapped as PrestoException(INVALID_TABLE_PROPERTY, \"Invalid sorted_by definition\"). It guards the table-creation DDL against malformed sort specifications.","triggerScenarios":"CREATE TABLE ... WITH (sorted_by = ARRAY[...]) where an entry parses (passes regex) but fails semantic validation when building the SortOrder — e.g. duplicate sort fields, an invalid transform, or an internally inconsistent field spec.","commonSituations":"Copy-pasted sorted_by values from other engines; typos in transform syntax that still match the grammar but not semantics; combining transforms not allowed by Iceberg on the column type.","solutions":["Check the wrapped cause exception in the PrestoException to see exactly which sort field failed to build","Simplify sorted_by entries to the documented form: [ASC|DESC] optionally with transforms, e.g. 'id ASC', 'bucket(16, user_id) DESC'","Remove duplicate columns from sorted_by — each column may appear only once","Create the table without sorted_by, then validate each entry individually before re-adding"],"exampleFix":"// before\nWITH (sorted_by = ARRAY['id ASC', 'id DESC'])\n// after\nWITH (sorted_by = ARRAY['id ASC'])","handlingStrategy":"validation","validationCode":"// Validate sorted_by before DDL: unique columns, known transforms, valid directions\nSet<String> seen = new HashSet<>();\nfor (String f : sortedBy) {\n    String col = f.split(\"\\\\s+\")[0];\n    if (!seen.add(col)) throw new IllegalArgumentException(\"Duplicate sort column: \" + col);\n}","typeGuard":null,"tryCatchPattern":"try { /* CREATE TABLE with sorted_by */ } catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"INVALID_TABLE_PROPERTY\")) {\n        // inspect e.getCause() for which sort field failed\n    } else { throw e; }\n}","preventionTips":["Use the documented sorted_by syntax: identifier [ASC|DESC] with optional Iceberg transforms","Ensure each column appears at most once in sorted_by","Verify the chosen transform is valid for the column's Iceberg type","Read the wrapped cause exception — it names the failing field"],"tags":["iceberg","ddl","table-property","sort-order"],"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"}