You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/10/26 19:25:05 UTC

[GitHub] [iceberg] aokolnychyi opened a new pull request #1664: Parquet: Optimize IN predicates in ParquetDictionaryRowGroupFilter

aokolnychyi opened a new pull request #1664:
URL: https://github.com/apache/iceberg/pull/1664


   This PR optimizes the evaluation of IN predicates on dictionary encoded columns in Parquet.
   
   The previous solution relied on `isEmpty` on top of `Sets$intersection`. That, in turn, used `Collections$disjoint(set2, set1)`. The latter checks whether the first argument is a set or not. If yes, it would simply iterate over the second argument ignoring the fact that the second argument can be also a set and may be even bigger. All of that led to the fact that we iterated through all dictionary values to evaluate IN predicates.


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #1664: Parquet: Optimize IN predicates in ParquetDictionaryRowGroupFilter

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #1664:
URL: https://github.com/apache/iceberg/pull/1664#discussion_r513581060



##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetDictionaryRowGroupFilter.java
##########
@@ -278,8 +278,27 @@ public Boolean or(Boolean leftResult, Boolean rightResult) {
 
       Set<T> dictionary = dict(id, ref.comparator());
 
-      // ROWS_CANNOT_MATCH if all values of the dictionary are not in the set (the intersection is empty)
-      return Sets.intersection(dictionary, literalSet).isEmpty() ? ROWS_CANNOT_MATCH : ROWS_MIGHT_MATCH;
+      // we need to find out the smaller set to iterate through
+      Set<T> smallerSet;
+      Set<T> biggerSet;
+
+      if (literalSet.size() < dictionary.size()) {
+        smallerSet = literalSet;
+        biggerSet = dictionary;
+      } else {
+        smallerSet = dictionary;
+        biggerSet = literalSet;
+      }
+
+      for (T e : smallerSet) {

Review comment:
       Is this equivalent to reversing the order of sets passed to `intersection`?
   
   ```java
   if (dictionary.size() > literalSet.size()) {
     return Sets.intersection(dictionary, literalSet).isEmpty() ? ROWS_CANNOT_MATCH : ROWS_MIGHT_MATCH;
   } else {
     return Sets.intersection(literalSet, dictionary).isEmpty() ? ROWS_CANNOT_MATCH : ROWS_MIGHT_MATCH;
   }
   ```
   
   I guess that this can return earlier if at least one value in the intersection is found.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] aokolnychyi commented on a change in pull request #1664: Parquet: Optimize IN predicates in ParquetDictionaryRowGroupFilter

Posted by GitBox <gi...@apache.org>.
aokolnychyi commented on a change in pull request #1664:
URL: https://github.com/apache/iceberg/pull/1664#discussion_r513584484



##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetDictionaryRowGroupFilter.java
##########
@@ -278,8 +278,27 @@ public Boolean or(Boolean leftResult, Boolean rightResult) {
 
       Set<T> dictionary = dict(id, ref.comparator());
 
-      // ROWS_CANNOT_MATCH if all values of the dictionary are not in the set (the intersection is empty)
-      return Sets.intersection(dictionary, literalSet).isEmpty() ? ROWS_CANNOT_MATCH : ROWS_MIGHT_MATCH;
+      // we need to find out the smaller set to iterate through
+      Set<T> smallerSet;
+      Set<T> biggerSet;
+
+      if (literalSet.size() < dictionary.size()) {
+        smallerSet = literalSet;
+        biggerSet = dictionary;
+      } else {
+        smallerSet = dictionary;
+        biggerSet = literalSet;
+      }
+
+      for (T e : smallerSet) {

Review comment:
       Calling `isEmpty` on `intersection` is equivalent to just calling `Collections$disjoint`. We may rely on the order of args but that seems fragile to me. There is no guarantee the internal implementation won't change.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] aokolnychyi commented on a change in pull request #1664: Parquet: Optimize IN predicates in ParquetDictionaryRowGroupFilter

Posted by GitBox <gi...@apache.org>.
aokolnychyi commented on a change in pull request #1664:
URL: https://github.com/apache/iceberg/pull/1664#discussion_r512213739



##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetDictionaryRowGroupFilter.java
##########
@@ -278,8 +278,27 @@ public Boolean or(Boolean leftResult, Boolean rightResult) {
 
       Set<T> dictionary = dict(id, ref.comparator());
 
-      // ROWS_CANNOT_MATCH if all values of the dictionary are not in the set (the intersection is empty)
-      return Sets.intersection(dictionary, literalSet).isEmpty() ? ROWS_CANNOT_MATCH : ROWS_MIGHT_MATCH;
+      // we need to find out the smaller set to iterate through
+      Set<T> smallerSet;
+      Set<T> biggerSet;
+
+      if (literalSet.size() < dictionary.size()) {
+        smallerSet = literalSet;
+        biggerSet = dictionary;
+      } else {
+        smallerSet = dictionary;
+        biggerSet = literalSet;
+      }
+
+      for (T e : smallerSet) {

Review comment:
       We could rely on `Collections$disjoint` here knowing how it behaves but I'd prefer to have full control here and be sure this logic does not change.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] aokolnychyi merged pull request #1664: Parquet: Optimize IN predicates in ParquetDictionaryRowGroupFilter

Posted by GitBox <gi...@apache.org>.
aokolnychyi merged pull request #1664:
URL: https://github.com/apache/iceberg/pull/1664


   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #1664: Parquet: Optimize IN predicates in ParquetDictionaryRowGroupFilter

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #1664:
URL: https://github.com/apache/iceberg/pull/1664#discussion_r513581060



##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetDictionaryRowGroupFilter.java
##########
@@ -278,8 +278,27 @@ public Boolean or(Boolean leftResult, Boolean rightResult) {
 
       Set<T> dictionary = dict(id, ref.comparator());
 
-      // ROWS_CANNOT_MATCH if all values of the dictionary are not in the set (the intersection is empty)
-      return Sets.intersection(dictionary, literalSet).isEmpty() ? ROWS_CANNOT_MATCH : ROWS_MIGHT_MATCH;
+      // we need to find out the smaller set to iterate through
+      Set<T> smallerSet;
+      Set<T> biggerSet;
+
+      if (literalSet.size() < dictionary.size()) {
+        smallerSet = literalSet;
+        biggerSet = dictionary;
+      } else {
+        smallerSet = dictionary;
+        biggerSet = literalSet;
+      }
+
+      for (T e : smallerSet) {

Review comment:
       Is this equivalent to reversing the order of sets passed to `intersection`?
   
   ```java
   if (dictionary.size() > literalSet.size()) {
     return Sets.intersection(dictionary, literalSet).isEmpty() ? ROWS_CANNOT_MATCH : ROWS_MIGHT_MATCH;
   } else {
     return Sets.intersection(literalSet, dictionary).isEmpty() ? ROWS_CANNOT_MATCH : ROWS_MIGHT_MATCH;
   }
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org