You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/10/09 23:57:49 UTC
[groovy] branch GROOVY-8258 updated: GROOVY-8258: support nested
GINQ in the `where` clause
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-8258
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY-8258 by this push:
new 588afcf GROOVY-8258: support nested GINQ in the `where` clause
588afcf is described below
commit 588afcff1be8b71845743cd2ac42d043f3535c31
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Oct 10 07:57:33 2020 +0800
GROOVY-8258: support nested GINQ in the `where` clause
---
.../org/apache/groovy/linq/dsl/GinqAstBuilder.java | 8 ++++++++
.../linq/provider/collection/GinqAstWalker.groovy | 18 +++++++++++++++---
.../test/groovy/org/apache/groovy/linq/GinqTest.groovy | 2 --
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/dsl/GinqAstBuilder.java b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/dsl/GinqAstBuilder.java
index 0b8c974..c446bc6 100644
--- a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/dsl/GinqAstBuilder.java
+++ b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/dsl/GinqAstBuilder.java
@@ -129,6 +129,14 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
if ("where".equals(methodName) || "on".equals(methodName)) {
Expression filterExpr = ((ArgumentListExpression) call.getArguments()).getExpression(0);
+ if (filterExpr instanceof BinaryExpression && ((BinaryExpression) filterExpr).getOperation().getType() == Types.KEYWORD_IN) {
+ if (null != latestGinqExpression) {
+ // use the nested ginq and clear it
+ ((BinaryExpression) filterExpr).setRightExpression(latestGinqExpression);
+ latestGinqExpression = null;
+ }
+ }
+
FilterExpression filterExpression = null;
if ("where".equals(methodName)) {
filterExpression = new WhereExpression(filterExpr);
diff --git a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/GinqAstWalker.groovy b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/GinqAstWalker.groovy
index 25c0bf4..33cab8c 100644
--- a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/GinqAstWalker.groovy
+++ b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/GinqAstWalker.groovy
@@ -25,7 +25,6 @@ import org.apache.groovy.linq.dsl.GinqVisitor
import org.apache.groovy.linq.dsl.SyntaxErrorReportable
import org.apache.groovy.linq.dsl.expression.AbstractGinqExpression
import org.apache.groovy.linq.dsl.expression.DataSourceExpression
-import org.apache.groovy.linq.dsl.expression.FilterExpression
import org.apache.groovy.linq.dsl.expression.FromExpression
import org.apache.groovy.linq.dsl.expression.GinqExpression
import org.apache.groovy.linq.dsl.expression.GroupExpression
@@ -184,8 +183,8 @@ class GinqAstWalker implements GinqVisitor<Object>, SyntaxErrorReportable {
private MethodCallExpression constructFromMethodCallExpression(Expression dataSourceExpr) {
MethodCallExpression fromMethodCallExpression = macro {
$v{ makeQueryableCollectionClassExpression() }.from($v {
- if (dataSourceExpr instanceof GinqExpression) {
- return this.visitGinqExpression((GinqExpression) dataSourceExpr)
+ if (dataSourceExpr instanceof AbstractGinqExpression) {
+ return this.visit((AbstractGinqExpression) dataSourceExpr)
} else {
return dataSourceExpr
}
@@ -243,6 +242,19 @@ class GinqAstWalker implements GinqVisitor<Object>, SyntaxErrorReportable {
Expression fromMethodCallExpression = whereExpression.getNodeMetaData(__METHOD_CALL_RECEIVER)
Expression filterExpr = whereExpression.getFilterExpr()
+ if (filterExpr instanceof BinaryExpression && ((BinaryExpression) filterExpr).operation.type == Types.KEYWORD_IN) {
+ filterExpr = filterExpr.transformExpression(new ExpressionTransformer() {
+ @Override
+ Expression transform(Expression expression) {
+ if (expression instanceof AbstractGinqExpression) {
+ return callX((Expression) GinqAstWalker.this.visit((AbstractGinqExpression) expression), "toList")
+ }
+
+ return expression.transformExpression(this)
+ }
+ })
+ }
+
return callXWithLambda(fromMethodCallExpression, "where", dataSourceExpression, filterExpr)
}
diff --git a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
index 44fef6c..c6b9a16 100644
--- a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
+++ b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
@@ -19,7 +19,6 @@
package org.apache.groovy.linq
import groovy.json.JsonSlurper
-import groovy.test.NotYetImplemented
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.junit.Test
@@ -696,7 +695,6 @@ class GinqTest {
'''
}
- @NotYetImplemented
@Test
void "testGinq - nested from - 15"() {
assertScript '''