Skip to content

Commit

Permalink
Fix planning of pattern navigation offset
Browse files Browse the repository at this point in the history
The offset value is a LongLiteral. Before this change,
it was rewritten by the TranslationMap, which could lead to
replacing the literal with a symbol reference, if the map
already contained a mapping for that literal.
It resulted in a failure in LogicalIndexExtractor, where
a literal was expected.

After this change, the offset argument is not rewritten.
  • Loading branch information
kasiafi committed Jun 21, 2021
1 parent c92ec68 commit 34d8485
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -214,9 +213,14 @@ public Expression rewriteIdentifier(Identifier node, Void context, ExpressionTre
public Expression rewriteFunctionCall(FunctionCall node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
{
if (analysis.isPatternRecognitionFunction(node)) {
List<Expression> rewrittenArguments = node.getArguments().stream()
.map(argument -> treeRewriter.rewrite(argument, null))
.collect(toImmutableList());
ImmutableList.Builder<Expression> 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(
Expand All @@ -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)
Expand Down

0 comments on commit 34d8485

Please sign in to comment.