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/05/02 00:41:32 UTC

[GitHub] [iceberg] samredai opened a new pull request, #4678: Add a skeleton for the BuildPositionAccessors visitor

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

   This adds a skeleton visitor for the `BuildPositionAccessors` visitor and the following `# TODO` in the struct component of the visitor:
   ```
   # TODO: Populate the `self._index` dictionary where the key is the field ID and the value is an accessor for that field.
   #   The equivalent java logic can be found here: https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/Accessors.java#L213-L230
   ```
   The main reason for adding this now is to unblock the work on expressions visitors (for example PR #)


-- 
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] samredai commented on a diff in pull request #4678: Add a skeleton for the BuildPositionAccessors visitor

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


##########
python/src/iceberg/schema.py:
##########
@@ -471,3 +495,44 @@ def index_name_by_id(schema_or_type) -> Dict[int, str]:
     indexer = _IndexByName()
     visit(schema_or_type, indexer)
     return indexer.by_id()
+
+
+class _BuildPositionAccessors(SchemaVisitor[Dict[int, "Accessor"]]):
+    """A schema visitor for generating a field ID to accessor index"""
+
+    def __init__(self) -> None:
+        self._index: Dict[int, "Accessor"] = {}
+
+    def schema(self, schema, result: Dict[int, "Accessor"]) -> Dict[int, "Accessor"]:

Review Comment:
   Nice! We already have that import at the top of this file. I was getting `NameError: name 'Accessor' is not defined` but after your comment and playing with this a bit I realize it was only [this](https://github.com/apache/iceberg/pull/4678/files#diff-03d2c14d19e23634780ee3ccba4a37a5b5a06b0acd1d7c6a5e2a9f7c60da0c1bR500) single line that was causing it:
   ```py
   class _BuildPositionAccessors(SchemaVisitor[Dict[int, "Accessor"]]):
   ```
   I wonder if it's because that's a type for a generic? I just left that one there and changed `"Accessor"` to `Accessor` everywhere else, thanks @Fokko !



-- 
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 pull request #4678: Add a skeleton for the BuildPositionAccessors visitor

Posted by GitBox <gi...@apache.org>.
rdblue commented on PR #4678:
URL: https://github.com/apache/iceberg/pull/4678#issuecomment-1115251320

   Seems reasonable to me. Do you want to merge this right away, or are you planning to update it with an implementation?


-- 
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 #4678: Add a skeleton for the BuildPositionAccessors visitor

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


##########
python/src/iceberg/schema.py:
##########
@@ -19,7 +19,10 @@
 
 import sys
 from abc import ABC, abstractmethod
-from typing import Dict, Generic, Iterable, List, TypeVar
+from typing import TYPE_CHECKING, Dict, Generic, Iterable, List, TypeVar
+
+if TYPE_CHECKING:
+    from iceberg.expressions.base import Accessor

Review Comment:
   At that makes sense, thanks!



##########
python/src/iceberg/schema.py:
##########
@@ -19,7 +19,10 @@
 
 import sys
 from abc import ABC, abstractmethod
-from typing import Dict, Generic, Iterable, List, TypeVar
+from typing import TYPE_CHECKING, Dict, Generic, Iterable, List, TypeVar
+
+if TYPE_CHECKING:
+    from iceberg.expressions.base import Accessor

Review Comment:
   At that makes sense, thanks!



-- 
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] samredai commented on pull request #4678: Add a skeleton for the BuildPositionAccessors visitor

Posted by GitBox <gi...@apache.org>.
samredai commented on PR #4678:
URL: https://github.com/apache/iceberg/pull/4678#issuecomment-1115306099

   @rdblue this is good to merge now and then I'll rebase PR #4679 which should get that in a good state to merge. Thanks!


-- 
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 #4678: Add a skeleton for the BuildPositionAccessors visitor

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


-- 
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] samredai commented on a diff in pull request #4678: Add a skeleton for the BuildPositionAccessors visitor

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


##########
python/src/iceberg/schema.py:
##########
@@ -19,7 +19,10 @@
 
 import sys
 from abc import ABC, abstractmethod
-from typing import Dict, Generic, Iterable, List, TypeVar
+from typing import TYPE_CHECKING, Dict, Generic, Iterable, List, TypeVar
+
+if TYPE_CHECKING:
+    from iceberg.expressions.base import Accessor

