{"record":{"id":"2d0c185378b5ec3a","repo":"prestodb/presto","slug":"column-not-found-2d0c18","errorCode":"COLUMN_NOT_FOUND","errorMessage":"Column not found: ","messagePattern":"Column not found: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/SortFieldUtils.java","lineNumber":68,"sourceCode":"\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    }\n\n    private static void parseSortField(SortOrderBuilder<?> builder, String field)\n    {\n        Matcher matcher = PATTERN.matcher(field);\n        if (!matcher.matches()) {\n            throw new IllegalArgumentException(format(\"Unable to parse sort field: [%s]\", field));\n        }\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/SortFieldUtils.java#L50-L86","documentation":"After building the SortOrder, parseSortFields verifies every sort field's sourceId exists among the schema's top-level column field IDs. A field referencing a column absent from the table schema throws PrestoException(COLUMN_NOT_FOUND, \"Column not found: \" + findColumnName(sourceId)). This prevents sort orders referencing non-existent columns.","triggerScenarios":"CREATE TABLE ... WITH (sorted_by = ARRAY['colname']) where 'colname' is not a top-level column of the created table schema — misspelled name, a nested field path, or a column defined only in a later schema.","commonSituations":"Typos in DDL; referencing nested struct fields (only top-level columns are supported for sorting); copying sorted_by from another table with different columns; referencing a column renamed before table creation.","solutions":["Compare the sorted_by column names against the actual CREATE TABLE column list and fix any misspelling","Use only top-level columns — nested or struct-internal fields cannot be sort sources here","Run SHOW COLUMNS / DESCRIBE on the table to confirm the exact column names before re-running DDL","Ensure the sort field identifier doesn't include stray whitespace or case mismatches (depending on case-sensitivity settings)"],"exampleFix":"// before\nCREATE TABLE t (id BIGINT, data VARCHAR) WITH (sorted_by = ARRAY['ts ASC'])\n// after\nCREATE TABLE t (id BIGINT, data VARCHAR, ts TIMESTAMP) WITH (sorted_by = ARRAY['ts ASC'])","handlingStrategy":"validation","validationCode":"// Before DDL, confirm every sorted_by column is a top-level column of the table\nSet<String> columns = Set.of(\"id\", \"data\", \"ts\"); // actual CREATE TABLE columns\nfor (String f : sortedBy) {\n    String col = f.trim().split(\"\\\\s+\")[0];\n    if (!columns.contains(col)) throw new IllegalArgumentException(\"Column not found: \" + col);\n}","typeGuard":null,"tryCatchPattern":"try { /* CREATE TABLE with sorted_by */ } catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"COLUMN_NOT_FOUND\")) {\n        // message names the missing column; fix DDL and retry\n    } else { throw e; }\n}","preventionTips":["Cross-check sorted_by entries against the CREATE TABLE column list","Only reference top-level columns — no nested struct fields","Run DESCRIBE/SHOW COLUMNS first when copying sorted_by from other tables","Watch for typos and case mismatches in column identifiers"],"tags":["iceberg","ddl","column-not-found","sort-order"],"backgroundTag":"column-not-found","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}