prestodb/presto · error · PrestoException

COLUMN_NOT_FOUND

COLUMN_NOT_FOUND

Error message

Z-order column(s) not found in table: %s. Available columns: %s

What it means

Planning error for a distributed table-data-rewrite procedure (e.g. compaction/OptimizeTableZOrder): some columns named in the ZORDER BY list do not exist in the target table. The %s lists the missing columns and the table's available columns.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java:342

        Set<VariableReferenceExpression> notNullColumnVariables = tableMetadata.getColumns().stream()
                .filter(column -> !column.isNullable())
                .map(ColumnMetadata::getName)
                .map(columnToVariableMap::get)
                .collect(toImmutableSet());

        PlanNode queryRoot = plan.getRoot();
        Optional<List<String>> zOrderColumns = analysis.getCallDistributedProcedureAnalysis()
                .flatMap(Analysis.CallDistributedProcedureAnalysis::getProcedureAnalysisContext)
                .map(TableDataRewriteAnalysisContext.class::cast)
                .flatMap(TableDataRewriteAnalysisContext::getzOrderColumns);
        if (zOrderColumns.isPresent() && !zOrderColumns.get().isEmpty()) {
            // Validate all z-order column names exist before mapping to variables
            List<String> invalidColumns = zOrderColumns.get().stream()
                    .filter(columnName -> !columnToVariableMap.containsKey(columnName))
                    .collect(toImmutableList());

            if (!invalidColumns.isEmpty()) {
                throw new PrestoException(
                        COLUMN_NOT_FOUND,
                        format("Z-order column(s) not found in table: %s. Available columns: %s",
                                invalidColumns,
                                columnToVariableMap.keySet()));
            }

            List<VariableReferenceExpression> zOrderColumnVars = zOrderColumns.get().stream()
                    .map(columnToVariableMap::get)
                    .collect(toImmutableList());

            CallExpression zorderFunction = buildZOrderFunctionCall(zOrderColumnVars, metadata);

            VariableReferenceExpression output = variableAllocator.newVariable("$z_order", VARBINARY);
            Assignments assignments = Assignments.builder()
                    .putAll(identityAssignments(queryRoot.getOutputVariables()))
                    .put(output, zorderFunction)
                    .build();
            queryRoot = new ProjectNode(idAllocator.getNextId(), queryRoot, assignments);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use only existing column names in the ZORDER BY clause
  2. Check spelling/quoting of column names against SHOW COLUMNS
  3. Add the desired columns to the table before rewriting
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java:342 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/d73397d2b4d81d82. Report an issue: GitHub.