Skip to content
Merged
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
26 changes: 12 additions & 14 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ of its identity (GroupBy's member_order), never the input's column order.
_source_ prefix — Source info provenance (ColumnConfig source)
_input_source_ prefix — Source-info provenance of an input data column as stored by a
function node, e.g. _input_source_age (ColumnConfig(source=True))
_tag:: prefix — System tag (ColumnConfig system_tags)
_tag_ prefix — System tag (ColumnConfig system_tags)
_context_key — Data context (ColumnConfig context)

Prefixes are computed from SystemConstant in system_constants.py.
Expand Down Expand Up @@ -1521,19 +1521,17 @@ data. The rules:
to large_list, recursively). Width, nullability and logical (extension) types are never
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 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. DataFrameSource uses an explicit schema for
custom system-tag nullability and validates the raw values, types and metadata before casting.
Join's sync and batch sort pairs source and record IDs within each printed
provenance path. The rebuilt ID field can hold nulls when any corresponding
input field can hold nulls or an input lacks that field. Custom tags keep their
input positions in these tables. Standalone row channels sort the custom tags
of a tied path with its IDs at every link. Join rows infer tied system-tag
fields from values. Non-tied system-tag fields keep their Arrow declarations.
A raw `ArrowTableStream` preserves the system-tag fields in its table and
rows, including the Arrow Null type (ITL-1543).
Orcapod constructs system tags (ITL-1751). Public source and stream inputs refuse
columns in the system-tag namespace. Function pod outputs and operator rename targets
cannot use reserved system column names. Saved source configs that nominate system
tags are refused before loading a wrapped source or resolving its cache.
Tables built by operators, sources, row transport
and storage reads enter through the private Arrow stream factory. It preserves system-tag
field declarations and requires string values without nulls. Cached source rows also
require non-nullable fields without metadata, pending ITL-1561.
Join's sync and batch sort source and record ID pairs within each printed provenance
path. Join rows infer tied system-tag fields from values. Non-tied system-tag fields
keep their Arrow declarations.
Streams, rows and record batches declare every `_source_*` token field nullable (ITL-1557).
The top-level flag comes from `arrow_utils.source_info_field` and is independent
of the token values and of any list item fields. CachedSource writes these fields
Expand Down
26 changes: 12 additions & 14 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ of its identity (GroupBy's `member_order`), never the input's column order.
| `__` | System metadata | `__data_id`, `__pod_version` | `ColumnConfig(meta=True)` |
| `_source_` | Source info provenance | `_source_age` | `ColumnConfig(source=True)` |
| `_input_source_` | Source-info provenance of an input data column as stored by a function node | `_input_source_age` | `ColumnConfig(source=True)` |
| `_tag::` | System tag | `_tag::source:abc123` | `ColumnConfig(system_tags=True)` |
| `_tag_` | System tag | `_tag_source_id::abc123` | `ColumnConfig(system_tags=True)` |
| `_context_key` | Data context | `_context_key` | `ColumnConfig(context=True)` |

Prefixes are computed from `SystemConstant` in `system_constants.py`. The `constants` singleton
Expand Down Expand Up @@ -1566,19 +1566,17 @@ data. The rules:
to `large_list`, recursively). Width, nullability and logical (extension) types are never
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 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. DataFrameSource uses an explicit schema for
custom system-tag nullability and validates the raw values, types and metadata before casting.
Join's sync and batch sort pairs source and record IDs within each printed
provenance path. The rebuilt ID field can hold nulls when any corresponding
input field can hold nulls or an input lacks that field. Custom tags keep their
input positions in these tables. Standalone row channels sort the custom tags
of a tied path with its IDs at every link. Join rows infer tied system-tag
fields from values. Non-tied system-tag fields keep their Arrow declarations.
A raw `ArrowTableStream` preserves the system-tag fields in its table and
rows, including the Arrow Null type (ITL-1543).
Orcapod constructs system tags (ITL-1751). Public source and stream inputs refuse
columns in the system-tag namespace. Function pod outputs and operator rename targets
cannot use reserved system column names. Saved source configs that nominate system
tags are refused before loading a wrapped source or resolving its cache.
Tables built by operators, sources, row transport
and storage reads enter through the private Arrow stream factory. It preserves system-tag
field declarations and requires string values without nulls. Cached source rows also
require non-nullable fields without metadata, pending ITL-1561.
Join's sync and batch sort source and record ID pairs within each printed provenance
path. Join rows infer tied system-tag fields from values. Non-tied system-tag fields
keep their Arrow declarations.
Streams, rows and record batches declare every `_source_*` token field nullable (ITL-1557).
The top-level flag comes from `arrow_utils.source_info_field` and is independent
of the token values and of any list item fields. CachedSource writes these fields
Expand Down
10 changes: 10 additions & 0 deletions changelog.d/ITL-1751.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Breaking changes and migration

