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 2019/10/29 20:05:11 UTC

[GitHub] [incubator-iceberg] rdblue commented on a change in pull request #544: [python] Adding parquet package which contains classes necessary for …

rdblue commented on a change in pull request #544: [python] Adding parquet package which contains classes necessary for …
URL: https://github.com/apache/incubator-iceberg/pull/544#discussion_r340297283
 
 

 ##########
 File path: python/iceberg/parquet/parquet_rowgroup_evaluator.py
 ##########
 @@ -0,0 +1,236 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from iceberg.api.expressions import Binder, Expressions, ExpressionVisitors
+from iceberg.api.types import Conversions
+
+
+class ParquetRowgroupEvaluator():
+    """
+    Handles Reading a parquet file for a given start to end range.  Also, enforces
+    the projected iceberg schema on the read data.  This may involve selectively reading
+    columns, remapping column names, re-arranging the projection ordering, and possibly
+    adding null columns
+
+    Parameters
+    ----------
+    schema : iceberg.api.Schema
+        An iceberg schema to use for binding the predicate
+    unbound : iceberg.api.expressions.UnboundPredicate
+        The unbound predicate to evaluate
+    start : int
+        The start index of the assigned reader
+    end : int
+        The end-index of the assigned reader
+    """
+    def __init__(self, schema, unbound, start, end):
+        self.schema = schema
+        self.struct = schema.as_struct()
+
+        self.expr = None if unbound is None else Binder.bind(self.struct, Expressions.rewrite_not(unbound))
+        self.start = start
+        self.end = end
+        self._visitors = None
+
+    def _visitor(self):
+        if self._visitors is None:
+            self._visitors = ParquetRowgroupEvalVisitor(self.expr, self.schema, self.struct,
+                                                        self.start, self.end)
+
+        return self._visitors
+
+    def eval(self, row_group):
+        return self._visitor().eval(row_group)
+
+
+class ParquetRowgroupEvalVisitor(ExpressionVisitors.BoundExpressionVisitor):
+    ROWS_MIGHT_MATCH = True
+    ROWS_CANNOT_MATCH = False
+
+    def __init__(self, expr, schema, struct, start, end):
+        self.expr = expr
+        self.schema = schema
+        self.struct = struct
+        self.start = start
+        self.end = end
+        self.lower_bounds = None
+        self.upper_bounds = None
+        self.midpoint = None
+
+    def eval(self, row_group):
+        """
+        Returns a boolean that determines if the given row-group may contain rows
+        for the assigned predicate and read-range[start, end]
+
+        Parameters
+        ----------
+        row_group : fastparquet.parquet_thrift.parquet.ttypes.RowGroup
 
 Review comment:
   This is the problem that @xhochy identified. We use a Parquet version based on 1.9, with a fix and an additional version range where we trust the file stats.
   
   I'm going to be rebasing on 1.10.1 soon, which should fix this problem for tests.

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


With regards,
Apache Git Services

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