-
Notifications
You must be signed in to change notification settings - Fork 414
Adding promotion for UnknownType per V3+ spec #2155
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| from pyiceberg.expressions.literals import literal | ||
| from pyiceberg.io.pyarrow import ( | ||
| UnsupportedPyArrowTypeException, | ||
| _check_pyarrow_schema_compatible, | ||
| _ConvertToArrowSchema, | ||
| _ConvertToIceberg, | ||
| _ConvertToIcebergWithoutIDs, | ||
|
|
@@ -313,6 +314,28 @@ def test_pyarrow_dictionary_encoded_type_to_iceberg(value_type: pa.DataType, exp | |
| assert visit_pyarrow(pyarrow_dict, _ConvertToIceberg()) == expected_result | ||
|
|
||
|
|
||
| def test_schema_check_null_column(table_schema_simple: Schema) -> None: | ||
| pyarrow_schema: pa.Schema = schema_to_pyarrow(table_schema_simple) | ||
| new_field = pyarrow_schema.field(0).with_type(pa.null()) # Make the optional string field null for testing | ||
| pyarrow_schema = pyarrow_schema.set(0, new_field) | ||
| assert pyarrow_schema.field(0).type == pa.null() | ||
| _check_pyarrow_schema_compatible(table_schema_simple, pyarrow_schema) | ||
|
|
||
|
|
||
| def test_schema_conversion_null_column(table_schema_simple: Schema) -> None: | ||
| pyarrow_schema: pa.Schema = schema_to_pyarrow(table_schema_simple) | ||
| new_field = pyarrow_schema.field(2).with_type(pa.null()) # Make the optional boolean field null for testing | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about creating a new schema with just a field with a NestedType instead? I don't think we want to re-assign fields as that makes the test harder te read.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I can make a new schema. I think I was just trying to get it working and forgot to clean this up 😀 |
||
| pyarrow_schema = pyarrow_schema.set(2, new_field) | ||
| assert pyarrow_schema.field(2).type == pa.null() | ||
| actual = str(pyarrow_to_schema(pyarrow_schema)) | ||
| expected = """table { | ||
| 1: foo: optional string | ||
| 2: bar: required int | ||
| 3: baz: optional unknown | ||
| }""" | ||
| assert actual == expected | ||
|
|
||
|
|
||
| def test_round_schema_conversion_simple(table_schema_simple: Schema) -> None: | ||
| actual = str(pyarrow_to_schema(schema_to_pyarrow(table_schema_simple))) | ||
| expected = """table { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
If I read the spec carefully, I think it only allows for promoting to primitive types:
So, it cannot be promoted to a
{List,Map,Struct}Type.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.
I interpreted this as promotions available for a primitive type rather than promotions to a primitive type. i.e. UnknownType is a primitive type and these are the types it can be promoted to. It should be easy enough to change, so I'm fine either way. But, to me it would make sense that if a
{List,Map,Struct}Typefield is nullable and anullPyArrow field is being evaluated for compatibility, that evaluation should succeed. What are your thoughts?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.
I think we need to extend this logic a bit: