prestodb/presto · warning · SemanticException

NOT_SUPPORTED

NOT_SUPPORTED

Error message

Nonassociative function call rewrite not supported function calls with fields other than name and arguments

What it means

rewriteNonAssociativeFunction only supports rewriting function calls whose fields are limited to the function name and arguments. If the FunctionCall carries anything else (filter, window, ordering, distinct), validateNonAssociativeFunctionCallFields fails and a NOT_SUPPORTED SemanticException is raised.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/MaterializedViewUtils.java:292

    public static TupleDomain<String> getDomainFromFilter(Session session, DomainTranslator domainTranslator, RowExpression rowExpression)
    {
        DomainTranslator.ExtractionResult<String> predicateFromBaseQuery = domainTranslator.fromPredicate(
                session.toConnectorSession(),
                rowExpression,
                (baseFilterExpression, domain) -> baseFilterExpression instanceof VariableReferenceExpression
                        ? Optional.of(((VariableReferenceExpression) baseFilterExpression).getName())
                        : Optional.empty());

        return predicateFromBaseQuery.getTupleDomain();
    }

    /**
     * Rewrites the provided argument if it is non-associative (e.g. it cannot be handled by simply re-applying function to derived columns)
     */
    public static Expression rewriteNonAssociativeFunction(FunctionCall functionCall, Map<Expression, Identifier> baseToViewColumnMap)
    {
        if (!validateNonAssociativeFunctionCallFields(functionCall)) {
            throw new SemanticException(NOT_SUPPORTED, functionCall, "Nonassociative function call rewrite not supported function calls with fields other than name and arguments");
        }

        QualifiedName functionName = functionCall.getName();
        List<Expression> expressions = functionCall.getArguments();

        if (!validateNonAssociativeFunctionCallArguments(functionName, expressions)) {
            throw new SemanticException(NOT_SUPPORTED, functionCall, "Nonassociative function call rewrite not supported without single identifier as argument");
        }

        Identifier baseTableColumn = (Identifier) expressions.get(0);

        return NON_ASSOCIATIVE_REWRITE_FUNCTIONS.get(functionName).rewrite(baseTableColumn, baseToViewColumnMap);
    }

    public static boolean validateNonAssociativeFunctionRewrite(FunctionCall functionCall, Map<Expression, Identifier> baseToViewColumnMap)
    {
        QualifiedName functionName = functionCall.getName();
        List<Expression> expressions = functionCall.getArguments();

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Restructure the query to avoid FILTER/OVER/ORDER BY on the non-associative aggregate (e.g. filter rows in an outer query instead)
  2. Compute the aggregate outside the materialized-view-rewritten query
  3. If authoring the optimizer, extend validateNonAssociativeFunctionCallFields to handle these fields explicitly
  4. Materialize the exact aggregate expression in the view so rewrite is unnecessary

Example fix

// before
SELECT avg(x) FILTER (WHERE status = 'ok') FROM mv;
// after
SELECT avg(x) FROM mv WHERE status = 'ok';
Defensive patterns

Strategy: validation

Validate before calling

// avoid unsupported fields on non-associative aggregates in queries against MVs
// reject: avg(x) FILTER (...), avg(x) OVER (...), avg(x) ORDER BY ...
// allow only: avg(x)

Try / catch

try { ... } catch (SemanticException e) { if (e.getCode() == NOT_SUPPORTED) { /* fall back to base-table query */ } else { throw e; } }

Prevention

When it happens

Trigger: Materialized view query rewrite encounters a non-associative function (registered in NON_ASSOCIATIVE_REWRITE_FUNCTIONS) whose call includes unsupported fields such as FILTER (WHERE ...), OVER (...) window clauses, ORDER BY within the call, or DISTINCT.

Common situations: Queries against materialized views using e.g. avg(x) FILTER (WHERE ...) or avg(x) OVER (PARTITION BY ...) expecting automatic rewrite to derived view columns.

Understand the failure class

Background: Presto NOT_SUPPORTED error: what "not supported" means and how to fix it — this error's family across 3 libraries.

Related errors


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