Skip to content

Commit 3f44dfe

Browse files
authored
Lowercase bool values in table properties (apache#924)
1 parent b11cdb5 commit 3f44dfe

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

pyiceberg/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def transform_dict_value_to_str(dict: Dict[str, Any]) -> Dict[str, str]:
6767
for key, value in dict.items():
6868
if value is None:
6969
raise ValueError(f"None type is not a supported value in properties: {key}")
70-
return {k: str(v) for k, v in dict.items()}
70+
return {k: str(v).lower() if isinstance(v, bool) else str(v) for k, v in dict.items()}
7171

7272

7373
def _parse_decimal_type(decimal: Any) -> Tuple[int, int]:

tests/cli/test_console.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def mock_datetime_now(monkeypatch: pytest.MonkeyPatch) -> None:
8383
NestedField(3, "z", LongType(), required=True),
8484
)
8585
TEST_TABLE_PARTITION_SPEC = PartitionSpec(PartitionField(name="x", transform=IdentityTransform(), source_id=1, field_id=1000))
86-
TEST_TABLE_PROPERTIES = {"read.split.target.size": "134217728"}
86+
TEST_TABLE_PROPERTIES = {"read.split.target.size": "134217728", "write.parquet.bloom-filter-enabled.column.x": True}
8787
TEST_TABLE_UUID = uuid.UUID("d20125c8-7284-442c-9aea-15fee620737c")
8888
TEST_TIMESTAMP = 1602638573874
8989
MOCK_ENVIRONMENT = {"PYICEBERG_CATALOG__PRODUCTION__URI": "test://doesnotexist"}
@@ -367,7 +367,10 @@ def test_properties_get_table(catalog: InMemoryCatalog) -> None:
367367
runner = CliRunner()
368368
result = runner.invoke(run, ["properties", "get", "table", "default.my_table"])
369369
assert result.exit_code == 0
370-
assert result.output == "read.split.target.size 134217728\n"
370+
assert (
371+
result.output
372+
== "read.split.target.size 134217728\nwrite.parquet.bloom-filter-enabled.column.x true \n"
373+
)
371374

372375

373376
def test_properties_get_table_specific_property(catalog: InMemoryCatalog) -> None:
@@ -763,7 +766,7 @@ def test_json_properties_get_table(catalog: InMemoryCatalog) -> None:
763766
runner = CliRunner()
764767
result = runner.invoke(run, ["--output=json", "properties", "get", "table", "default.my_table"])
765768
assert result.exit_code == 0
766-
assert result.output == """{"read.split.target.size": "134217728"}\n"""
769+
assert result.output == """{"read.split.target.size": "134217728", "write.parquet.bloom-filter-enabled.column.x": "true"}\n"""
767770

768771

769772
def test_json_properties_get_table_specific_property(catalog: InMemoryCatalog) -> None:

tests/test_types.py

+12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
TimeType,
4545
UUIDType,
4646
strtobool,
47+
transform_dict_value_to_str,
4748
)
4849

4950
non_parameterized_types = [
@@ -649,3 +650,14 @@ def test_strtobool() -> None:
649650
for val in invalid_values:
650651
with pytest.raises(ValueError, match=f"Invalid truth value: {val!r}"):
651652
strtobool(val)
653+
654+
655+
def test_transform_dict_value_to_str() -> None:
656+
input_dict = {"key1": 1, "key2": 2.0, "key3": "3", "key4: ": True, "key5": False}
657+
expected_dict = {"key1": "1", "key2": "2.0", "key3": "3", "key4: ": "true", "key5": "false"}
658+
# valid values
659+
assert transform_dict_value_to_str(input_dict) == expected_dict
660+
# Null value not allowed, should raise ValueError
661+
input_dict["key6"] = None
662+
with pytest.raises(ValueError, match="None type is not a supported value in properties: key6"):
663+
transform_dict_value_to_str(input_dict)

0 commit comments

Comments
 (0)