diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/TranslationMap.java b/core/trino-main/src/main/java/io/trino/sql/planner/TranslationMap.java index 797a302acb6e6..96994d9f48871 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/TranslationMap.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/TranslationMap.java @@ -50,7 +50,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Verify.verify; -import static com.google.common.collect.ImmutableList.toImmutableList; import static io.trino.sql.planner.ScopeAware.scopeAwareKey; import static java.lang.String.format; import static java.util.Objects.requireNonNull; @@ -214,9 +213,14 @@ public Expression rewriteIdentifier(Identifier node, Void context, ExpressionTre public Expression rewriteFunctionCall(FunctionCall node, Void context, ExpressionTreeRewriter treeRewriter) { if (analysis.isPatternRecognitionFunction(node)) { - List rewrittenArguments = node.getArguments().stream() - .map(argument -> treeRewriter.rewrite(argument, null)) - .collect(toImmutableList()); + ImmutableList.Builder rewrittenArguments = ImmutableList.builder(); + if (!node.getArguments().isEmpty()) { + rewrittenArguments.add(treeRewriter.rewrite(node.getArguments().get(0), null)); + if (node.getArguments().size() > 1) { + // do not rewrite the offset literal + rewrittenArguments.add(node.getArguments().get(1)); + } + } // Pattern recognition functions are special constructs, passed using the form of FunctionCall. // They are not resolved like regular function calls. They are processed in LogicalIndexExtractor. return coerceIfNecessary(node, new FunctionCall( @@ -228,7 +232,7 @@ public Expression rewriteFunctionCall(FunctionCall node, Void context, Expressio false, Optional.empty(), node.getProcessingMode(), - rewrittenArguments)); + rewrittenArguments.build())); } // TODO handle aggregation in pattern recognition context (and handle its processingMode)