- Orcapod owns system tags. Source constructors and `ArrowTableStream` no longer accept
`system_tag_columns` and reject input columns in the reserved system-tag namespace.
Rename those fields and use ordinary tag columns for user-supplied tags. Saved source
configs with an empty setting still load. Remove non-empty settings and update the
source's tag columns before loading.
- Function pods reject output names reserved for system tags, source-info columns,
metadata, and the data context. `Index` and `Pick` also reject these names as output
targets. Rename affected outputs before defining the pod or operator.
6 changes: 2 additions & 4 deletions docs/concepts/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,8 @@ and neither does a source's own `run()` outside a job (`source.run()` does what
| `DerivedSource` | over a source, checks it; reads the origin's rows again when the origin's modified time moved since this source read them (a source that took in new data, a job node that ran again); holds the new rows if they changed; one that holds no rows (over a job node that had not run) moves when its origin's time moves |
| `SourceProxy` | checks the source bound to it; its modified time follows that source's, and binding or unbinding moves it |

Rows read again are compared with the rows read before, as read from the table or file
(every column, a `system_tag_columns` column too), value by value, with a
NaN equal to a NaN (and -0.0 equal to 0.0), so a table holding a NaN is not a change at every
check. A check that raises part way changes nothing, so the next run checks again.
A check compares every column from the original table or file, value by value. NaN equals
NaN and -0.0 equals 0.0 for this comparison. A check that raises part way changes nothing, so the next run checks again.

Row order follows the source's record id rule (developer, November 14, 2026). Without
key columns a row's record id is its position: a change of row order is a change, so
Expand Down
16 changes: 16 additions & 0 deletions docs/dev/design_issues/ITL-1751-AS5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## `src/orcapod/core/streams/`

### AS5 — User-defined system tags could be mistaken for provenance
**Status:** resolved
**Severity:** medium
**Issue:** ITL-1751

A source or stream could accept user-defined system tags with the same names as
Orcapod's own provenance columns. The same column could appear to have different
roles at different construction boundaries.

**Fix:** Reserve the system-tag namespace at public construction boundaries.
Use a private stream factory for provenance produced by Orcapod. Function
pods, `Index`, and `Pick` refuse reserved output names at definition.
Source configs omit the removed setting and refuse a saved non-empty list,
including in wrapped source configs, before reconstructing sources or caches.
7 changes: 7 additions & 0 deletions src/orcapod/core/function_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ def __init__(
config: OrcapodConfig | None = None,
ctx_arg_name: str | None = None,
) -> None:
output_names = data_function.output_data_schema.keys()
try:
schema_utils.require_names_not_meta(output_names)
schema_utils.require_names_not_system(output_names)
except InputValidationError as exc:
raise InputValidationError(f"Invalid function output: {exc}") from exc

