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/07 19:08:37 UTC
[groovy] branch GROOVY-8258 updated: GROOVY-8258: support nested
from for joins
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 2e6e80a GROOVY-8258: support nested from for joins
2e6e80a is described below
commit 2e6e80a872fafa8dd854daa1972c5cd0b9c2ceb3
Author: Daniel Sun <su...@apache.org>
AuthorDate: Thu Oct 8 03:08:17 2020 +0800
GROOVY-8258: support nested from for joins
---
.../linq/provider/collection/QueryableCollection.java | 13 ++-----------
.../test/groovy/org/apache/groovy/linq/GinqTest.groovy | 15 +++++++++++++++
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/QueryableCollection.java b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/QueryableCollection.java
index 645bb08..b5df13a 100644
--- a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/QueryableCollection.java
+++ b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/QueryableCollection.java
@@ -45,16 +45,13 @@ import static org.apache.groovy.linq.provider.collection.Queryable.from;
@Internal
class QueryableCollection<T> implements Queryable<T>, Iterable<T> {
private final Iterable<T> sourceIterable;
- private Stream<T> sourceStream;
QueryableCollection(Iterable<T> sourceIterable) {
if (sourceIterable instanceof QueryableCollection) {
QueryableCollection<T> queryableCollection = (QueryableCollection<T>) sourceIterable;
this.sourceIterable = queryableCollection.sourceIterable;
- this.sourceStream = queryableCollection.sourceStream;
} else {
this.sourceIterable = sourceIterable;
- this.sourceStream = toStream(sourceIterable);
}
}
@@ -188,13 +185,7 @@ class QueryableCollection<T> implements Queryable<T>, Iterable<T> {
@Override
public Stream<T> stream() {
- try {
- sourceStream = sourceStream.peek(e -> {}); // check whether the stream is usable
- } catch (IllegalStateException ex) {
- sourceStream = toStream(sourceIterable); // we have to create new stream every time because Java stream can not be reused
- }
-
- return sourceStream;
+ return toStream(sourceIterable); // we have to create new stream every time because Java stream can not be reused
}
@Override
@@ -243,7 +234,7 @@ class QueryableCollection<T> implements Queryable<T>, Iterable<T> {
}
private static <T> Iterable<T> toIterable(Stream<T> sourceStream) {
- return sourceStream::iterator;
+ return sourceStream.collect(Collectors.toList());
}
@Override
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 e38943b..1863d18 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
@@ -653,6 +653,21 @@ class GinqTest {
}
@Test
+ void "testGinq - nested from - 14"() {
+ assertScript '''
+ assert [2, 3] == GINQ {
+ from n in [1, 2, 3]
+ innerJoin k in (
+ from m in [2, 3, 4]
+ select m
+ )
+ on n == k
+ select n
+ }.toList()
+ '''
+ }
+
+ @Test
void "testGinq - from leftJoin select - 1"() {
assertScript '''
def nums1 = [1, 2, 3]