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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]