Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6d26384
fix(schema): refuse sets of struct-stored user classes
eywalker Nov 29, 2026
cbe2329
docs(database): generate the user-class set restriction
eywalker Nov 29, 2026
4be401a
docs(schema): track deferred user-class set ordering
eywalker Nov 29, 2026
8d3be77
Merge remote-tracking branch 'origin/main' into eywalker/itl-922-refu…
eywalker Nov 29, 2026
2122329
fix(schema): limit user-class set checks to declarations
eywalker Nov 29, 2026
cc7fea0
fix(schema): close user-class set declaration gaps
eywalker Nov 29, 2026
85f147e
chore: merge main into user class set branch
eywalker Nov 29, 2026
f4b5bcd
fix(semantic-types): refuse struct-stored user class sets at conversion
eywalker Nov 29, 2026
125f721
fix(semantic-types): name the column in set write errors
eywalker Nov 29, 2026
650f9c9
test(semantic-types): type the custom source fixture
eywalker Nov 29, 2026
667d66b
Merge remote-tracking branch 'origin/main' into eywalker/itl-922-refu…
eywalker Nov 29, 2026
bb40cb1
fix(conversion): complete the user-class set refusal
eywalker Nov 29, 2026
5077879
fix(conversion): keep the user-class set check read-only
eywalker Nov 29, 2026
f8baad2
Merge remote-tracking branch 'origin/main' into eywalker/itl-922-refu…
eywalker Nov 29, 2026
56b2486
fix(conversion): simplify user-class set refusal diagnostics
eywalker Nov 29, 2026
56ca4a8
fix(conversion): refuse sets of deferred struct types
eywalker Nov 29, 2026
1fec597
fix(conversion): honor registered whole-set encoders
eywalker Nov 29, 2026
97ba08c
docs(database): sync native set wording with matrix generator
eywalker Nov 29, 2026
d0ebcdd
fix(conversion): preserve precomputed write schema and refusal context
eywalker Nov 29, 2026
debef3b
Merge remote-tracking branch 'origin/main' into eywalker/itl-922-refu…
eywalker Nov 29, 2026
658c635
fix(conversion): preserve eager converter selection for native sets
eywalker Nov 29, 2026
ecb550d
fix(conversion): preserve native set validation before writes
eywalker Nov 29, 2026
00a75c4
test(conversion): match native annotation wording on Python 3.13
eywalker Nov 29, 2026
5c5f889
fix(conversion): validate before refusing native class set writes
eywalker Nov 29, 2026
1382e19
chore: merge main into ITL-922
eywalker Nov 29, 2026
756366c
chore: merge main into PR 666
eywalker Nov 29, 2026
9055604
test(semantic-types): isolate the cold IPC set fixture
eywalker Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ A class a user defines is one of two kinds (developer, November 12, 2026, ITL-97
only conversion, and Orcapod never calls it.
- A declared class stores its own instances and subclasses (`UserClassLogicalType.accepts_instance`);
only the declared class fields enter storage. Unrelated look-alike classes are refused.
- For 0.4.0, build a refusing Python-to-Arrow converter for native `set[T]` storage
when the element is a struct-stored user class (developer decision D47, ITL-922).
Use the converter's normal resolution and caching, including deferred types.
A logical type selected for the whole set owns its storage.
The refusal surfaces on a Python value write. Declarations and Arrow reads use
their existing paths. Direct writers to `list[T]`. ITL-1691 tracks canonical ordering.
- The identity record (`logical_types/user_class_identity.py`) is `{kind, name, fields}`
with JSON type tokens. The Arrow extension name is `name@<SHA-256 of the record>` and the
record is part of the extension metadata; together they are the logical type identifier. A nested
Expand Down
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ A class a user defines is one of two kinds (developer, November 12, 2026, ITL-97
only conversion, and Orcapod never calls it.
- A declared class stores its own instances and subclasses (`UserClassLogicalType.accepts_instance`);
only the declared class fields enter storage. Unrelated look-alike classes are refused.
- For 0.4.0, build a refusing Python-to-Arrow converter for native `set[T]` storage
when the element is a struct-stored user class (developer decision D47, ITL-922).
Use the converter's normal resolution and caching, including deferred types.
A logical type selected for the whole set owns its storage.
The refusal surfaces on a Python value write. Declarations and Arrow reads use
their existing paths. Direct writers to `list[T]`. ITL-1691 tracks canonical ordering.
- The identity record (`logical_types/user_class_identity.py`) is `{kind, name, fields}`
with JSON type tokens. The Arrow extension name is `name@<SHA-256 of the record>` and the
record is part of the extension metadata; together they are the logical type identifier. A nested
Expand Down
7 changes: 7 additions & 0 deletions changelog.d/ITL-922.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Breaking changes and migration

- Converting Python sets of struct-stored user classes to Orcapod's native set storage now
raises an error, including for nested sets. Use `list[T]` and supply the elements in the
order you want stored. Registered logical types for whole sets keep their own storage.
Annotations and reads of existing Arrow data continue to work. ITL-1691 tracks canonical
ordering for these sets.
5 changes: 5 additions & 0 deletions docs/concepts/function-pods.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ output (ITL-1150). The same types are faithful as a column, inside a list, and a
dataclass, an `orcapod.dataclass` or a pydantic model: hold such a value in a dataclass
field, or declare the plain type (`dict[str, list[int]]`).

A pod definition can declare a set of user classes stored as structs. When the first
returned value is converted to native set storage, Orcapod 0.4.0 reports an
`OutputTypeError` for that output. Use `list[T]` to return these values, including inside
other types.

Outputs are validated against the declared storage schema immediately, and accepted numeric
exceptions are normalized so downstream pods, hashes and stored rows see the same value.
Eager validation never replaces a compatible user-class object; stored reads keep their
Expand Down
6 changes: 6 additions & 0 deletions docs/concepts/logical-type-identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ that the element is a plain Arrow type, which a reader takes from the storage
(`large_list<large_string>`). A stored column whose storage is not a list of the element its
name names is refused with `LogicalTypeIdentifierError`.

Orcapod 0.4.0 refuses native set conversion when the logical type for a set's user-class
elements stores them as Arrow structs. Use `list[T]` for these classes. Sets of primitives
and scalar-stored logical types such as `Path` and `UUID` are supported. A registered
logical type for the entire set defines its own storage. Existing Arrow data and saved
schemas can still be read.

```python
from orcapod.sources import DictSource

Expand Down
10 changes: 10 additions & 0 deletions docs/concepts/your-own-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ can return. For example, a returned object with `None` in an `int` field raises
values deliberately. Pydantic's own validation still applies whenever it
constructs a model.

Orcapod 0.4.0 accepts annotations such as `set[T]` for user classes stored as Arrow
structs. The error occurs when Orcapod first converts a Python set to native set storage.
This applies to ordinary dataclasses, `op.dataclass` classes and pydantic models,
including sets nested in another type. Use `list[T]` and supply the items in the order
you want stored. Existing Arrow data can still be read. ITL-1691 tracks canonical
ordering for these sets. A registered logical type for the entire set defines its own
storage. A custom source's `from_config` follows the same rule when it
builds a source from fresh Python rows. If that conversion fails during a saved-job load,
the job logs a warning and leaves the source unbound.

## `op.dataclass` in a notebook

`op.dataclass` is used like `dataclasses.dataclass` and returns a real dataclass. Define
Expand Down
22 changes: 22 additions & 0 deletions docs/dev/design_issues/ITL-922-SU1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## `src/orcapod/logical_types/list_logical_type_factory.py` — set storage order

### SU1 — A set of struct-stored user classes needs a canonical order
**Status:** resolved
**Severity:** high
**Issue:** ITL-922

The stored order of a set of struct-stored user classes can follow the set's iteration
order, so equal sets can have different stored representations and row hashes.

**Fix:** The native set converter checks the resolved Arrow destination after the
original encoder validates the elements. The converter caches the refusal decision for
resolved plans. A registered whole-set encoder owns its storage. Empty declarations
and Arrow reads keep their original behavior. For a cold or wrapped annotation that
fails eager resolution, a matching native Arrow destination and actual instances identify
the write to refuse. The refusal directs writers to `list[T]`. ITL-1691 tracks the
canonical storage order.

With a cold converter and a matching explicit native Arrow schema, a required
`set[PlainPoint]` containing `PlainPoint(1)` and `None` raises
`UserClassSetNotStorableError` in place of the eager schema-resolution `ValueError`
(ITL-1754).
3 changes: 3 additions & 0 deletions docs/reference/database-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ preserve a nested extension. Use the corresponding Orcapod container or class ty
to keep the logical type: it stores its children in Arrow storage form within one
top-level logical column.

Orcapod 0.4.0 refuses to convert Python sets of struct-stored user classes to native set
storage. Use `list[T]` for those classes.

What a cell says:

- **kept**: read back exactly: the Arrow type with the name, nullability and metadata of
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,10 @@ of affected inputs, and changing storage order would move row hashes and what a
`set[T]` of a logical type (`set[Path]`, `set[UUID]`) is ordered by `ListLogicalType`, not
by this rule.

Orcapod 0.4.0 refuses to convert Python `set[T]` values to native set storage when `T` is a
user class stored as a struct. Use `list[T]` and choose the element order before handing
the list to Orcapod. ITL-1691 tracks canonical storage ordering for those sets.

**The set's identity is part of the row hash** (ITL-611). A set of a primitive is stored
under its native container type, and the Arrow hasher hashes an extension column's
identifier (extension name and metadata) with its stored values. So `{1, 2, 3}` as
Expand Down
7 changes: 5 additions & 2 deletions src/orcapod/core/data_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
PythonFunctionReturnCheckProtocol,
)
from orcapod.protocols.database_protocols import ArrowDatabaseProtocol
from orcapod.semantic_types.nested_storage import UserClassSetNotStorableError
from orcapod.semantic_types.output_conformance import (
check_conformance,
normalize_output_numbers,
Expand Down Expand Up @@ -1190,13 +1191,15 @@ def _convert_outputs(
failure.reason,
failure.hint,
) from None
except Exception:
except Exception as failure:
raise OutputTypeError(
self.canonical_function_name,
key,
output_schema[key],
value,
type(exc).__name__,
str(failure).removesuffix(".")
if isinstance(failure, UserClassSetNotStorableError)
else type(exc).__name__,
) from None
raise

Expand Down
4 changes: 4 additions & 0 deletions src/orcapod/semantic_types/nested_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class NestedTypeNotStorableError(ValueError):
"""A logical type is declared where storage cannot keep it (ITL-1150)."""


class UserClassSetNotStorableError(NestedTypeNotStorableError):
"""A set of struct-stored user classes has no canonical storage order (ITL-922)."""


def require_storable_in_struct_field(arrow_type: pa.DataType) -> None:
"""Refuse a logical type or native container as a dict key or value or a tuple field.

Expand Down
36 changes: 28 additions & 8 deletions src/orcapod/semantic_types/precomputed_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import pyarrow as pa


from orcapod.semantic_types.universal_converter import UniversalTypeConverter
from orcapod.semantic_types.nested_storage import UserClassSetNotStorableError
from orcapod.semantic_types.universal_converter import (
UniversalTypeConverter,
_converter_for_arrow_field,
)


class SemanticSchemaConverter:
Expand Down Expand Up @@ -47,7 +51,8 @@ def __init__(
self._python_to_arrow_converters: dict[str, Callable[[Any], Any]] = {}
self._arrow_to_python_converters: dict[str, Callable[[Any], Any]] = {}

for field_name, python_type in self.python_schema.items():
# Snapshot the caller's field plan before building converters.
for field_name, python_type in tuple(self.python_schema.items()):
self._python_to_arrow_converters[field_name] = (
self.universal_converter.get_python_to_arrow_converter(python_type)
)
Expand All @@ -72,20 +77,30 @@ def python_dicts_to_struct_dicts(
"""
Convert a list of Python dictionaries to a list of Arrow-compatible struct dictionaries.
"""
return self._convert_rows(data, self._python_to_arrow_converters)

def _convert_rows(
self, data: list[dict[str, Any]], converters: dict[str, Callable[[Any], Any]]
) -> list[dict[str, Any]]:
if not data:
raise ValueError("Cannot convert empty data list")

converted_data = []
for record in data:
converted_record = {}
for field_name, converter in self._python_to_arrow_converters.items():
for field_name, converter in converters.items():
# TODO: test the case of None/missing value
value = record.get(field_name)
if value is None:
converted_record[field_name] = None
else:
# Convert using the pre-computed converter
converted_record[field_name] = converter(value)
try:
converted_record[field_name] = converter(value)
except UserClassSetNotStorableError as exc:
raise UserClassSetNotStorableError(
f"Column {field_name!r}: {exc}"
) from exc
converted_data.append(converted_record)

return converted_data
Expand Down Expand Up @@ -140,10 +155,15 @@ def python_dicts_to_arrow_table(
when the caller needs to enforce specific field types or nullable
flags that differ from what was inferred at construction time.
"""
return pa.Table.from_pylist(
self.python_dicts_to_struct_dicts(data),
schema=arrow_schema or self.arrow_schema,
)
if arrow_schema:
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
converters = {
name: _converter_for_arrow_field(converter, arrow_schema, name)
for name, converter in self._python_to_arrow_converters.items()
}
rows = self._convert_rows(data, converters)
else:
rows = self.python_dicts_to_struct_dicts(data)
return pa.Table.from_pylist(rows, schema=arrow_schema or self.arrow_schema)

def arrow_table_to_python_dicts(self, table: pa.Table) -> list[dict[str, Any]]:
"""
Expand Down
Loading
Loading