Skip to content

Commit e8b7fa6

Browse files
committed
Core: improve error for null schema types
1 parent e07296e commit e8b7fa6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pyiceberg/io/pyarrow.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,13 @@ def primitive(self, primitive: pa.DataType) -> PrimitiveType:
14351435
elif pa.types.is_null(primitive):
14361436
# PyArrow null type (pa.null()) is converted to Iceberg UnknownType
14371437
# UnknownType can be promoted to any primitive type in V3+ tables per the Iceberg spec
1438+
if self._format_version < 3:
1439+
field_path = ".".join(self._field_names) if self._field_names else "<root>"
1440+
raise ValueError(
1441+
"Null type (pa.null()) is not supported in Iceberg format version "
1442+
f"{self._format_version}. Field: {field_path}. "
1443+
"Use a concrete type (string, int, boolean, etc.) or set format-version=3."
1444+
)
14381445
return UnknownType()
14391446
elif isinstance(primitive, pa.UuidType):
14401447
return UUIDType()

tests/catalog/test_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ def test_convert_schema_if_needed(
207207
assert expected == catalog._convert_schema_if_needed(schema)
208208

209209

210+
def test_convert_schema_if_needed_rejects_null_type(catalog: InMemoryCatalog) -> None:
211+
schema = pa.schema([pa.field("n1", pa.null())])
212+
with pytest.raises(ValueError) as exc_info:
213+
catalog._convert_schema_if_needed(schema)
214+
message = str(exc_info.value)
215+
assert "Null type" in message
216+
assert "n1" in message
217+
assert "format-version=3" in message
218+
219+
210220
def test_create_table_pyarrow_schema(catalog: InMemoryCatalog, pyarrow_schema_simple_without_ids: pa.Schema) -> None:
211221
catalog.create_namespace(TEST_TABLE_NAMESPACE)
212222
table = catalog.create_table(

0 commit comments

Comments
 (0)