Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyiceberg/table/name_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def field(self, field: NestedField, field_partner: MappedField | None, field_res
required=field.required,
doc=field.doc,
initial_default=field.initial_default,
initial_write=field.write_default,
write_default=field.write_default,
)

def list(self, list_type: ListType, list_partner: MappedField | None, element_result: IcebergType) -> IcebergType:
Expand Down
19 changes: 19 additions & 0 deletions tests/table/test_name_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,22 @@ def test_mapping_using_by_visitor(table_schema_nested: Schema, table_name_mappin
),
)
assert apply_name_mapping(schema_without_ids, table_name_mapping_nested).fields == table_schema_nested.fields


def test_mapping_preserves_field_defaults() -> None:
schema_without_ids = Schema(
NestedField(
field_id=0,
name="foo",
field_type=StringType(),
required=False,
initial_default="init",
write_default="write",
),
)
name_mapping = NameMapping([MappedField(field_id=1, names=["foo"])])

mapped_field = apply_name_mapping(schema_without_ids, name_mapping).fields[0]

assert mapped_field.initial_default == "init"
assert mapped_field.write_default == "write"