Skip to content

Commit

Permalink
Lowercase bool values in table properties (apache#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
soumya-ghosh authored Jul 13, 2024
1 parent b11cdb5 commit 3f44dfe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyiceberg/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def transform_dict_value_to_str(dict: Dict[str, Any]) -> Dict[str, str]:
for key, value in dict.items():
if value is None:
raise ValueError(f"None type is not a supported value in properties: {key}")
return {k: str(v) for k, v in dict.items()}
return {k: str(v).lower() if isinstance(v, bool) else str(v) for k, v in dict.items()}


def _parse_decimal_type(decimal: Any) -> Tuple[int, int]:
Expand Down
9 changes: 6 additions & 3 deletions tests/cli/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def mock_datetime_now(monkeypatch: pytest.MonkeyPatch) -> None:
NestedField(3, "z", LongType(), required=True),
)
TEST_TABLE_PARTITION_SPEC = PartitionSpec(PartitionField(name="x", transform=IdentityTransform(), source_id=1, field_id=1000))
TEST_TABLE_PROPERTIES = {"read.split.target.size": "134217728"}
TEST_TABLE_PROPERTIES = {"read.split.target.size": "134217728", "write.parquet.bloom-filter-enabled.column.x": True}
TEST_TABLE_UUID = uuid.UUID("d20125c8-7284-442c-9aea-15fee620737c")
TEST_TIMESTAMP = 1602638573874
MOCK_ENVIRONMENT = {"PYICEBERG_CATALOG__PRODUCTION__URI": "test://doesnotexist"}
Expand Down Expand Up @@ -367,7 +367,10 @@ def test_properties_get_table(catalog: InMemoryCatalog) -> None:
runner = CliRunner()
result = runner.invoke(run, ["properties", "get", "table", "default.my_table"])
assert result.exit_code == 0
assert result.output == "read.split.target.size 134217728\n"
assert (
result.output
== "read.split.target.size 134217728\nwrite.parquet.bloom-filter-enabled.column.x true \n"
)


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


def test_json_properties_get_table_specific_property(catalog: InMemoryCatalog) -> None:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
TimeType,
UUIDType,
strtobool,
transform_dict_value_to_str,
)

non_parameterized_types = [
Expand Down Expand Up @@ -649,3 +650,14 @@ def test_strtobool() -> None:
for val in invalid_values:
with pytest.raises(ValueError, match=f"Invalid truth value: {val!r}"):
strtobool(val)


def test_transform_dict_value_to_str() -> None:
input_dict = {"key1": 1, "key2": 2.0, "key3": "3", "key4: ": True, "key5": False}
expected_dict = {"key1": "1", "key2": "2.0", "key3": "3", "key4: ": "true", "key5": "false"}
# valid values
assert transform_dict_value_to_str(input_dict) == expected_dict
# Null value not allowed, should raise ValueError
input_dict["key6"] = None
with pytest.raises(ValueError, match="None type is not a supported value in properties: key6"):
transform_dict_value_to_str(input_dict)

0 comments on commit 3f44dfe

Please sign in to comment.