Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1345,9 +1345,16 @@ data. The rules:
changed, so `int8` stays `int8`. Sources refuse Arrow type `null` at any depth, including
in reserved raw columns. Declare a supported nullable type for missing values.
A source's custom system-tag names must each identify an existing non-nullable text
column with no null values. When Join sorts tied system tags, an output field is
nullable if any of the corresponding input fields can hold a null.
column with no null values and no Arrow field metadata. Remove field metadata before
building the source. This restriction is a stopgap pending ITL-1561. System-tag fields on
a raw ArrowTableStream keep their metadata. When Join sorts tied system tags, it declares
the rebuilt fields without operand metadata. A rebuilt field is nullable if any of the
corresponding input fields can hold a null.
A raw `ArrowTableStream` still preserves `null` in its table in ITL-1543 part A.
A row's system-tag fields come from its stream, including raw streams. Join
uses those declarations on the async row path as well as in its tables.
Source-info token declarations and the row-built gate are tracked separately
under ITL-1557 and the PR 601 follow-up.
A row built by `Data` still gives an untyped null the `large_string` type.
PolarsFilter is the one operator that still round-trips its columns through Polars; it
casts them back to the normalized input types (arrow_utils.restore_column_types and
Expand Down
11 changes: 9 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1393,9 +1393,16 @@ data. The rules:
changed, so `int8` stays `int8`. Sources refuse Arrow type `null` at any depth, including
in reserved raw columns. Declare a supported nullable type for missing values.
A source's custom system-tag names must each identify an existing non-nullable text
column with no null values. When Join sorts tied system tags, an output field is
nullable if any of the corresponding input fields can hold a null.
column with no null values and no Arrow field metadata. Remove field metadata before
building the source. This restriction is a stopgap pending ITL-1561. System-tag fields on
a raw ArrowTableStream keep their metadata. When Join sorts tied system tags, it declares
the rebuilt fields without operand metadata. A rebuilt field is nullable if any of the
corresponding input fields can hold a null.
A raw `ArrowTableStream` still preserves `null` in its table in ITL-1543 part A.
A row's system-tag fields come from its stream, including raw streams. Join
uses those declarations on the async row path as well as in its tables.
Source-info token declarations and the row-built gate are tracked separately
under ITL-1557 and the PR 601 follow-up.
A row built by `Data` still gives an untyped null the `large_string` type.
`PolarsFilter` is the one operator that still round-trips its columns through Polars; it
casts them back to the normalized input types (`arrow_utils.restore_column_types` and
Expand Down
11 changes: 11 additions & 0 deletions changelog.d/ITL-1543.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
- A custom system-tag column on a source must be a non-nullable string column
with no null values. Sources also reject missing names in `system_tag_columns`.
Convert custom tags to text before building the source.
- Sources refuse Arrow field metadata on nominated custom system tags, including
tag copies nominated with `system_tag_columns`. Remove the field metadata before
building the source. Rebuild a source cache if it was written with field
metadata on a system tag. ITL-1561 tracks re-evaluating this restriction.

### Fixed

- Join uses the declared fields of inputs tied on pipeline hash to set the
sorted system tags' nullability. The tag is non-nullable when every
corresponding input field is non-nullable. Existing entry IDs, instance IDs,
record IDs and operator hashes for source inputs stay the same.
- Rows preserve the stream's Arrow fields for system tags, including width,
nullability, and metadata. Standalone async Join uses those fields as well.
IDs can change for hand-built streams with unusual system-tag fields.
- Standalone async Join uses the same fields as the table and sync rows for
sorted system tags of tied inputs, and leaves custom tags with their operands.
Entry-ID errors for a raw Arrow Null system
tag name the column and ask for a supported nullable type.
4 changes: 3 additions & 1 deletion docs/dev/design_issues/ITL-1543-AS2.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ data was read. For example, a Join of streams tied on pipeline hash can declare
its sorted system tags nullable, although its rows have non-nullable system tags.

Part A corrects that Join schema and rejects Arrow Null in sources, including
nested Null. Part B remains open and makes rows use the stream's field definitions.
nested Null. Part B carries a stream's system-tag fields through row and batch
reads, including the standalone async Join. Source-info flag decisions remain
open in ITL-1557, and the existing row-built guard remains pending PR 601.
5 changes: 4 additions & 1 deletion src/orcapod/core/datagrams/datagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def _rows_of_table(
"""
if table.num_rows == 0:
return
original_table = table
table = arrow_utils.normalize_table_to_large_types(table)
row_contexts: list[Any | None] | None = None
if constants.CONTEXT_KEY in table.column_names and data_context is None:
Expand All @@ -365,7 +366,9 @@ def _rows_of_table(
if apart_prefix is not None:
apart = [c for c in data_table.column_names if c.startswith(apart_prefix)]
if apart:
apart_table = data_table.select(apart)
apart_table = arrow_utils.normalize_table_to_large_types(
original_table.select(apart), keep_null=True
)
data_table = data_table.drop_columns(apart)
# The optional tables that are there, and where each is in a row's tuple.
optional = [meta_table, apart_table, beside]
Expand Down
48 changes: 38 additions & 10 deletions src/orcapod/core/datagrams/tag_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(
data = _pa.Table.from_batches([data])

extracted_sys_tags: dict[str, DataValue]
system_tag_table = None

if isinstance(data, _pa.Table):
# Arrow path: call super() first, then extract system-tag columns from
Expand All @@ -107,9 +108,12 @@ def __init__(
if c.startswith(constants.SYSTEM_TAG_PREFIX)
]
if sys_tag_cols:
system_tag_table = arrow_utils.normalize_table_to_large_types(
data.select(sys_tag_cols), keep_null=True
)
extracted_sys_tags = (
self._data_context.type_converter.arrow_table_to_python_dicts(
self._data_table.select(sys_tag_cols) # type: ignore[union-attr]
system_tag_table
)[0]
)
self._data_table = self._data_table.drop_columns(sys_tag_cols) # type: ignore[union-attr]
Expand Down Expand Up @@ -138,7 +142,10 @@ def __init__(
**kwargs,
)

self._set_system_tags({**extracted_sys_tags, **(system_tags or {})})
if system_tag_table is not None and not system_tags:
self._set_system_tag_table(system_tag_table, extracted_sys_tags)
else:
self._set_system_tags({**extracted_sys_tags, **(system_tags or {})})

def _set_system_tags(self, system_tags: dict[str, DataValue]) -> None:
"""Hold ``system_tags`` as this tag's system tags."""
Expand All @@ -147,6 +154,20 @@ def _set_system_tags(self, system_tags: dict[str, DataValue]) -> None:
[self._system_tags], default_type=str
)
self._system_tags_table: "pa.Table | None" = None
self._system_tags_from_arrow = False

def _set_system_tag_table(
self, table: "pa.Table", values: dict[str, DataValue]
) -> None:
"""Hold the system-tag fields and values supplied by an Arrow table."""
self._system_tags_table = table
self._system_tags = values
self._system_tags_python_schema = Schema(
self._data_context.type_converter.arrow_schema_to_python_schema(
table.schema
)
)
self._system_tags_from_arrow = True

@classmethod
def rows_of(
Expand Down Expand Up @@ -178,13 +199,15 @@ def rows_of(
table, data_context, apart_prefix=constants.SYSTEM_TAG_PREFIX
)
for tag, system_tag_row, _ in rows:
tag._set_system_tags(
tag._data_context.type_converter.arrow_table_to_python_dicts(
system_tag_row
)[0]
if system_tag_row is not None
else {}
)
if system_tag_row is None:
tag._set_system_tags({})
else:
tag._set_system_tag_table(
system_tag_row,
tag._data_context.type_converter.arrow_table_to_python_dicts(
system_tag_row
)[0],
)
yield tag

# ------------------------------------------------------------------
Expand Down Expand Up @@ -287,7 +310,12 @@ def copy(self, include_cache: bool = True, preserve_id: bool = False) -> Self:
new_tag = super().copy(include_cache=include_cache, preserve_id=preserve_id)
new_tag._system_tags = dict(self._system_tags)
new_tag._system_tags_python_schema = self._system_tags_python_schema
new_tag._system_tags_table = self._system_tags_table if include_cache else None
new_tag._system_tags_from_arrow = self._system_tags_from_arrow
new_tag._system_tags_table = (
self._system_tags_table
if include_cache or self._system_tags_from_arrow
else None
)
return new_tag


Expand Down
Loading
Loading