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_r268158421
 
 

 ##########
 File path: 
linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
 ##########
 @@ -1298,11 +1298,11 @@ private void closeInner() {
       final EqualityComparer<TKey> comparer) {
     return new AbstractEnumerable<TSource>() {
       public Enumerator<TSource> enumerator() {
-        final Enumerable<TKey> innerLookup =
-            comparer == null
-                ? inner.select(innerKeySelector).distinct()
-                : inner.select(innerKeySelector).distinct(comparer);
-
+        // 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
+        final Enumerable<TKey> innerLookup = comparer == null
+                ? Linq4j.lazyEnumerable(() -> 
inner.select(innerKeySelector).distinct())
+                : Linq4j.lazyEnumerable(() -> 
inner.select(innerKeySelector).distinct(comparer));
 
 Review comment:
   Originally I was guided by the fact that it is nicer (from API perspective) 
to use `T` (which may be lazy) rather than explicitly define `Lazy<T>`.  Some 
examples:
   1. 
[Supplier.memoize](https://google.github.io/guava/releases/19.0/api/docs/com/google/common/base/Suppliers.html#memoize(com.google.common.base.Supplier))
 from guava. 
   2. 
[StreamSupport.stream(Supplier<Spliterator>)](https://docs.oracle.com/javase/8/docs/api/java/util/stream/StreamSupport.html#stream-java.util.function.Supplier-int-boolean-)
   3. 
[Observable.defer](http://reactivex.io/RxJava/javadoc/rx/Observable.html#defer-rx.functions.Func0-)
   
   I'm sorry if I have wasted your time @rubenada . This change looks fine. Pls 
rebase and I'll merge it after 1.19 release.

----------------------------------------------------------------
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

Reply via email to