diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java index 94a44f4a8219f..b20e9b69e9ec6 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java @@ -2128,6 +2128,10 @@ public Type visitFieldReference(FieldReference node, StackableAstVisitorContext< @Override protected Type visitLambdaExpression(LambdaExpression node, StackableAstVisitorContext 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"); diff --git a/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java b/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java index 69a2fe33796c6..6f82de31850f4 100644 --- a/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java +++ b/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java @@ -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() {