prestodb/presto · error · IllegalStateException

Unsupported query type: %s

Error message

Unsupported query type: %s

What it means

QueryRewriter.rewriteQuery dispatches on the parsed Statement type (Select, Insert, Delete, CreateTableAsSelect, etc.). When the statement's concrete class matches none of the handled branches, it throws IllegalStateException signaling the verifier does not support rewriting that query type.

Source

Thrown at presto-verifier/src/main/java/com/facebook/presto/verifier/rewrite/QueryRewriter.java:294

        }
        if (statement instanceof Query) {
            Query queryBody = (Query) statement;
            return rewriteQuery(queryBody, queryConfiguration, clusterType, shouldReuseTable, prefix, properties);
        }
        if (statement instanceof CreateView) {
            CreateView createView = (CreateView) statement;
            return rewriteCreateView(createView, queryConfiguration, clusterType, shouldReuseTable, prefix, properties);
        }
        if (statement instanceof CreateTable) {
            CreateTable createTable = (CreateTable) statement;
            return rewriteCreateTable(createTable, queryConfiguration, clusterType, shouldReuseTable, prefix, properties);
        }
        if (statement instanceof Delete) {
            Delete delete = (Delete) statement;
            return rewriteDelete(delete, queryConfiguration, clusterType, shouldReuseTable, prefix, properties);
        }

        throw new IllegalStateException(format("Unsupported query type: %s", statement.getClass()));
    }

    protected QueryObjectBundle rewriteCreateTableAsSelect(CreateTableAsSelect createTableAsSelect, QueryConfiguration queryConfiguration, ClusterType clusterType, boolean shouldReuseTable, QualifiedName prefix, List<Property> properties)
    {
        SubstitutedStatement<Query> substitutedQuery = rewriteQueryFunctions(createTableAsSelect.getQuery());
        Query createQuery = substitutedQuery.getStatement();
        Optional<String> functionSubstitutions = substitutedQuery.getFunctionSubstitutions();

        if (shouldReuseTable && !functionSubstitutions.isPresent()) {
            Optional<Expression> partitionsPredicate = getPartitionsPredicate(createTableAsSelect.getName(), queryConfiguration.getPartitions());
            if (partitionsPredicate.isPresent()) {
                return new QueryObjectBundle(
                        createTableAsSelect.getName(),
                        ImmutableList.of(),
                        createTableAsSelect,
                        ImmutableList.of(),
                        clusterType,
                        Optional.empty(),

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Remove or replace the unsupported statement in the verifier query configuration with a supported type (SELECT/INSERT/DELETE/CTAS)
  2. Add a rewrite branch for the statement type in QueryRewriter (e.g. implement rewriteCreateView) and dispatch on it
  3. Log and skip unsupported statements upstream instead of passing them to rewriteQuery

Example fix

// before
throw new IllegalStateException(format("Unsupported query type: %s", statement.getClass()));
// after
if (statement instanceof CreateView) {
    return rewriteCreateView((CreateView) statement, queryConfiguration, clusterType, prefix);
}
throw new IllegalStateException(format("Unsupported query type: %s", statement.getClass()));
Defensive patterns

Strategy: validation

Validate before calling

Statement stmt = parser.createStatement(sql);
Set<Class<?>> supported = Set.of(Query.class, Insert.class, Delete.class, CreateTableAsSelect.class);
if (supported.stream().noneMatch(c -> c.isAssignableFrom(stmt.getClass()))) {
    throw new IllegalArgumentException("Query type not supported by verifier: " + stmt.getClass().getSimpleName());
}

Type guard

boolean isRewritableStatement(Statement s) {
    return s instanceof Query || s instanceof Insert || s instanceof Delete || s instanceof CreateTableAsSelect;
}

Try / catch

try {
    return rewriter.rewriteQuery(...);
} catch (IllegalStateException ex) {
    if (ex.getMessage().startsWith("Unsupported query type")) {
        log.warn("Skipping unsupported statement: %s", ex.getMessage());
        return null;
    }
    throw ex;
}

Prevention

When it happens

Trigger: Calling rewriteQuery (directly or via bundle) with a parsed statement whose class is not one of the instanceof-handled types — e.g. CREATE VIEW, MERGE, CALL, EXPLAIN, or any newer statement kind.

Common situations: A verifier suite is extended with new query kinds (DDL like CREATE VIEW, SHOW statements) that the rewriter never supported; a Presto upgrade adds new statement types that fall through the dispatch; tests feed arbitrary SQL to the verifier.

Related errors


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