Skip to content

Commit

Permalink
Add analyzer check for lambda in pattern recognition context
Browse files Browse the repository at this point in the history
Before this change, queries containing lambda failed in
ValidateDependenciesChecker, because lambda wasn't properly
planned and desugared.
  • Loading branch information
kasiafi committed Aug 6, 2021
1 parent 20f9c48 commit 5048dda
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,10 @@ public Type visitFieldReference(FieldReference node, StackableAstVisitorContext<
@Override
protected Type visitLambdaExpression(LambdaExpression node, StackableAstVisitorContext<Context> context)
{
if (context.getContext().isPatternRecognition()) {
throw semanticException(NOT_SUPPORTED, node, "Lambda expression in pattern recognition context is not yet supported");
}

verifyNoAggregateWindowOrGroupingFunctions(metadata, node.getBody(), "Lambda expression");
if (!context.getContext().isExpectingLambda()) {
throw semanticException(TYPE_MISMATCH, node, "Lambda expression should always be used inside a function");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4469,6 +4469,25 @@ public void testNoOutputColumns()
.hasMessage("line 1:25: pattern recognition output table has no columns");
}

@Test
public void testLambdaInPatternRecognition()
{
String query = "SELECT M.Measure " +
" FROM (VALUES (ARRAY[1]), (ARRAY[2])) Ticker(Value) " +
" MATCH_RECOGNIZE ( " +
" MEASURES %s AS Measure " +
" PATTERN (A B+) " +
" DEFINE B AS %s " +
" ) AS M";

assertFails(format(query, "transform(A.Value, x -> x + 100)", "true"))
.hasErrorCode(NOT_SUPPORTED)
.hasMessage("line 1:161: Lambda expression in pattern recognition context is not yet supported");
assertFails(format(query, "true", "transform(A.Value, x -> x + 100) = ARRAY[50]"))
.hasErrorCode(NOT_SUPPORTED)
.hasMessage("line 1:242: Lambda expression in pattern recognition context is not yet supported");
}

@Test
public void testRowPatternRecognitionFunctions()
{
Expand Down

0 comments on commit 5048dda

Please sign in to comment.