-
Notifications
You must be signed in to change notification settings - Fork 306
[Avro] Accept dict with only 'type': 'null'
as representation of null
#2109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Avro] Accept dict with only 'type': 'null'
as representation of null
#2109
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes sense, but i cant find a corresponding mention in the avro spec
cc @Fokko to chime in here
@@ -171,11 +171,11 @@ def _resolve_union( | |||
# This means that null has to come first: | |||
# https://avro.apache.org/docs/current/spec.html | |||
# type of the default value must match the first element of the union. | |||
if "null" != avro_types[0]: | |||
raise TypeError("Only null-unions are supported") | |||
if avro_types[0] != "null" and avro_types[0] != {'type': 'null'}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a test for this in
iceberg-python/tests/utils/test_schema_conversion.py
Lines 235 to 239 in 483d947
def test_resolve_union() -> None: | |
with pytest.raises(TypeError) as exc_info: | |
AvroSchemaConversion()._resolve_union(["null", "string", "long"]) | |
assert "Non-optional types aren't part of the Iceberg specification" in str(exc_info.value) |
The spec seems to indicate that this is valid: Right under
List of primitive types
And then below the list:
Which is why |
ty that makes sense, thanks for the pointer |
Looks like theres a linter issue, could you run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the syntax looks a bit weird, I agree that this is valid:

I agree with @kevinjqliu that a test would be a very good idea, since we're moving this part to rust somewhere in the not-so-distant future :)
This PR makes it so that a different serialization of the
null
type is accepted, this variation is produced byavro-c
(apache/avro
'sc
lang implementation)