You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "barronw (via GitHub)" <gi...@apache.org> on 2024/12/12 01:54:58 UTC
[PR] fix: field id in name mapping should be optional [iceberg-python]
barronw opened a new pull request, #1426:
URL: https://github.com/apache/iceberg-python/pull/1426
Closes #1420.
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1890305553
##########
pyiceberg/table/name_mapping.py:
##########
@@ -49,9 +49,10 @@ def convert_null_to_empty_List(cls, v: Any) -> Any:
@model_serializer
def ser_model(self) -> Dict[str, Any]:
"""Set custom serializer to leave out the field when it is empty."""
+ field_id = {"field-id": self.field_id} if self.field_id is not None else {}
fields = {"fields": self.fields} if len(self.fields) > 0 else {}
return {
- "field-id": self.field_id,
+ **field_id,
"names": self.names,
**fields,
}
Review Comment:
More a style thing, I think it is a bit awkward to merge all the dicts, how about:
```python
serialized = {
"names": self.names
}
if self.field_id is not None:
serialized['field-id'] = self.field_id
if len(self.fields) > 0:
serialized['fields'] = fields
return serialized
```
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1888945215
##########
pyiceberg/table/name_mapping.py:
##########
@@ -232,7 +234,9 @@ def mapping(self, nm: NameMapping, field_results: List[MappedField]) -> List[Map
def fields(self, struct: List[MappedField], field_results: List[MappedField]) -> List[MappedField]:
reassignments: Dict[str, int] = {
- update.name: update.field_id for f in field_results if (update := self._updates.get(f.field_id))
+ update.name: update.field_id
+ for f in field_results
+ if f.field_id is not None and (update := self._updates.get(f.field_id))
Review Comment:
what is the rationale behind this change? Should we look at all the other places where `.field_id` is used?
##########
pyiceberg/table/name_mapping.py:
##########
@@ -333,8 +334,8 @@ def struct(self, struct: StructType, struct_partner: Optional[MappedField], fiel
return StructType(*field_results)
def field(self, field: NestedField, field_partner: Optional[MappedField], field_result: IcebergType) -> IcebergType:
- if field_partner is None:
- raise ValueError(f"Field missing from NameMapping: {'.'.join(self.current_path)}")
+ if field_partner is None or field_partner.field_id is None:
Review Comment:
I see `field_id` is a required field in `NestedField`. Without `field_partner.field_id is None`, type checker errors
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "barronw (via GitHub)" <gi...@apache.org>.
barronw commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1889379616
##########
pyiceberg/table/name_mapping.py:
##########
@@ -232,7 +234,9 @@ def mapping(self, nm: NameMapping, field_results: List[MappedField]) -> List[Map
def fields(self, struct: List[MappedField], field_results: List[MappedField]) -> List[MappedField]:
reassignments: Dict[str, int] = {
- update.name: update.field_id for f in field_results if (update := self._updates.get(f.field_id))
+ update.name: update.field_id
+ for f in field_results
+ if f.field_id is not None and (update := self._updates.get(f.field_id))
Review Comment:
Yes, changing the API of `updating_mapping` probably requires larger discussion.
##########
pyiceberg/table/name_mapping.py:
##########
@@ -232,7 +234,9 @@ def mapping(self, nm: NameMapping, field_results: List[MappedField]) -> List[Map
def fields(self, struct: List[MappedField], field_results: List[MappedField]) -> List[MappedField]:
reassignments: Dict[str, int] = {
- update.name: update.field_id for f in field_results if (update := self._updates.get(f.field_id))
+ update.name: update.field_id
+ for f in field_results
+ if f.field_id is not None and (update := self._updates.get(f.field_id))
Review Comment:
Yes, also changing the API of `updating_mapping` probably requires larger discussion.
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#issuecomment-2541812934
@barronw looks like theres a linter issue, could you try to run `make lint`?
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "barronw (via GitHub)" <gi...@apache.org>.
barronw commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1887662401
##########
pyiceberg/table/name_mapping.py:
##########
@@ -333,8 +334,8 @@ def struct(self, struct: StructType, struct_partner: Optional[MappedField], fiel
return StructType(*field_results)
def field(self, field: NestedField, field_partner: Optional[MappedField], field_result: IcebergType) -> IcebergType:
- if field_partner is None:
- raise ValueError(f"Field missing from NameMapping: {'.'.join(self.current_path)}")
+ if field_partner is None or field_partner.field_id is None:
Review Comment:
This should just be a type check since `NestedField` expects a field ID below. The field partner is looked up by field ID before being passed into this method.
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1889378149
##########
pyiceberg/table/name_mapping.py:
##########
@@ -232,7 +234,9 @@ def mapping(self, nm: NameMapping, field_results: List[MappedField]) -> List[Map
def fields(self, struct: List[MappedField], field_results: List[MappedField]) -> List[MappedField]:
reassignments: Dict[str, int] = {
- update.name: update.field_id for f in field_results if (update := self._updates.get(f.field_id))
+ update.name: update.field_id
+ for f in field_results
+ if f.field_id is not None and (update := self._updates.get(f.field_id))
Review Comment:
I see, is this change also due to the type checker?
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1887165186
##########
pyiceberg/table/name_mapping.py:
##########
Review Comment:
In `__str__` https://github.com/apache/iceberg-python/pull/1426/files#diff-55b6571bab1c711ef0bc63727c189fa6cb3ef5b38f0e6c4ade09f059fbc9960dR69
`(str(self.field_id) or "?")`, `str(None)` is `"None"`, we probably want `?` instead
##########
pyiceberg/table/name_mapping.py:
##########
@@ -333,8 +334,8 @@ def struct(self, struct: StructType, struct_partner: Optional[MappedField], fiel
return StructType(*field_results)
def field(self, field: NestedField, field_partner: Optional[MappedField], field_result: IcebergType) -> IcebergType:
- if field_partner is None:
- raise ValueError(f"Field missing from NameMapping: {'.'.join(self.current_path)}")
+ if field_partner is None or field_partner.field_id is None:
Review Comment:
I'm curious about this change, why do we need to check for `field_partner.field_id`
##########
tests/table/test_name_mapping.py:
##########
@@ -109,6 +109,21 @@ def test_json_mapped_field_no_names_deserialization() -> None:
assert MappedField(field_id=1, names=[]) == MappedField.model_validate_json(mapped_field_with_null_fields)
+def test_json_mapped_field_no_field_id_deserialization() -> None:
+ mapped_field = """{
+ "names": []
+ }
+ """
+ assert MappedField(field_id=None, names=[]) == MappedField.model_validate_json(mapped_field)
Review Comment:
nit: also test omitting the `field_id=None`
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#issuecomment-2553046141
Thanks for fixing this @barronw and thanks for the review @kevinjqliu
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko merged PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "barronw (via GitHub)" <gi...@apache.org>.
barronw commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1889308898
##########
pyiceberg/table/name_mapping.py:
##########
@@ -232,7 +234,9 @@ def mapping(self, nm: NameMapping, field_results: List[MappedField]) -> List[Map
def fields(self, struct: List[MappedField], field_results: List[MappedField]) -> List[MappedField]:
reassignments: Dict[str, int] = {
- update.name: update.field_id for f in field_results if (update := self._updates.get(f.field_id))
+ update.name: update.field_id
+ for f in field_results
+ if f.field_id is not None and (update := self._updates.get(f.field_id))
Review Comment:
The `update_mapping` API doesn't currently support changes to mappings without a field ID since `updates` is typed with `Dict[int, NestedField]`.
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "barronw (via GitHub)" <gi...@apache.org>.
barronw commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1889379616
##########
pyiceberg/table/name_mapping.py:
##########
@@ -232,7 +234,9 @@ def mapping(self, nm: NameMapping, field_results: List[MappedField]) -> List[Map
def fields(self, struct: List[MappedField], field_results: List[MappedField]) -> List[MappedField]:
reassignments: Dict[str, int] = {
- update.name: update.field_id for f in field_results if (update := self._updates.get(f.field_id))
+ update.name: update.field_id
+ for f in field_results
+ if f.field_id is not None and (update := self._updates.get(f.field_id))
Review Comment:
Yes, also changing the API of `updating_mapping` probably requires a larger discussion.
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1889384130
##########
pyiceberg/table/name_mapping.py:
##########
@@ -232,7 +234,9 @@ def mapping(self, nm: NameMapping, field_results: List[MappedField]) -> List[Map
def fields(self, struct: List[MappedField], field_results: List[MappedField]) -> List[MappedField]:
reassignments: Dict[str, int] = {
- update.name: update.field_id for f in field_results if (update := self._updates.get(f.field_id))
+ update.name: update.field_id
+ for f in field_results
+ if f.field_id is not None and (update := self._updates.get(f.field_id))
Review Comment:
thanks for the explanation! cc @Fokko / @sungwy for another set of eyes
--
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
Re: [PR] fix: field id in name mapping should be optional [iceberg-python]
Posted by "barronw (via GitHub)" <gi...@apache.org>.
barronw commented on code in PR #1426:
URL: https://github.com/apache/iceberg-python/pull/1426#discussion_r1890958338
##########
pyiceberg/table/name_mapping.py:
##########
@@ -49,9 +49,10 @@ def convert_null_to_empty_List(cls, v: Any) -> Any:
@model_serializer
def ser_model(self) -> Dict[str, Any]:
"""Set custom serializer to leave out the field when it is empty."""
+ field_id = {"field-id": self.field_id} if self.field_id is not None else {}
fields = {"fields": self.fields} if len(self.fields) > 0 else {}
return {
- "field-id": self.field_id,
+ **field_id,
"names": self.names,
**fields,
}
Review Comment:
Updated, needed to reorder fields in the tests.
##########
pyiceberg/table/name_mapping.py:
##########
@@ -49,9 +49,10 @@ def convert_null_to_empty_List(cls, v: Any) -> Any:
@model_serializer
def ser_model(self) -> Dict[str, Any]:
"""Set custom serializer to leave out the field when it is empty."""
+ field_id = {"field-id": self.field_id} if self.field_id is not None else {}
fields = {"fields": self.fields} if len(self.fields) > 0 else {}
return {
- "field-id": self.field_id,
+ **field_id,
"names": self.names,
**fields,
}
Review Comment:
Updated, needed to also reorder fields in the 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.
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