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
2 changes: 2 additions & 0 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ tokens, ITL-1425), and with the sorted mapping the source id is the source's ide
origin enters only through the schema). The
config type key stays derived. DerivedSource without tags_as_data (a job node's stored records)
keeps its old identity; do not change it (ITL-956).
The tags_as_data argument is provisional and may be removed (ITL-1020), so when in
doubt start with a data-tag, or start with data and promote it to a data-tag if needed.

### Two identity chains

Expand Down
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ tokens, ITL-1425), and with the sorted mapping the source id is the source's ide
origin enters only through the schema). The
config type key stays `derived`. `DerivedSource` without `tags_as_data` (a job node's stored records)
keeps its old identity; do not change it (ITL-956).
The `tags_as_data` argument is provisional and may be removed (ITL-1020), so when in
doubt start with a data-tag, or start with data and promote it to a data-tag if needed.

### Two identity chains

Expand Down
11 changes: 11 additions & 0 deletions changelog.d/ITL-1020.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Changed

- A non-empty `tags_as_data` mapping now warns once per process for each of
`DerivedSource`, `node.as_source()`, and `SpiralDBTableSource`, including when
a saved job is loaded and its source stays unbound.

### Known limitations

- The `tags_as_data` argument is provisional and may change or be removed.
When in doubt, start with a data-tag, or start with data and promote it to
a data-tag if needed. Promotion from a plain tag is still being designed.
5 changes: 5 additions & 0 deletions docs/concepts/data-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ take it from that column: as in v0.3, the value must also be a data column of it
example a copy in the source's data under another name, or
`DerivedSource(origin, tags_as_data={...})`.

!!! warning "Provisional"
`tags_as_data` may change or be removed in a later version. When in doubt, start
with a data-tag at the source, or start with data and promote it to a data-tag
if needed. How to promote a plain tag to a data-tag is still being designed.

## Errors that name a data-tag

- `pod.process(stream)` and `pod(stream, strict_columns=True)` are exact: they hand every data
Expand Down
4 changes: 4 additions & 0 deletions docs/concepts/identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ per-row hash is what caching uses.
row's content hash is checked against the database. If the hash already exists, the cached
result is returned without recomputation.

!!! warning "Provisional"
The [`tags_as_data` argument](sources.md#provisional-sources) may change or
be removed in a later version.

### `pipeline_hash()` -- schema and topology only

The pipeline hash captures the pipeline's **structure** -- schemas, function identities, and
Expand Down
5 changes: 5 additions & 0 deletions docs/concepts/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ The output schema follows three rules:
`tag_only_columns`), declare it as data at the source, or derive a source that offers the
tag as data with `DerivedSource(origin, tags_as_data={...})`.

!!! warning "Provisional"
`tags_as_data` may change or be removed in a later version. When in doubt, start
with a data-tag at the source, or start with data and promote it to a data-tag
if needed. How to promote a plain tag to a data-tag is still being designed.

```python
from orcapod.sources import DerivedSource

Expand Down
20 changes: 19 additions & 1 deletion docs/concepts/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ columns, copied as each batch is read (so the source still reads no rows when bu
name; you name the copy, which comes after the table's data columns, with the key column's
type, never null:

!!! warning "Provisional"
`tags_as_data` may change or be removed in a later version. When in doubt, start
with a data-tag at the source, or start with data and promote it to a data-tag
if needed. How to promote a plain tag to a data-tag is still being designed.

<!-- docs-test: skip -->
```python
spikes = SpiralDBTableSource(
Expand Down Expand Up @@ -947,7 +952,8 @@ reads it through its data role, under the same name (see
never receives it. When a plain tag's value is also needed as data (a session's start time
identifies the session, and it is also what you subtract to get an elapsed time), or you want
the value as a data column under another name, pass `tags_as_data` to get a source that keeps
the tag and also offers its value as a data column under a name you choose:
the tag and also offers its value as a data column under a name you choose.
See the [provisional status of `tags_as_data`](#provisional-sources).

```python
from datetime import datetime, timezone
Expand Down Expand Up @@ -1061,6 +1067,18 @@ saved config or by loading a saved job, issues `orcapod.errors.ProvisionalHashWa
per source kind per process; filter its class to silence it, as for
[provisional operators](operators.md#provisional-operators).

!!! warning "Provisional"
`tags_as_data` may change or be removed in a later version. When in doubt, start
with a data-tag at the source, or start with data and promote it to a data-tag
if needed. How to promote a plain tag to a data-tag is still being designed.

A non-empty mapping warns on first use per process for each of
`DerivedSource`, `node.as_source()` (shared by function and operator nodes),
and `SpiralDBTableSource`. Loading a job with such a mapping also warns for
that route, even if the source stays unbound. Saved node-backed sources use
the `node.as_source()` route. The warning about `DerivedSource` identity is
still issued separately.

## What a source does at a run

A job node that has run holds its rows until it is stale, and staleness comes from modified
Expand Down
15 changes: 15 additions & 0 deletions docs/dev/design_issues/ITL-1020-TAD1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Sources and tags as data

### TAD1 — Provisional tag copies after data-tags
**Status:** resolved
**Severity:** medium
**Issue:** ITL-1020

Data-tags cover the common case of using a tag's value in a computation.
Removing `tags_as_data` would break existing callers that copy tag values into
data columns. The transition from a plain tag to a data-tag still needs a design.

**Fix:** Keep `tags_as_data` provisional, with possible future removal, and warn
once per process per route on the first use of a non-empty mapping, including
when loading a saved job whose source stays unbound. When in doubt, start with
a data-tag or start with data and promote it later.
4 changes: 4 additions & 0 deletions docs/reference/golden-hashes.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ wanted on purpose starts a new data context version. It never edits a released v
the developer's approval of the exact list. So the promise on this page holds for a
pipeline only when it contains none of them. See [Provisional files](#provisional-files).

!!! warning "Provisional"
The [`tags_as_data` argument](../concepts/sources.md#provisional-sources) may
change or be removed in a later version.

!!! warning "Provisional"
In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity,
when it delivers, and the layout of its delivery log may change in a later version.
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ renaming a label moves every hash it feeds, and with it the paths and keys built

### Default source ids and row identifiers

!!! warning "Provisional"
The [`tags_as_data` argument](../concepts/sources.md#provisional-sources) may
change or be removed in a later version.

A source id is the source's name (rule 7), and every source id is `<kind>_v<N>:<name>`
(developer, November 23, 2026, ITL-1425). The kind part, `<kind>_v<N>`, is the class's
`SOURCE_KIND` (also its config type key: one vocabulary) and its `SOURCE_VERSION`, the
Expand Down
9 changes: 8 additions & 1 deletion src/orcapod/core/nodes/function_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3553,7 +3553,13 @@ def as_source(
tags_as_data: Maps a tag column of this node to the name of a data
column that receives a copy of it. When given, the result is a
new root source with its own provenance, which needs a
``source_id``; see ``DerivedSource``.
``source_id``.

:::caution[Provisional]
`tags_as_data` may change or be removed in a later version. Start
with a data-tag at the source, or start with data and promote it
to a data-tag if needed.
:::
source_id: The source's name. Required with ``tags_as_data``, which
has no default (ITL-1313).

Expand All @@ -3577,6 +3583,7 @@ def as_source(
tags_as_data=tags_as_data,
data_context=self.data_context_key,
config=self.orcapod_config,
_tags_as_data_route="node.as_source()",
)

# ------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion src/orcapod/core/nodes/operator_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2346,7 +2346,13 @@ def as_source(
tags_as_data: Maps a tag column of this node to the name of a data
column that receives a copy of it. When given, the result is a
new root source with its own provenance, which needs a
``source_id``; see ``DerivedSource``.
``source_id``.

:::caution[Provisional]
`tags_as_data` may change or be removed in a later version. Start
with a data-tag at the source, or start with data and promote it
to a data-tag if needed.
:::
source_id: The source's name. Required with ``tags_as_data``, which
has no default (ITL-1313).

Expand All @@ -2370,6 +2376,7 @@ def as_source(
tags_as_data=tags_as_data,
data_context=self.data_context_key,
config=self.orcapod_config,
_tags_as_data_route="node.as_source()",
)

# ------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions src/orcapod/core/operators/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ class GroupBy(UnaryOperator):
the input. The members' values of a dropped plain tag are not carried
anywhere. If a downstream step needs to know which member each element
came from, make that value a data column before grouping: declare the tag
a data-tag at the source (the default), declare it as data, or use
``DerivedSource(origin, tags_as_data={...})``.
a data-tag at the source (the default), or declare it as data.

Members are sorted by the input's non-group-key tags in name order, each
ascending with nulls last, then by the ``record_id`` columns and then the
Expand Down Expand Up @@ -290,6 +289,12 @@ class GroupBy(UnaryOperator):
has no key, so it keeps every tag column, list-valued: those lists are
what tells a batch's members apart.

Warning:
``DerivedSource(origin, tags_as_data={...})`` can copy an existing
plain tag into data before grouping, but ``tags_as_data`` may change or be
removed in a later version. Prefer a data-tag at the source, or start
with data and promote it to a data-tag if needed.

Args:
by: Tag column names to group on, in any order (a set too), or one
name as a string (a bare string is one name, never its characters).
Expand Down
17 changes: 16 additions & 1 deletion src/orcapod/core/sources/derived_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

from orcapod.core.identity_chains import require_bound_identity_origin
from orcapod.core.sources.base import RootSource
from orcapod.core.sources.provisional import warn_provisional_source
from orcapod.core.sources.provisional import (
TagsAsDataRoute,
warn_provisional_source,
warn_provisional_tags_as_data,
)
from orcapod.core.sources.reload import same_rows
from orcapod.core.sources.source_ids import hash_source_name
from orcapod.core.sources.stream_builder import (
Expand Down Expand Up @@ -172,6 +176,12 @@ class DerivedSource(RootSource):
``derived_v1:semantic_v1:<hex>``.
tags_as_data: Maps a tag column of the origin to the name of the data
column that receives a copy of it.

:::caution[Provisional]
`tags_as_data` may change or be removed in a later version. Start
with a data-tag at the source, or start with data and promote it
to a data-tag if needed.
:::
record_id_columns: Key columns whose values identify a row in record IDs and
provenance tokens, instead of the row position. Only with
``tags_as_data``.
Expand Down Expand Up @@ -265,6 +275,9 @@ def __init__(
from orcapod.core.nodes.staleness import RunHoldingNode
from orcapod.pipeline.source_consistency import require_live_source_bindings

# A direct constructor call can also take a job node. The two as_source
# methods explicitly identify their route.
route: TagsAsDataRoute = kwargs.pop("_tags_as_data_route", "DerivedSource")
key_columns = normalize_record_id_columns(record_id_columns)
if tags_as_data is None:
if isinstance(origin, RootSource):
Expand Down Expand Up @@ -302,6 +315,8 @@ def __init__(
# (ITL-1425): ``derived_v1:<algorithm label>:<hex>``.
source_id = hash_source_name(origin.content_hash())
super().__init__(source_id=source_id, **kwargs)
if self._tags_as_data:
warn_provisional_tags_as_data(route)
self._origin = origin
self._record_id_columns = key_columns
self._key_columns = key_columns or ()
Expand Down
17 changes: 17 additions & 0 deletions src/orcapod/core/sources/provisional.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from collections.abc import Mapping
from types import MappingProxyType
from typing import Literal, TypeAlias

from orcapod.utils.provisional import warn_provisional_use

Expand Down Expand Up @@ -54,3 +55,19 @@ def warn_provisional_source(name: str) -> None:
"docs/concepts/sources.md. To silence: warnings.filterwarnings('ignore', "
"category=orcapod.errors.ProvisionalHashWarning).",
)


TagsAsDataRoute: TypeAlias = Literal[
"DerivedSource", "node.as_source()", "SpiralDBTableSource"
]


def warn_provisional_tags_as_data(route: TagsAsDataRoute) -> None:
"""Warn once per route for the tag-copy argument, separately from identity."""
warn_provisional_use(
f"tags_as_data:{route}",
"tags_as_data is provisional and may change or be removed in a later version. "
"When in doubt, declare the column as a data-tag (or at least as data) at the "
f"source. Used via {route}.",
record_identity=False,
)
9 changes: 9 additions & 0 deletions src/orcapod/core/sources/spiraldb_table_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from orcapod.core.data_tags import TagOnlyColumns, source_data_tags
from orcapod.core.sources.source_ids import joined_location, location_source_name
from orcapod.core.sources.derived_source import validate_tags_as_data
from orcapod.core.sources.provisional import warn_provisional_tags_as_data
from orcapod.core.sources.stream_builder import (
require_custom_system_tags,
require_supported_nullable_types,
Expand Down Expand Up @@ -276,6 +277,12 @@ class SpiralDBTableSource(RootSource):
name of a data column that receives a copy of it, as in
``DerivedSource``. ``None`` (default) or an empty mapping copies nothing.

:::caution[Provisional]
`tags_as_data` may change or be removed in a later version. Start
with a data-tag at the source, or start with data and promote it
to a data-tag if needed.
:::

Raises:
ValueError: If the table is not found, has no key schema, a tag column or a
``where`` column is not in the table, a ``where`` value is ``None``, or
Expand Down Expand Up @@ -365,6 +372,8 @@ def __init__(
self._batch_rows = batch_rows
self._given_asof = asof
self._tags_as_data: dict[str, str] = dict(tags_as_data) if tags_as_data else {}
if self._tags_as_data:
warn_provisional_tags_as_data("SpiralDBTableSource")
location = f"SpiralDB project {project_id!r}, dataset {dataset!r}"

try:
Expand Down
11 changes: 8 additions & 3 deletions src/orcapod/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ class OrcapodDatabaseContentWarning(UserWarning):


class ProvisionalHashWarning(UserWarning):
"""A feature was used whose identity is provisional.
"""A provisional identity or feature was used.

The library value types (``numpy.ndarray``, ``torch.Tensor``, pandas and polars
``DataFrame`` and ``Series``) are hashed and stored with formats that may still
Expand All @@ -907,8 +907,8 @@ class ProvisionalHashWarning(UserWarning):
downstream of it, which are then computed again. The warning is issued once per
operator per process, when the operator is constructed.

A provisional source (``orcapod.sources.PROVISIONAL_SOURCES``, ITL-1314; today
``PollingSource``) has a default source id and a content hash that are not frozen
A provisional source (``orcapod.sources.PROVISIONAL_SOURCES``, ITL-1314)
has a default source id and a content hash that are not frozen
with data context v1. The warning is issued once per source kind per process, when
the source is constructed (also from a saved config).

Expand All @@ -923,6 +923,11 @@ class ProvisionalHashWarning(UserWarning):
category=ProvisionalHashWarning)`` after importing Orcapod. Python's ``-W`` option
and ``PYTHONWARNINGS`` cannot name this class: they are read before installed
packages can be imported.

Warning:
``tags_as_data`` may change or be removed in a later version (ITL-1020).
A non-empty mapping warns once per route per process. Prefer a data-tag
at the source, or start with data and promote it to a data-tag if needed.
"""


Expand Down
13 changes: 9 additions & 4 deletions src/orcapod/pipeline/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,7 @@ def load(
saved_connector_kind,
saved_database_kind,
saved_source_kind,
warn_saved_tags_as_data,
)

path = _Path(path)
Expand Down Expand Up @@ -2124,6 +2125,7 @@ def load(
except ValueError as exc:
raise ValueError(f"{path}: source {spec_name!r}: {exc}") from exc
failure: Exception | None = None
source: cp.StreamProtocol | None = None
try:
# Slots written with the same complete config share one rebuild.
config_key = _json.dumps(src_config, sort_keys=True)
Expand All @@ -2134,9 +2136,15 @@ def load(
deepcopy(src_config)
)
source = sources_by_config[config_key]
except Warning:
# A warning treated as an error propagates (ITL-1331).
raise
except Exception as exc:
failure = exc
else:
# A failed rebuild can leave a source or a nested source unbound.
# Check what the saved config uses regardless of what was rebuilt.
warn_saved_tags_as_data(src_config)
if failure is None:
if source is None:
unresolved_sources[spec_name] = src_config
continue
Expand Down Expand Up @@ -2167,9 +2175,6 @@ def load(
spec_name,
)
elif isinstance(failure, Warning):
# A warning turned into an error (a ProvisionalHashWarning under an
# error filter) is the caller's request: it propagates, never read as a
# source that could not be rebuilt (ITL-1331).
raise failure
elif failure is not None:
logger.warning(
Expand Down
Loading
Loading