prestodb/presto · error · PrestoException

GENERIC_USER_ERROR

GENERIC_USER_ERROR

Error message

Errors encountered while optimizing expressions.

What it means

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.

Source

Thrown at presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/expressions/NativeSidecarExpressionInterpreter.java:100

        this.expressionOptimizationRequestCodec = requireNonNull(expressionOptimizationRequestCodec, "expressionOptimizationRequestCodec is null");
    }

    public Map<RowExpression, RowExpression> optimizeBatch(ConnectorSession session, Map<RowExpression, RowExpression> expressions, ExpressionOptimizer.Level level)
    {
        ImmutableList.Builder<RowExpression> originalExpressionsBuilder = ImmutableList.builder();
        ImmutableList.Builder<RowExpression> resolvedExpressionsBuilder = ImmutableList.builder();
        for (Map.Entry<RowExpression, RowExpression> entry : expressions.entrySet()) {
            originalExpressionsBuilder.add(entry.getKey());
            resolvedExpressionsBuilder.add(entry.getValue());
        }
        List<RowExpression> originalExpressions = originalExpressionsBuilder.build();
        List<RowExpression> resolvedExpressions = resolvedExpressionsBuilder.build();

        List<RowExpressionOptimizationResult> rowExpressionOptimizationResults = optimize(session, level, resolvedExpressions);

        Optional<Exception> exception = rePackageExceptions(rowExpressionOptimizationResults);
        if (exception.isPresent()) {
            throw new PrestoException(GENERIC_USER_ERROR, "Errors encountered while optimizing expressions.", exception.get());
        }

        checkArgument(
                rowExpressionOptimizationResults.size() == resolvedExpressions.size(),
                "Expected %s optimized expressions, but got %s",
                resolvedExpressions.size(),
                rowExpressionOptimizationResults.size());

        Map<RowExpression, RowExpression> result = new IdentityHashMap<>();
        for (int i = 0; i < rowExpressionOptimizationResults.size(); i++) {
            result.put(originalExpressions.get(i), rowExpressionOptimizationResults.get(i).getOptimizedExpression());
        }
        return unmodifiableMap(result);
    }

    public List<RowExpressionOptimizationResult> optimize(ConnectorSession session, ExpressionOptimizer.Level level, List<RowExpression> resolvedExpressions)
    {
        List<RowExpressionOptimizationResult> optimizedExpressions;

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Inspect the cause (exception.get()) — it names the specific expression/function the native side rejected
  2. Fall back to Java expression interpreter for unsupported expressions, or upgrade native sidecar to add support
  3. Verify coordinator and sidecar versions are compatible
  4. Reproduce with the single failing expression to confirm and file/support the gap

Example fix

// before: hard fail on any expression
throw new PrestoException(GENERIC_USER_ERROR, "Errors encountered while optimizing expressions.", e);
// after: caller falls back to Java interpreter
try {
    return interpreter.optimizeBatch(session, level, expressions);
} catch (PrestoException ex) {
    return javaInterpreter.optimizeBatch(session, level, expressions); // fallback
}
Defensive patterns

Strategy: try-catch

Validate before calling

// check expressions are non-empty and metadata-resolved before native optimization
if (expressions.isEmpty()) {
  return ImmutableList.of();
}
// optionally verify each function is in the sidecar-supported set
boolean allSupported = expressions.stream().allMatch(this::isSupportedByNative);

Try / catch

try {
  return sidecarInterpreter.optimizeBatch(session, level, expressions);
} catch (PrestoException e) {
  if (e.getErrorCode().toCode() == GenericErrorCode.GENERIC_USER_ERROR.toCode()) {
    // cause names the unsupported expression/function; fall back to Java
    return javaInterpreter.optimizeBatch(session, level, expressions);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling optimizeBatch with RowExpressions that the native expression optimizer rejects — unsupported functions, unsupported types, or a native-side internal error during constant folding/PEE.

Common situations: 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.

Related errors


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