super().__init__(
label=label,
data_context=data_context,
Expand Down
11 changes: 4 additions & 7 deletions src/orcapod/core/nodes/function_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@
from orcapod.core.cached_function_pod import CachedFunctionPod
from orcapod.core.data_function import PYTHON_FUNCTION, declaration_for
from orcapod.core.result_cache import with_recorded_output_keys
from orcapod.core.streams.arrow_table_stream import (
ArrowTableStream,
stream_from_derived_table,
)
from orcapod.core.streams.arrow_table_stream import ArrowTableStream
from orcapod.core.streams.base import (
ZERO_ROW_INPUT_COLUMNS,
StreamBase,
Expand Down Expand Up @@ -627,11 +624,11 @@ def output_schema(
restored to a Python type (an unregistered logical type).
"""
if self._function_pod is None:
from orcapod.logical_types.identifier import LogicalTypeIdentifierError
from orcapod.pipeline.serialization import (
deserialize_output_schema,
SavedSchemaVersionError,
deserialize_output_schema,
)
from orcapod.logical_types.identifier import LogicalTypeIdentifierError

try:
return deserialize_output_schema(
Expand Down Expand Up @@ -4163,7 +4160,7 @@ def _stored_rows_stream(
# A fall-through column is the stored tag column in its data role (ITL-1023):
# the table states which (ITL-1019). In the stream the binding is the shared
# name, so the marker stays with the stored table.
stream = stream_from_derived_table(
stream = ArrowTableStream._from_derived_table(
without_tag_kind_marks(joined.drop(drop_cols)),
tag_columns=self._stored_tag_keys(fetched),
data_tags=fetched.data_tags,
Expand Down
19 changes: 8 additions & 11 deletions src/orcapod/core/nodes/operator_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@
produced_stream,
rows_on_read,
)
from orcapod.core.streams.arrow_table_stream import (
ArrowTableStream,
stream_from_derived_table,
)
from orcapod.core.streams.arrow_table_stream import ArrowTableStream
from orcapod.core.streams.base import (
ZERO_ROW_INPUT_COLUMNS,
StreamBase,
Expand Down Expand Up @@ -508,7 +505,7 @@ def _zero_row_table(self, config: ColumnConfig) -> "pa.Table | None":
saved = self._saved_zero_row_table()
if saved is None:
return None
return stream_from_derived_table(
return ArrowTableStream._from_derived_table(
saved,
tag_columns=self.keys()[0],
data_tags=stream_data_tags(self),
Expand Down Expand Up @@ -541,11 +538,11 @@ def output_schema(
restored to a Python type (an unregistered logical type).
"""
if self._operator is None:
from orcapod.logical_types.identifier import LogicalTypeIdentifierError
from orcapod.pipeline.serialization import (
deserialize_output_schema,
SavedSchemaVersionError,
deserialize_output_schema,
)
from orcapod.logical_types.identifier import LogicalTypeIdentifierError

try:
return deserialize_output_schema(
Expand Down Expand Up @@ -1354,7 +1351,7 @@ def _stream_over_stored(self, records: "pa.Table") -> ArrowTableStream:
pa.field(constants.CONTEXT_KEY, pa.large_string(), nullable=False),
pa.array([self.data_context_key] * rows.num_rows, pa.large_string()),
)
return stream_from_derived_table(
return ArrowTableStream._from_derived_table(
rows,
tag_columns=self.keys()[0],
data_tags=self.declared_data_tags(),
Expand Down Expand Up @@ -1850,8 +1847,8 @@ def execute(
feeding ``input_streams`` is restricted (ITL-1218); nothing is
read, computed or written.
"""
from orcapod.pipeline.restrictions import refuse_restricted_operator_cache
from orcapod.pipeline.observer import NoOpObserver
from orcapod.pipeline.restrictions import refuse_restricted_operator_cache

# A loaded node runs only in a load-only run, with its rebuilt operator.
if self._loaded and (not load_only or self._operator is None):
Expand Down Expand Up @@ -2250,7 +2247,7 @@ def as_table(
return current.as_table(columns=columns, all_info=all_info)
# Every node, one with an operator or one rebuilt without it, from the one
# builder of its zero-row table (``_make_empty_table``).
empty_stream = stream_from_derived_table(
empty_stream = ArrowTableStream._from_derived_table(
self._make_empty_table(),
tag_columns=self.keys()[0],
data_tags=stream_data_tags(self),
Expand Down Expand Up @@ -2451,8 +2448,8 @@ async def async_execute(
feeding its ``upstreams`` (which the channels carry) is restricted
(ITL-1218); the output is closed, nothing read or written.
"""
from orcapod.pipeline.restrictions import refuse_restricted_operator_cache
from orcapod.pipeline.observer import NoOpObserver
from orcapod.pipeline.restrictions import refuse_restricted_operator_cache

# A loaded node runs only in a load-only run, with its rebuilt operator.
if self._loaded and (not load_only or self._operator is None):
Expand Down
9 changes: 3 additions & 6 deletions src/orcapod/core/nodes/source_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
)
from orcapod.core.operators.drop_nulls import _without_none # pyright: ignore[reportPrivateUsage] # DropNulls' rule for removing None from a type, shared, never copied
from orcapod.core.sources.base import RootSource, table_is_rows
from orcapod.core.streams.arrow_table_stream import (
ArrowTableStream,
stream_from_derived_table,
)
from orcapod.core.streams.arrow_table_stream import ArrowTableStream
from orcapod.core.streams.base import (
ZERO_ROW_INPUT_COLUMNS,
CompleteStreamFeed,
Expand Down Expand Up @@ -1417,12 +1414,12 @@ def execute(
Raises:
UnboundSourceError: When no concrete data is available.
"""
from orcapod.core.output_bindings import capture_output_bindings
from orcapod.core.operators.static_output_pod import (
RowBuiltFormUnavailable,
StaticOutputOperatorPod,
rows_on_read,
)
from orcapod.core.output_bindings import capture_output_bindings

bindings = capture_output_bindings(self)
node_label = self.label
Expand Down Expand Up @@ -1963,7 +1960,7 @@ def _declared_stream(
*table* must hold the system-tag, source-info and context columns, so the
stream selects, sorts and hashes the declared rows as any stream does.
"""
return stream_from_derived_table(
return ArrowTableStream._from_derived_table(
form.apply(table),
tag_columns=tuple(self._tag_schema.keys()),
data_context=source.data_context, # pyright: ignore[reportAttributeAccessIssue] # StreamProtocol omits data_context, which every concrete stream provides (ITL-844)
Expand Down
4 changes: 2 additions & 2 deletions src/orcapod/core/operators/add_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from orcapod.core.operators.base import UnaryOperator
from orcapod.core.operators.column_selection import is_meta_column
from orcapod.core.operators.meta_columns import WithoutMetaWriter
from orcapod.core.streams.arrow_table_stream import stream_from_derived_table
from orcapod.core.streams.arrow_table_stream import ArrowTableStream
from orcapod.errors import InputValidationError
from orcapod.protocols.core_protocols import DataProtocol, StreamProtocol, TagProtocol
from orcapod.system_constants import constants
Expand Down Expand Up @@ -333,7 +333,7 @@ def unary_static_process(self, stream: StreamProtocol) -> StreamProtocol:
"sort_by_tags": False,
}
)
return stream_from_derived_table(
return ArrowTableStream._from_derived_table(
self._with_constants(table, tag_keys, data_context.type_converter),
tag_columns=[*tag_keys, *self._tags],
data_tags=stream_data_tags(stream),
Expand Down
4 changes: 2 additions & 2 deletions src/orcapod/core/operators/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
finish_operator,
)
from orcapod.core.data_tags import stream_data_tags
from orcapod.core.streams.arrow_table_stream import stream_from_derived_table
from orcapod.core.streams.arrow_table_stream import ArrowTableStream
from orcapod.protocols.core_protocols import DataProtocol, StreamProtocol, TagProtocol
from orcapod.system_constants import constants
from orcapod.types import ColumnConfig, ContentHash
Expand Down Expand Up @@ -202,7 +202,7 @@ def unary_static_process(self, stream: StreamProtocol) -> StreamProtocol:
)

# A data-tag stays a data-tag: the same list in both roles.
return stream_from_derived_table(
return ArrowTableStream._from_derived_table(
batched_table,
tag_columns=tag_columns,
data_context=stream.data_context,
Expand Down
Loading
Loading