Review Comment:
   `if TYPE_CHECKING` here is to avoid circular imports when using the class as a typehint (see docs [here](https://docs.python.org/3/library/typing.html#constant)). In summary, it's true when static type-checking is happening by mypy and false at runtime (avoiding any circular imports at runtime).



-- 
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 #4678: Add a skeleton for the BuildPositionAccessors visitor

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


##########
python/src/iceberg/schema.py:
##########
@@ -471,3 +495,44 @@ def index_name_by_id(schema_or_type) -> Dict[int, str]:
     indexer = _IndexByName()
     visit(schema_or_type, indexer)
     return indexer.by_id()
+
+
+class _BuildPositionAccessors(SchemaVisitor[Dict[int, "Accessor"]]):
+    """A schema visitor for generating a field ID to accessor index"""
+
+    def __init__(self) -> None:
+        self._index: Dict[int, "Accessor"] = {}
+
+    def schema(self, schema, result: Dict[int, "Accessor"]) -> Dict[int, "Accessor"]:

Review Comment:
   If we defer the evaluation of the annotations:
   ```python
   from __future__ import annotations
   ```
   Then we can just write
   ```suggestion
       def schema(self, schema, result: Dict[int, "Accessor"]) -> Dict[int, Accessor]:
   ```



##########
python/src/iceberg/schema.py:
##########
@@ -471,3 +495,44 @@ def index_name_by_id(schema_or_type) -> Dict[int, str]:
     indexer = _IndexByName()
     visit(schema_or_type, indexer)
     return indexer.by_id()
+
+
+class _BuildPositionAccessors(SchemaVisitor[Dict[int, "Accessor"]]):
+    """A schema visitor for generating a field ID to accessor index"""
+
+    def __init__(self) -> None:
+        self._index: Dict[int, "Accessor"] = {}
+
+    def schema(self, schema, result: Dict[int, "Accessor"]) -> Dict[int, "Accessor"]:
+        return self._index
+
+    def struct(self, struct, result: List[Dict[int, "Accessor"]]) -> Dict[int, "Accessor"]:
+        # TODO: Populate the `self._index` dictionary where the key is the field ID and the value is an accessor for that field.
+        #   The equivalent java logic can be found here: https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/Accessors.java#L213-L230
+        return self._index
+
+    def field(self, field: NestedField, result: Dict[int, "Accessor"]) -> Dict[int, "Accessor"]:
+        return self._index
+
+    def list(self, list_type: ListType, result: Dict[int, "Accessor"]) -> Dict[int, "Accessor"]:
+        return self._index
+
+    def map(
+        self, map_type: MapType, key_result: Dict[int, "Accessor"], value_result: Dict[int, "Accessor"]
+    ) -> Dict[int, "Accessor"]:
+        return self._index
+
+    def primitive(self, primitive: PrimitiveType) -> Dict[int, "Accessor"]:
+        return self._index
+
+
+def build_position_accessors(schema_or_type) -> Dict[int, "Accessor"]:

Review Comment:
   ```suggestion
   def build_position_accessors(schema_or_type: Schema | IcebergType) -> Dict[int, Accessor]:
   ```



##########
python/src/iceberg/schema.py:
##########
@@ -19,7 +19,10 @@
 
 import sys
 from abc import ABC, abstractmethod
-from typing import Dict, Generic, Iterable, List, TypeVar
+from typing import TYPE_CHECKING, Dict, Generic, Iterable, List, TypeVar
+
+if TYPE_CHECKING:
+    from iceberg.expressions.base import Accessor

Review Comment:
   I was curious about the circular import. Removing the guard doesn't give an error on my side. The guard doesn't do any harm, but it would be better to avoid any potential circular imports at all.



-- 
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] samredai commented on a diff in pull request #4678: Add a skeleton for the BuildPositionAccessors visitor

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


##########
python/src/iceberg/schema.py:
##########
@@ -19,7 +19,10 @@
 
 import sys
 from abc import ABC, abstractmethod
-from typing import Dict, Generic, Iterable, List, TypeVar
+from typing import TYPE_CHECKING, Dict, Generic, Iterable, List, TypeVar
+
+if TYPE_CHECKING:
+    from iceberg.expressions.base import Accessor

Review Comment:
   Sorry I forgot to mention that the circular import happens when PR #4679 is combined with this since that adds an import from schema in `expressions/base.py` so this is preemptive, specifically for [this](https://github.com/apache/iceberg/pull/4679/files#diff-47510d45242fa16200be79774cb6177b3084a1d363e15fde90940b3949a9eabaR23) line.



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