prestodb/presto · error · PrestoException
COLUMN_NOT_FOUND
COLUMN_NOT_FOUND
Error message
Column not found:
What it means
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.
Source
Thrown at presto-iceberg/src/main/java/com/facebook/presto/iceberg/SortFieldUtils.java:68
public static SortOrder parseSortFields(Schema schema, List<String> fields)
{
SortOrder.Builder builder = SortOrder.builderFor(schema);
parseSortFields(builder, fields);
SortOrder sortOrder;
try {
sortOrder = builder.build();
}
catch (RuntimeException e) {
throw new PrestoException(INVALID_TABLE_PROPERTY, "Invalid " + SORTED_BY_PROPERTY + " definition", e);
}
Set<Integer> baseColumnFieldIds = schema.columns().stream()
.map(Types.NestedField::fieldId)
.collect(toImmutableSet());
for (SortField field : sortOrder.fields()) {
if (!baseColumnFieldIds.contains(field.sourceId())) {
throw new PrestoException(COLUMN_NOT_FOUND, "Column not found: " + schema.findColumnName(field.sourceId()));
}
}
return sortOrder;
}
public static void parseSortFields(SortOrderBuilder<?> sortOrderBuilder, List<String> fields)
{
fields.forEach(field -> parseSortField(sortOrderBuilder, field));
}
private static void parseSortField(SortOrderBuilder<?> builder, String field)
{
Matcher matcher = PATTERN.matcher(field);
if (!matcher.matches()) {
throw new IllegalArgumentException(format("Unable to parse sort field: [%s]", field));
}
View on GitHub (pinned to 55bb57d202)
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)
Example fix
// before CREATE TABLE t (id BIGINT, data VARCHAR) WITH (sorted_by = ARRAY['ts ASC']) // after CREATE TABLE t (id BIGINT, data VARCHAR, ts TIMESTAMP) WITH (sorted_by = ARRAY['ts ASC'])
Defensive patterns
Strategy: validation
Validate before calling
// Before DDL, confirm every sorted_by column is a top-level column of the table
Set<String> columns = Set.of("id", "data", "ts"); // actual CREATE TABLE columns
for (String f : sortedBy) {
String col = f.trim().split("\\s+")[0];
if (!columns.contains(col)) throw new IllegalArgumentException("Column not found: " + col);
} Try / catch
try { /* CREATE TABLE with sorted_by */ } catch (PrestoException e) {
if (e.getErrorCode().getName().equals("COLUMN_NOT_FOUND")) {
// message names the missing column; fix DDL and retry
} else { throw e; }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/2d0c185378b5ec3a.
Report an issue: GitHub.