You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by gi...@apache.org on 2026/09/24 20:47:51 UTC

(iceberg-python) branch gh-readonly-queue/main/pr-3899-07099ee180db9a1e89fc55d21bcac21b7a33e2f9 created (now ebbc0ba3e)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-3899-07099ee180db9a1e89fc55d21bcac21b7a33e2f9
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


      at ebbc0ba3e Register `to_bytes` for `UnknownType` (#3899)

This branch includes the following new commits:

     new ebbc0ba3e Register `to_bytes` for `UnknownType` (#3899)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(iceberg-python) 01/01: Register `to_bytes` for `UnknownType` (#3899)

Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-3899-07099ee180db9a1e89fc55d21bcac21b7a33e2f9
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git

commit ebbc0ba3e4c633179b4069a70a8f9a4453e75d88
Author: Alex Stephen <13...@users.noreply.github.com>
AuthorDate: Thu Sep 24 20:15:27 2026 +0000

    Register `to_bytes` for `UnknownType` (#3899)
    
    `from_bytes` and `partition_to_py` both handle `UnknownType`, but
    `to_bytes` did not, so serializing an unknown value fell through to the
    dispatch fallback and raised. Unknown values are always null and have no
    binary representation, so return None, matching `Conversions.toByteBuffer`
    in the Java implementation.
    
    The JSON single-value entry points are deliberately left unregistered:
    the spec defines no JSON representation for unknown, since a non-null
    initial-default or write-default is invalid for the type.
---
 pyiceberg/conversions.py  |  6 ++++++
 tests/test_conversions.py | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/pyiceberg/conversions.py b/pyiceberg/conversions.py
index 268cbb93e..6dd964f43 100644
--- a/pyiceberg/conversions.py
+++ b/pyiceberg/conversions.py
@@ -321,6 +321,12 @@ def _(primitive_type: DecimalType, value: Decimal) -> bytes:
     return decimal_to_bytes(value)
 
 
+@to_bytes.register(UnknownType)
+def _(_: UnknownType, value: Any) -> None:
+    """Return None since the unknown type has no binary representation."""
+    return None
+
+
 @singledispatch  # type: ignore
 def from_bytes(primitive_type: PrimitiveType, b: bytes) -> L:  # type: ignore
     """Convert bytes to a built-in python value.
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index ec04d393c..e786ae068 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -109,6 +109,7 @@ from pyiceberg.types import (
     TimestamptzNanoType,
     TimestamptzType,
     TimeType,
+    UnknownType,
     UUIDType,
 )
 
@@ -606,3 +607,20 @@ def test_json_single_serialization(primitive_type: PrimitiveType, value: Any, ex
 )
 def test_json_serialize_roundtrip(primitive_type: PrimitiveType, value: Any) -> None:
     assert value == conversions.from_json(primitive_type, conversions.to_json(primitive_type, value))
+
+
+def test_unknown_type_conversions() -> None:
+    """Unknown values are always null, so they have no binary or partition representation."""
+    unknown = UnknownType()
+
+    assert conversions.to_bytes(unknown, "iceberg") is None
+    assert conversions.from_bytes(unknown, b"\x01\x02\x03\xff") is None
+    assert conversions.partition_to_py(unknown, "iceberg") is None
+
+    # The spec defines no JSON single-value representation for unknown, since a
+    # non-null initial-default or write-default is invalid for the type.
+    with pytest.raises(TypeError):
+        conversions.to_json(unknown, "iceberg")
+
+    with pytest.raises(TypeError):
+        conversions.from_json(unknown, "iceberg")