This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 53c3622 Validate window clause
53c3622 is described below
commit 53c3622c6e51b0fc845be947377fdd9d81d27c21
Author: Daniel Sun <[email protected]>
AuthorDate: Fri Jan 1 10:21:08 2021 +0800
Validate window clause
---
.../ginq/provider/collection/GinqAstWalker.groovy | 21 +++++++++++++++++++++
.../org/apache/groovy/ginq/GinqErrorTest.groovy | 12 ++++++++++++
2 files changed, 33 insertions(+)
diff --git
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
index c2c0d68..635d91d 100644
---
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
+++
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
@@ -782,6 +782,7 @@ class GinqAstWalker implements GinqAstVisitor<Expression>,
SyntaxErrorReportable
Expression rowsExpr = null
ArgumentListExpression argumentListExpression =
(ArgumentListExpression) methodCallExpression.arguments
if (1 == argumentListExpression.getExpressions().size()) {
+ final List<MethodCallExpression> ignoredMethodCallExpressionList =
[]
argumentListExpression.visit(new CodeVisitorSupport() {
@Override
@@ -793,10 +794,13 @@ class GinqAstWalker implements
GinqAstVisitor<Expression>, SyntaxErrorReportable
orderExpr = call.arguments
} else if ('rows' == call.methodAsString) {
rowsExpr = call.arguments
+ } else {
+ ignoredMethodCallExpressionList << call
}
}
})
+ validateWindowClause(classifierExpr, orderExpr, rowsExpr,
ignoredMethodCallExpressionList)
}
def argumentExpressionList = []
@@ -824,6 +828,23 @@ class GinqAstWalker implements GinqAstVisitor<Expression>,
SyntaxErrorReportable
)
}
+ private void validateWindowClause(Expression classifierExpr, Expression
orderExpr, Expression rowsExpr, List<? extends MethodCallExpression>
ignoredMethodCallExpressionList) {
+ new ListExpression(Arrays.asList(classifierExpr, orderExpr,
rowsExpr).grep(e -> null != e)).visit(new GinqAstBaseVisitor() {
+ @Override
+ void visitMethodCallExpression(MethodCallExpression call) {
+ ignoredMethodCallExpressionList.remove(call)
+ }
+ })
+
+ if (ignoredMethodCallExpressionList) {
+ MethodCallExpression ignoredMce =
ignoredMethodCallExpressionList.get(0)
+ this.collectSyntaxError(new GinqSyntaxError(
+ "Unknown window clause: `${ignoredMce.methodAsString}`",
+ ignoredMce.getLineNumber(), ignoredMce.getColumnNumber()
+ ))
+ }
+ }
+
private int windowQueryableNameSeq = 0
private String getWindowQueryableName() {
String name = (String)
currentGinqExpression.getNodeMetaData(__WINDOW_QUERYABLE_NAME)
diff --git
a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
index 8bf9087..70227fe 100644
---
a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
+++
b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
@@ -442,4 +442,16 @@ class GinqErrorTest {
assert err.toString().contains('Unsupported window function: `xxx` @
line 3, column 28.')
}
+
+ @Test
+ void "testGinq - window - 47"() {
+ def err = shouldFail '''\
+ GQ {
+ from n in [1, 1, 2, 2]
+ select n, (rowNumber() over(order by n))
+ }.toList()
+ '''
+
+ assert err.toString().contains('Unknown window clause: `order` @ line
3, column 51.')
+ }
}