Repository navigation
Backlog
Description
Follow-up from #4489, revisiting the discussion in #3801.
Java's PropertyUtil treats a property as unset only when its value is null, and parses every other value. The PyIceberg helpers still treat "" as unset, accept non-string values that Java never sees, and parse booleans differently.
| Input | Java | PyIceberg after #4489 |
|---|---|---|
property_as_int / property_as_float with "" |
throws NumberFormatException |
returns default |
property_as_int with False or 1.5 |
n/a, values are strings | 0 / 1 |
property_as_bool with "" |
false |
returns default |
property_as_bool with "1", "yes" or "on" |
false |
True |
property_as_bool with "abc" |
false |
raises ValueError |
get_first_property_value with "" for the first key |
no equivalent | skips to the next key |
- Treat only
Noneas unset. Useif (value := properties.get(property_name)) is not None:in all four helpers. An empty string then raisesValueErrorinproperty_as_intandproperty_as_float, where Java throwsNumberFormatException. Update thefor unset in (None, "")tests from Preserve falsy non-empty values in property helper functions #4489. - Parse the string form of the value. Use
int(str(value))andfloat(str(value)). Values likeFalseor1.5for an int property then raise instead of becoming0or1, which matches Java parsing the string. - Match
Boolean.parseBooleaninproperty_as_bool. Returnstr(value).lower() == "true"instead of callingstrtobool. Any other value, including"","1","yes"and typos, returnsFalsewithout raising. This silently changes"1","yes","on","y"and"t"fromTruetoFalse, so for one release, emit aDeprecationWarningwhenstrtobooland the new parsing disagree. Updatetest_property_as_bool_with_invalid_value. - Use
property_as_boolwherever a boolean property is read.catalog/sql.py(pool_pre_ping,init_catalog_tables, andechoapart from its"debug"value),io/fsspec.pyandio/pyarrow.py(s3.anonymous) callstrtobooldirectly, so they would keep the old parsing. - Only skip
Noneinget_first_property_value. Java has no equivalent. Java reads one key and checks for empty values where it uses them, for exampleStrings.isNullOrEmptyinAwsClientProperties#credentialsProvider. Return""instead of skipping to the next key, and check the callers inio/pyarrow.py,io/fsspec.py,catalog/glue.py,catalog/dynamodb.pyandcatalog/rest/__init__.py, so an empty credential still falls back to the default credential chain. - Use
Propertiesas the parameter type for all helpers. Preserve falsy non-empty values in property helper functions #4489 changedproperty_as_intandproperty_as_floatto takeMapping[str, Any]. - Fix the
*_with_invalid_valuetests. Theassert ... in str(exc.value)is inside thewith pytest.raises(...)block, so it never runs. Usepytest.raises(ValueError, match=...). - Mention the user-facing changes in the release notes. An empty string no longer means "unset", and boolean properties follow Java's parsing.
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Follow-ups for property helpers in pyiceberg/utils/properties.py[/-][+]Align property helpers in pyiceberg/utils/properties.py with Java's PropertyUtil[/+]