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 38523ee Tweak searching partition in GINQ
38523ee is described below
commit 38523ee32048d22f922f297694f99b2610ab7f58
Author: Daniel Sun <[email protected]>
AuthorDate: Tue Dec 29 12:19:01 2020 +0800
Tweak searching partition in GINQ
---
.../ginq/provider/collection/runtime/QueryableCollection.java | 7 +++----
.../apache/groovy/ginq/provider/collection/runtime/WindowImpl.java | 7 +++----
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
index 3571539..db2b5a5 100644
---
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
+++
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
@@ -501,7 +501,7 @@ class QueryableCollection<T> implements Queryable<T>,
Serializable {
public <U extends Comparable<? super U>> Window<T> over(Tuple2<T, Long>
currentRecord, WindowDefinition<T, U> windowDefinition) {
this.makeReusable();
Queryable<Tuple2<T, Long>> partition =
- partitionCache.computeIfAbsent(windowDefinition, wd -> {
+
from(Collections.singletonList(currentRecord)).innerHashJoin(partitionCache.computeIfAbsent(windowDefinition,
wd -> {
long[] rn = new long[] { 1L };
List<Tuple2<T, Long>> listWithIndex =
this.toList().stream()
@@ -513,9 +513,8 @@ class QueryableCollection<T> implements Queryable<T>,
Serializable {
((QueryableCollection) q).makeReusable();
}
return q;
- })
- .where(e -> Objects.equals(e.getV1(),
windowDefinition.partitionBy().apply(currentRecord.getV1())))
- .select((e, q) -> e.getV2())
+ }), a -> windowDefinition.partitionBy().apply(a.getV1()),
Tuple2::getV1)
+ .select((e, q) -> e.getV2().getV2())
.stream()
.findFirst()
.orElse(Queryable.emptyQueryable());
diff --git
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/WindowImpl.java
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/WindowImpl.java
index a9cd806..d99f039 100644
---
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/WindowImpl.java
+++
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/WindowImpl.java
@@ -47,16 +47,15 @@ class WindowImpl<T, U extends Comparable<? super U>>
extends QueryableCollection
this.currentRecord = currentRecord;
this.windowDefinition = windowDefinition;
- final List<Order<? super T, ? extends U>> order =
windowDefinition.orderBy();
- if (null != order && 1 == order.size()) {
- this.keyExtractor = order.get(0).getKeyExtractor();
+ final List<Order<? super T, ? extends U>> orderList =
windowDefinition.orderBy();
+ if (null != orderList && 1 == orderList.size()) {
+ this.keyExtractor = orderList.get(0).getKeyExtractor();
this.value = keyExtractor.apply(currentRecord.getV1());
} else {
this.keyExtractor = null;
this.value = null;
}
- List<Queryable.Order<? super T, ? extends U>> orderList =
windowDefinition.orderBy();
int tmpIndex = null == orderList || orderList.isEmpty()
? binarySearch(listWithIndex, currentRecord,
comparing(Tuple2::getV2))
: binarySearch(listWithIndex, currentRecord,
makeComparator(composeOrders(orderList)).thenComparing(Tuple2::getV2));