{"record":{"id":"25703f2d4d452eaa","repo":"prestodb/presto","slug":"generic-user-error-25703f","errorCode":"GENERIC_USER_ERROR","errorMessage":"Errors encountered while optimizing expressions.","messagePattern":"Errors encountered while optimizing expressions\\.","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/expressions/NativeSidecarExpressionInterpreter.java","lineNumber":100,"sourceCode":"        this.expressionOptimizationRequestCodec = requireNonNull(expressionOptimizationRequestCodec, \"expressionOptimizationRequestCodec is null\");\n    }\n\n    public Map<RowExpression, RowExpression> optimizeBatch(ConnectorSession session, Map<RowExpression, RowExpression> expressions, ExpressionOptimizer.Level level)\n    {\n        ImmutableList.Builder<RowExpression> originalExpressionsBuilder = ImmutableList.builder();\n        ImmutableList.Builder<RowExpression> resolvedExpressionsBuilder = ImmutableList.builder();\n        for (Map.Entry<RowExpression, RowExpression> entry : expressions.entrySet()) {\n            originalExpressionsBuilder.add(entry.getKey());\n            resolvedExpressionsBuilder.add(entry.getValue());\n        }\n        List<RowExpression> originalExpressions = originalExpressionsBuilder.build();\n        List<RowExpression> resolvedExpressions = resolvedExpressionsBuilder.build();\n\n        List<RowExpressionOptimizationResult> rowExpressionOptimizationResults = optimize(session, level, resolvedExpressions);\n\n        Optional<Exception> exception = rePackageExceptions(rowExpressionOptimizationResults);\n        if (exception.isPresent()) {\n            throw new PrestoException(GENERIC_USER_ERROR, \"Errors encountered while optimizing expressions.\", exception.get());\n        }\n\n        checkArgument(\n                rowExpressionOptimizationResults.size() == resolvedExpressions.size(),\n                \"Expected %s optimized expressions, but got %s\",\n                resolvedExpressions.size(),\n                rowExpressionOptimizationResults.size());\n\n        Map<RowExpression, RowExpression> result = new IdentityHashMap<>();\n        for (int i = 0; i < rowExpressionOptimizationResults.size(); i++) {\n            result.put(originalExpressions.get(i), rowExpressionOptimizationResults.get(i).getOptimizedExpression());\n        }\n        return unmodifiableMap(result);\n    }\n\n    public List<RowExpressionOptimizationResult> optimize(ConnectorSession session, ExpressionOptimizer.Level level, List<RowExpression> resolvedExpressions)\n    {\n        List<RowExpressionOptimizationResult> optimizedExpressions;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/expressions/NativeSidecarExpressionInterpreter.java#L82-L118","documentation":"This PrestoException (GENERIC_USER_ERROR) is thrown by NativeSidecarExpressionInterpreter.optimizeBatch when one or more expressions in a batch failed to optimize on the native sidecar. rePackageExceptions surfaces the underlying native exception as the cause; the outer message is a generic wrapper. The failure came back per-expression from the sidecar's row-expression optimization endpoint.","triggerScenarios":"Calling optimizeBatch with RowExpressions that the native expression optimizer rejects — unsupported functions, unsupported types, or a native-side internal error during constant folding/PEE.","commonSituations":"Queries using functions or type combinations not yet supported by the native sidecar; sidecar/native version skew causing parse failures of serialized RowExpression; malformed resolved expressions after metadata resolution.","solutions":["Inspect the cause (exception.get()) — it names the specific expression/function the native side rejected","Fall back to Java expression interpreter for unsupported expressions, or upgrade native sidecar to add support","Verify coordinator and sidecar versions are compatible","Reproduce with the single failing expression to confirm and file/support the gap"],"exampleFix":"// before: hard fail on any expression\nthrow new PrestoException(GENERIC_USER_ERROR, \"Errors encountered while optimizing expressions.\", e);\n// after: caller falls back to Java interpreter\ntry {\n    return interpreter.optimizeBatch(session, level, expressions);\n} catch (PrestoException ex) {\n    return javaInterpreter.optimizeBatch(session, level, expressions); // fallback\n}","handlingStrategy":"try-catch","validationCode":"// check expressions are non-empty and metadata-resolved before native optimization\nif (expressions.isEmpty()) {\n  return ImmutableList.of();\n}\n// optionally verify each function is in the sidecar-supported set\nboolean allSupported = expressions.stream().allMatch(this::isSupportedByNative);","typeGuard":null,"tryCatchPattern":"try {\n  return sidecarInterpreter.optimizeBatch(session, level, expressions);\n} catch (PrestoException e) {\n  if (e.getErrorCode().toCode() == GenericErrorCode.GENERIC_USER_ERROR.toCode()) {\n    // cause names the unsupported expression/function; fall back to Java\n    return javaInterpreter.optimizeBatch(session, level, expressions);\n  }\n  throw e;\n}","preventionTips":["Always read the cause of the PrestoException — it names the rejected expression","Maintain a capability list of functions the native sidecar supports and route unsupported ones to Java","Keep sidecar and coordinator versions compatible","Test new function usage against the native sidecar before rollout"],"tags":["presto","native-sidecar","expression-optimization","generic-user-error"],"backgroundTag":"native-sidecar-expression-optimization-failed","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"}