Skip to content

Commit 2b6bad2

Browse files
committed
Comments
1 parent 19a3e48 commit 2b6bad2

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

pyiceberg/conversions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,12 @@ def _(_: StringType, val: str) -> str:
563563
def _(t: FixedType, val: Union[str, bytes]) -> bytes:
564564
"""JSON hexadecimal encoded string into bytes."""
565565
if isinstance(val, str):
566-
b = codecs.decode(val.encode(UTF8), "hex")
566+
val = codecs.decode(val.encode(UTF8), "hex")
567567

568-
if len(t) != len(b):
569-
raise ValueError(f"FixedType has length {len(t)}, which is different from the value: {len(b)}")
568+
if len(t) != len(val):
569+
raise ValueError(f"FixedType has length {len(t)}, which is different from the value: {len(val)}")
570570

571-
return b
572-
else:
573-
return val
571+
return val
574572

575573

576574
@from_json.register(BinaryType)

tests/integration/test_rest_schema.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ def test_add_required_column(catalog: Catalog) -> None:
10951095

10961096
@pytest.mark.integration
10971097
@pytest.mark.parametrize(
1098-
"iceberg_type, default_value, write_default",
1098+
"iceberg_type, initial_default, write_default",
10991099
[
11001100
(BooleanType(), True, False),
11011101
(IntegerType(), 123, 456),
@@ -1119,25 +1119,33 @@ def test_add_required_column(catalog: Catalog) -> None:
11191119
],
11201120
)
11211121
def test_initial_default_all_columns(
1122-
catalog: Catalog, iceberg_type: PrimitiveType, default_value: Any, write_default: Any
1122+
catalog: Catalog, iceberg_type: PrimitiveType, initial_default: Any, write_default: Any
11231123
) -> None:
11241124
# Round trips all the types through the rest catalog to check the serialization
11251125
table = _create_table_with_schema(catalog, Schema(), properties={TableProperties.FORMAT_VERSION: 3})
11261126

11271127
tx = table.update_schema()
1128-
tx.add_column(path="data", field_type=iceberg_type, required=True, default_value=default_value)
1128+
tx.add_column(path="data", field_type=iceberg_type, required=True, default_value=initial_default)
1129+
tx.add_column(path="nested", field_type=StructType(), required=False)
11291130
tx.commit()
11301131

1131-
field = table.schema().find_field(1)
1132-
assert field.initial_default == default_value
1133-
assert field.write_default == default_value
1132+
tx = table.update_schema()
1133+
tx.add_column(path=("nested", "data"), field_type=iceberg_type, required=True, default_value=initial_default)
1134+
tx.commit()
1135+
1136+
for field_id in [1, 3]:
1137+
field = table.schema().find_field(field_id)
1138+
assert field.initial_default == initial_default
1139+
assert field.write_default == initial_default
11341140

11351141
with table.update_schema() as tx:
11361142
tx.set_default_value("data", write_default)
1143+
tx.set_default_value(("nested", "data"), write_default)
11371144

1138-
field = table.schema().find_field(1)
1139-
assert field.initial_default == default_value
1140-
assert field.write_default == write_default
1145+
for field_id in [1, 3]:
1146+
field = table.schema().find_field(field_id)
1147+
assert field.initial_default == initial_default
1148+
assert field.write_default == write_default
11411149

11421150

11431151
@pytest.mark.integration

0 commit comments

Comments
 (0)