{"record":{"id":"6decda6f4101d33c","repo":"prestodb/presto","slug":"not-supported-6decda","errorCode":"NOT_SUPPORTED","errorMessage":"Nonassociative function call rewrite not supported function calls with fields other than name and arguments","messagePattern":"Nonassociative function call rewrite not supported function calls with fields other than name and arguments","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"warning","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/MaterializedViewUtils.java","lineNumber":292,"sourceCode":"    public static TupleDomain<String> getDomainFromFilter(Session session, DomainTranslator domainTranslator, RowExpression rowExpression)\n    {\n        DomainTranslator.ExtractionResult<String> predicateFromBaseQuery = domainTranslator.fromPredicate(\n                session.toConnectorSession(),\n                rowExpression,\n                (baseFilterExpression, domain) -> baseFilterExpression instanceof VariableReferenceExpression\n                        ? Optional.of(((VariableReferenceExpression) baseFilterExpression).getName())\n                        : Optional.empty());\n\n        return predicateFromBaseQuery.getTupleDomain();\n    }\n\n    /**\n     * Rewrites the provided argument if it is non-associative (e.g. it cannot be handled by simply re-applying function to derived columns)\n     */\n    public static Expression rewriteNonAssociativeFunction(FunctionCall functionCall, Map<Expression, Identifier> baseToViewColumnMap)\n    {\n        if (!validateNonAssociativeFunctionCallFields(functionCall)) {\n            throw new SemanticException(NOT_SUPPORTED, functionCall, \"Nonassociative function call rewrite not supported function calls with fields other than name and arguments\");\n        }\n\n        QualifiedName functionName = functionCall.getName();\n        List<Expression> expressions = functionCall.getArguments();\n\n        if (!validateNonAssociativeFunctionCallArguments(functionName, expressions)) {\n            throw new SemanticException(NOT_SUPPORTED, functionCall, \"Nonassociative function call rewrite not supported without single identifier as argument\");\n        }\n\n        Identifier baseTableColumn = (Identifier) expressions.get(0);\n\n        return NON_ASSOCIATIVE_REWRITE_FUNCTIONS.get(functionName).rewrite(baseTableColumn, baseToViewColumnMap);\n    }\n\n    public static boolean validateNonAssociativeFunctionRewrite(FunctionCall functionCall, Map<Expression, Identifier> baseToViewColumnMap)\n    {\n        QualifiedName functionName = functionCall.getName();\n        List<Expression> expressions = functionCall.getArguments();","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/MaterializedViewUtils.java#L274-L310","documentation":"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.","triggerScenarios":"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.","commonSituations":"Queries against materialized views using e.g. avg(x) FILTER (WHERE ...) or avg(x) OVER (PARTITION BY ...) expecting automatic rewrite to derived view columns.","solutions":["Restructure the query to avoid FILTER/OVER/ORDER BY on the non-associative aggregate (e.g. filter rows in an outer query instead)","Compute the aggregate outside the materialized-view-rewritten query","If authoring the optimizer, extend validateNonAssociativeFunctionCallFields to handle these fields explicitly","Materialize the exact aggregate expression in the view so rewrite is unnecessary"],"exampleFix":"// before\nSELECT avg(x) FILTER (WHERE status = 'ok') FROM mv;\n// after\nSELECT avg(x) FROM mv WHERE status = 'ok';","handlingStrategy":"validation","validationCode":"// avoid unsupported fields on non-associative aggregates in queries against MVs\n// reject: avg(x) FILTER (...), avg(x) OVER (...), avg(x) ORDER BY ...\n// allow only: avg(x)","typeGuard":null,"tryCatchPattern":"try { ... } catch (SemanticException e) { if (e.getCode() == NOT_SUPPORTED) { /* fall back to base-table query */ } else { throw e; } }","preventionTips":["Keep non-associative aggregates simple: single column argument, no FILTER/OVER/DISTINCT","Put filtering in outer queries instead of FILTER clauses on aggregates","Include needed aggregates in the materialized view definition","Test MV-backed queries for rewrite support"],"tags":["materialized-view","rewrite","not-supported","aggregate"],"backgroundTag":"mv-query-rewrite-not-supported","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}