asereda-gs commented on a change in pull request #1101: [CALCITE-2909] Optimize
Enumerable SemiJoin with lazy computation of innerLookup (Ruben Quesada Lopez)
URL: https://github.com/apache/calcite/pull/1101#discussion_r264328064
##########
File path:
linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
##########
@@ -1297,15 +1297,21 @@ private void closeInner() {
final Function1<TInner, TKey> innerKeySelector,
final EqualityComparer<TKey> comparer) {
return new AbstractEnumerable<TSource>() {
+ private Enumerable<TKey> innerLookup = null;
+ // CALCITE-2909 Delay the computation of the innerLookup until the
moment when we are sure
+ // that it will be really needed, i.e. when the first outer enumerator
item is processed
+ private Enumerable<TKey> getInnerLookup() {
Review comment:
I wonder if it makes more sense to create a generic `LazyEnumerable`. So the
code becomes :
```java
return Linq4j.lazy(() -> inner.select(innerKeySelector).distinct());
```
This is similar idea to Guava
[Supplier.memoize](https://google.github.io/guava/releases/23.0/api/docs/com/google/common/base/Suppliers.html#memoize-com.google.common.base.Supplier-)
or
[Observable.defer()](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html#defer-java.util.concurrent.Callable-).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services