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 2022/10/12 10:45:06 UTC

[GitHub] [iceberg] Fokko opened a new pull request, #5966: Python: Implement select

Fokko opened a new pull request, #5966:
URL: https://github.com/apache/iceberg/pull/5966

   So we can select a subset of the fields in a schema


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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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 diff in pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #5966:
URL: https://github.com/apache/iceberg/pull/5966#discussion_r994988767


##########
python/tests/test_schema.py:
##########
@@ -671,3 +672,24 @@ def test_prune_columns_struct_in_map_full():
 def test_prune_columns_select_original_schema(table_schema_nested: Schema):
     ids = set(range(table_schema_nested.highest_field_id))
     assert prune_columns(table_schema_nested, ids, True) == table_schema_nested
+
+
+def test_schema_select(table_schema_nested: Schema):
+    assert table_schema_nested.select("bar", "baz") == Schema(
+        NestedField(field_id=2, name="bar", field_type=IntegerType(), required=True),
+        NestedField(field_id=3, name="baz", field_type=BooleanType(), required=False),
+        schema_id=1,
+        identifier_field_ids=[1],

Review Comment:
   Minor: Should this be updated? This schema doesn't have all of the identifier field IDs, so maybe we should clear the identifier field ID list?



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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 diff in pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #5966:
URL: https://github.com/apache/iceberg/pull/5966#discussion_r994987249


##########
python/pyiceberg/exceptions.py:
##########
@@ -82,3 +82,7 @@ class NoSuchPropertyException(Exception):
 
 class NotInstalledError(Exception):
     """When an optional dependency is not installed"""
+
+
+class ColumnNotFoundError(Exception):
+    """When selecting a column that doesn't exist"""

Review Comment:
   In Java, we just throw IllegalArgumentException (equivalent to ValueError, I think) when something can't be 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.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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 diff in pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #5966:
URL: https://github.com/apache/iceberg/pull/5966#discussion_r994989319


##########
python/pyiceberg/scan.py:
##########
@@ -0,0 +1,76 @@
+# 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 typing import Optional, Union
+
+from pyiceberg.expressions.base import BooleanExpression
+from pyiceberg.schema import Schema
+from pyiceberg.table import Snapshot, Table
+
+
+class TableScan:

Review Comment:
   Can we move this to a separate PR? I'm not sure why it is in a PR that is adding `select` support.



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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] Fokko commented on a diff in pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
Fokko commented on code in PR #5966:
URL: https://github.com/apache/iceberg/pull/5966#discussion_r995553683


##########
python/tests/test_schema.py:
##########
@@ -671,3 +672,24 @@ def test_prune_columns_struct_in_map_full():
 def test_prune_columns_select_original_schema(table_schema_nested: Schema):
     ids = set(range(table_schema_nested.highest_field_id))
     assert prune_columns(table_schema_nested, ids, True) == table_schema_nested
+
+
+def test_schema_select(table_schema_nested: Schema):
+    assert table_schema_nested.select("bar", "baz") == Schema(
+        NestedField(field_id=2, name="bar", field_type=IntegerType(), required=True),
+        NestedField(field_id=3, name="baz", field_type=BooleanType(), required=False),
+        schema_id=1,
+        identifier_field_ids=[1],

Review Comment:
   Great catch, I'll now take the intersect of the `identifier_field_ids` and the IDs of the fields



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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] Fokko commented on a diff in pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
Fokko commented on code in PR #5966:
URL: https://github.com/apache/iceberg/pull/5966#discussion_r995513767


##########
python/pyiceberg/scan.py:
##########
@@ -0,0 +1,76 @@
+# 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 typing import Optional, Union
+
+from pyiceberg.expressions.base import BooleanExpression
+from pyiceberg.schema import Schema
+from pyiceberg.table import Snapshot, Table
+
+
+class TableScan:

Review Comment:
   Sure



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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] Fokko commented on a diff in pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
Fokko commented on code in PR #5966:
URL: https://github.com/apache/iceberg/pull/5966#discussion_r995513590


##########
python/pyiceberg/exceptions.py:
##########
@@ -82,3 +82,7 @@ class NoSuchPropertyException(Exception):
 
 class NotInstalledError(Exception):
     """When an optional dependency is not installed"""
+
+
+class ColumnNotFoundError(Exception):
+    """When selecting a column that doesn't exist"""

Review Comment:
   I figured this would be a nice one to add since it is very user facing. We're throwing a lot of `ValueError`'s already 😱 



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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 diff in pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #5966:
URL: https://github.com/apache/iceberg/pull/5966#discussion_r1002151896


##########
python/pyiceberg/schema.py:
##########
@@ -800,7 +800,11 @@ def primitive(self, primitive: PrimitiveType) -> PrimitiveType:
 
 def prune_columns(schema: Schema, selected: Set[int], select_full_types: bool = True) -> Schema:
     result = visit(schema.as_struct(), _PruneColumnsVisitor(selected, select_full_types))
-    return Schema(*(result or StructType()).fields, schema_id=schema.schema_id, identifier_field_ids=schema.identifier_field_ids)
+    return Schema(
+        *(result or StructType()).fields,
+        schema_id=schema.schema_id,
+        identifier_field_ids=list(selected.intersection(schema.identifier_field_ids)),

Review Comment:
   I don't think `intersection` is correct. The identifier field IDs are the set of fields that make a unique key. The resulting schema either has the same identifier fields (i.e. the same key) or doesn't have a key at all. I don't think it should ever have a different identifier/key.
   
   For example, if you have a table with identifier fields `first_name` and `last_name` and you project `first_name`, then the resulting schema should not have identifier fields set because just `first_name` would not really be a unique identifier for the projected records.
   
   I think this should be this:
   ```
   identifier_field_ids=schema.identifier_field_ids if all(id in selected for id in schema.identifier_field_ids) else []
   ```
   
   Looks like Java just drops identifier field IDs, which is okay too.



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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 diff in pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #5966:
URL: https://github.com/apache/iceberg/pull/5966#discussion_r1002151896


##########
python/pyiceberg/schema.py:
##########
@@ -800,7 +800,11 @@ def primitive(self, primitive: PrimitiveType) -> PrimitiveType:
 
 def prune_columns(schema: Schema, selected: Set[int], select_full_types: bool = True) -> Schema:
     result = visit(schema.as_struct(), _PruneColumnsVisitor(selected, select_full_types))
-    return Schema(*(result or StructType()).fields, schema_id=schema.schema_id, identifier_field_ids=schema.identifier_field_ids)
+    return Schema(
+        *(result or StructType()).fields,
+        schema_id=schema.schema_id,
+        identifier_field_ids=list(selected.intersection(schema.identifier_field_ids)),

Review Comment:
   I don't think `intersection` is correct. The identifier field IDs are the set of fields that make a unique key. The resulting schema either has the same identifier fields (i.e. the same key) or doesn't have a key at all. I don't think it should ever have a different identifier/key.
   
   So I think this should be `schema.identifier_field_ids if all(id in selected for id in schema.identifier_field_ids) else []`.



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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 merged pull request #5966: Python: Implement select

Posted by GitBox <gi...@apache.org>.
rdblue merged PR #5966:
URL: https://github.com/apache/iceberg/pull/5966


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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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