feat: support nullable scalar Function declarations (#5030)

Function declarations currently reject nullable scalar returns. Accept
`Optional[T]`, `T | None`, and explicit nullable Arrow fields,
preserving `nullable: true` in registration signatures, JSON round
trips, and remote `add_columns` requests.

The Rust planner accepts nullable scalar outputs, and binding readback
recognizes the server-owned assignment marker for a single nullable
scalar result. Clients do not allocate that marker. Non-nullable whole
results, whole structs, and Blob v2 retain their existing assignment
restrictions.

Validated with 127 Python tests, 30 documentation tests (1 skipped), and
seven focused Rust tests covering planning, binding readback, rejection
boundaries, and the remote request body. The final condition-collapse
change addresses strict Clippy; its delta check and CI are pending.
Python tests use a source overlay on a retained native extension, and
Rust remote coverage uses HTTP mocks.

Server support and end-to-end validation remain separate. This PR does
not claim that server publication distinguishes computed NULL values
from pending rows.
This commit is contained in:
Xuanwo
2026-11-14 20:59:20 +08:00
committed by GitHub
parent 005b33fa8b
commit e5a5b67212
8 changed files with 517 additions and 50 deletions
+21 -7
View File
@@ -154,13 +154,27 @@ def test_function_output_nullability():
("note", True),
]
# A scalar output, and a struct declared as one nullable field, may not be.
for nullable in (
pa.field("result", pa.float64(), nullable=True),
pa.field("result", pa.struct(fields), nullable=True),
):
with pytest.raises(ValueError, match="non-nullable"):
function(input_schema=inputs, output_schema=nullable)(describe)
# A scalar output may be nullable.
@function(input_schema=inputs)
def maybe_double(value: float) -> float | None:
return None if value == 0 else value * 2
output = maybe_double.registration_request.signature.output
assert (output.kind, output.arrow_type, output.nullable) == (
"scalar",
"float64",
True,
)
assert json.loads(maybe_double.registration_request.signature.to_canonical_json())[
"output"
] == {"kind": "scalar", "arrow_type": "float64", "nullable": True}
# A struct declared as one nullable field may not be.
with pytest.raises(ValueError, match="non-nullable"):
function(
input_schema=inputs,
output_schema=pa.field("result", pa.struct(fields), nullable=True),
)(describe)
def test_function_registration_is_remote(tmp_path):