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: 11 additions & 0 deletions changelog.d/ITL-1467.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Added

- `RunSummary.skipped_unbound_sources` maps each skipped node to the unbound source slots that blocked it.

### Fixed

- Load-only run summaries report nodes skipped for unbound sources, including when no node ran.
- Loading a saved job leaves missing Delta stores, source caches, and SQLite input database files absent. A local Delta store requires directories for the saved root and any saved scope.
- Saving a loaded job retains the recorded locations of stores that could not be opened.
- Load-only runs read existing source cache rows without writing to the cache or changing the source state used by a full run.
- SQLite sources save the original filesystem path text, including for path-like objects. Restored sources preserve literal filenames, including `file:` prefixes and `..` after a symlink.
25 changes: 23 additions & 2 deletions docs/concepts/function-pods.md
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,11 @@ but it does compute the results that are missing. `job.run(load_only=True)` fill
with what is already stored for this run's inputs and never computes: sources are read,
operators run on the rows that reach them, each function node takes the stored results of
its inputs and skips the inputs that have none, no side effect is delivered and nothing is
written to the database. The summary counts what each node loaded and skipped:
written to the database. A cached source checks its store on each run and reads only the
rows already there. If it has no stored rows, it warns and supplies an empty input.
These cache snapshots, including those read through a derived source, leave the source's
full-run rows and modification time intact.
The summary counts what each node loaded and skipped:

```python
more_mice = mice + [{"subject_id": "mouse_04", "weight": 30.0, "height": 0.12}]
Expand Down Expand Up @@ -699,6 +703,10 @@ incomplete: a group formed after it may lack members, and the result stored for
group by an earlier run may then be loaded for it. `run_async(load_only=True)` does the same
on the asynchronous orchestrator.

A run skips unbound source slots and every node that depends on them. The summary lists those
nodes and the slots blocking each one in `summary.skipped_unbound_sources`. Bind the missing
sources with `job.bind(sources=...)` to include those nodes on the next run.

A load-only run reads only job nodes, sources and streams that neither compute nor deliver.
A pod's stream built outside the job (a function pod's, which computes when it is read, or a
side-effect pod's, which delivers) is refused with a `ValueError` before anything is read,
Expand Down Expand Up @@ -1023,6 +1031,19 @@ file saved by an earlier release (format `0.1.0` to `0.3.0`) is refused, with a
saying so. Rebuild the pipeline from code and save it again; taking older files to the
current format is the work of a separate migration tool, not of `load`.

For a saved local Delta database, `load()` requires directories for its saved root
and any saved scope. A directory can hold zero Delta tables. If either path is
missing or is a file, loading warns and
leaves the database unbound. Use
`PipelineJob.load(path, database=...)` to give the job a moved store, or
`PipelineJob.load(path, result_database=...)` for a moved separate result store.
If a cached source's Delta cache cannot be opened, its source slot stays unbound.
For a remote Delta database, the connection is deferred until the store is accessed.
Saving the loaded job retains unavailable store and source cache locations.

See [Saving and loading](pipeline-job.md#saving-and-loading) for how loading handles
SQLite source paths and write-ahead log files.

For example:

```python
Expand Down Expand Up @@ -1057,7 +1078,7 @@ loaded job cannot compute: function pods are not saved with it, so `loaded.run()
`loaded.run(load_only=True)` fills its nodes from the database instead, as for any job (see
*Loading without computing* above): the sources are read (an in-memory source must be bound
first, since its data is not saved), the rebuilt operators run, and each function node takes
the results stored for those inputs. Nodes below a source that is not available stay empty.
the results stored for those inputs. The run summary lists the nodes skipped for unbound sources.
`node.run(load_only=True)` does the same for one node and what it depends on.

```python
Expand Down
57 changes: 46 additions & 11 deletions docs/concepts/pipeline-job.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ tag_schema=Schema({...}), data_schema=Schema({...}))`) means one Arrow type per
zones, declare the slot with Arrow schemas (`tag_schema=pa.schema([...])`). Binding a source
never changes a node's schema or where its results are stored.

A job made without sources has **unbound** slots. It can still be run: nodes that depend on
an unbound source are skipped, and `job.unbound_sources` lists what is missing. Bind later
with `job.bind(...)`:
A job made without sources has **unbound** slots. It can still run the parts of the
pipeline with bound inputs. `job.unbound_sources` lists the missing slots, and
`summary.skipped_unbound_sources` maps each skipped node to the slots blocking it.
Bind a source later with `job.bind(...)`:

```python
job_c = PipelineJob.from_pipeline(pipeline, database=database)
Expand Down Expand Up @@ -478,11 +479,40 @@ the **Nodes** table below the picture for each node's columns and status.
## Saving and loading

`job.save(path)` writes the job to a JSON file: the graph, the database's location (and the
result database's, when one was given) and how each source was configured. `PipelineJob.load(path)` reads it back, for example in a later
Python session. An `InMemoryArrowDatabase` has no location to record, so here the database
is passed again; `PipelineJob.load(path, database=...)` is also how you point a loaded job
at a database that has moved, and `PipelineJob.load(path, result_database=...)` at a result
database. The file records each node's own Arrow types, so saving types
result database's, when one was given) and how each source was configured.
`PipelineJob.load(path)` reads it back, for example in a later Python session. Pass the
original `InMemoryArrowDatabase` again to read its rows in the same process. For a
local Delta store, loading requires existing directories for the saved root and
any saved scope under it.
If the path is missing or is a file, loading warns and leaves the database unbound.
This also applies to a source's Delta cache, in which case the source slot stays
unbound. Open a moved store by passing `database=...` or `result_database=...` to
`PipelineJob.load()`. Bind a cached source with `job.bind(sources=...)` after giving
it the cache's new location. An existing directory opens even if it holds no Delta
tables. A remote Delta store's location is checked when it is accessed.

Saving a loaded job keeps the recorded locations of databases and source caches
that could not be opened, so a later load can find them when they return.

Loading a job creates no files or directories, with one exception. If an existing
SQLite database uses write-ahead logging (WAL), you may see `-wal` and `-shm`
files appear next to it. SQLite can create these working files as part of opening
the database in read-only mode. This is expected and harmless. Orcapod writes
nothing to the database. A missing SQLite database file stays absent and its
source slot stays unbound.

SQLite saves the supplied path text and uses it in the default source ID. A
relative path stays relative in the saved job, so loading the job in a different
working directory reads relative to that directory. Each live or restored source
pins its absolute filename when built and keeps using it after a working-directory
change. SQLite treats a `file:` prefix as part of the filename and follows symlinks
as it opens the file, including when a symlink is followed by `..`.

The `create_base_path` option on `DeltaTableDatabase.from_config()` is
**provisional**. Passing `False` requires the saved local root and scope directories
to exist. Job loading uses this setting.

The file records each node's own Arrow types, so saving types
every node from its inputs' types, as previewing an empty job does, and costs what that
preview costs: a pipeline whose joins keep many system-tag columns saves as slowly as it
previews.
Expand All @@ -504,9 +534,9 @@ not their code, so a loaded job cannot compute:
`as_source()` read what the database holds for the node: here the three rows of cohort A
and the one of cohort B, because both cohorts were read through a source named `"mice"`.
- `loaded.run()` raises `RuntimeError`. To compute, run the code that defines the pipeline.
- `loaded.run(load_only=True)` fills the nodes with the stored results for the sources'
current rows, computing nothing. An in-memory source such as `DictSource` is not saved
with the job, so bind it first:
- `loaded.run(load_only=True)` fills the nodes with stored results for the bound
sources' current rows. It computes nothing. The data in a `DictSource` is kept in
memory, so the summary names the skipped nodes and their blocking slot until you bind it.

```python
try:
Expand All @@ -515,6 +545,11 @@ except RuntimeError:
print("a loaded job cannot compute")
# a loaded job cannot compute

print(loaded.run(load_only=True))
# Load-only run of job 'bmi': no nodes ran.
# 'bmi': skipped (unbound sources: 'mice')
# 'mice': skipped (unbound sources: 'mice')

loaded.bind(sources={"mice": mice(cohort_a)})
summary = loaded.run(load_only=True)
print(loaded.nodes["bmi"].as_table().num_rows, summary.nodes["bmi"].not_stored)
Expand Down
75 changes: 75 additions & 0 deletions docs/dev/plans/ITL-1467.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ITL-1467 — Report nodes skipped for unbound sources and open existing stores

## Reproduced on origin/main

Run `uv run python docs/dev/scripts/itl_1467/reproduce.py` on `5eb327ad`. A job
over a saved `DictSource` slot loads with the slot unbound. With either the
original in-memory database or a Delta database supplied, the downstream
function has zero rows and the summary says “nothing to do; every node holds a
current run.” Moving a relative Delta store and loading without an override
recreates the empty root in the current working directory. The stored view
returns zero rows and warns when read.

## Run summary

`PipelineJob._prepare_run` excludes unbound slots and their descendants before
`plan_run` applies the held-node state rule. The summary sees only the remaining
graph. An empty `plan.to_run` therefore cannot establish that every node was
held.

Carry the exclusion reasons through the job's shared run preparation and
completion paths. Propagate the unbound slot names through the saved graph and
include only restored job nodes in the result. Add
`RunSummary.skipped_unbound_sources: Mapping[str, tuple[str, ...]]`, keyed by
skipped node label with sorted, unique blocking slot names. Include unbound
slots themselves. Keep `RunSummary.nodes` and `NodeRunSummary.held` as the
function and side-effect row counts for the resolvable graph.
`ran_nothing` still means that no node was run.

When there are exclusions and no node ran, use this headline:

> Load-only run of job 'small': no nodes ran.

When a partial load-only run ran nodes and had no stored-result misses, use
`every available input had a stored result.` in place of
`every input had a stored result.` The stored-result miss headline stays the
same. Under the headline, in text and notebook HTML, list the excluded nodes
by label using this wording (both the node label and each slot name are
represented as Python strings):

```text
'joined': skipped (unbound sources: 'memory')
'memory': skipped (unbound sources: 'memory')
'total': skipped (unbound sources: 'memory')
```

Use the same skip lines for partial full runs of freshly compiled jobs. The
held headline still applies when there are no exclusions.

## Reopen the existing database

`DeltaTableDatabase.from_config` always requests local root creation, including
when the read-only job loader calls it. Give Delta config resolution a way to
require an existing local root. Use it for both the saved job and separate
result databases, so a missing root takes the existing load-time warning and
override/bind path. Continue honoring explicit overrides, relative path
resolution, and remote Delta behavior. Retain creation defaults for callers
that reconstruct a store for writing. Apply the same rule when rebuilding a
saved source's Delta cache. The root and any saved scope must be directories.
A missing directory or regular file leaves the binding unavailable, and saving
the job preserves the configuration. An existing directory can open with zero
Delta tables. Open existing SQLite source files read-only; SQLite can still
make its own working files while reading an existing WAL database. Restore the
embedded blueprint directly from the decoded job instead of using a temporary
file. There is no saved-format, stored-path, or identity change.

## Verification

Write public regression tests before library edits. Exercise memory and Delta,
sync and async, using a rebuilt CSV and a skipped in-memory source with two tag
and two data columns, a function and an operator. Check the summary fields and
text, including the no-execution and partial-execution cases and an unchanged
rerun. Check directory absence in a temporary working directory after loading
a moved Delta store, the warning and the explicit override. Update the
published load and load-only documentation and add the issue changelog
fragment. Run targeted tests and the golden check without updating goldens.
56 changes: 56 additions & 0 deletions docs/dev/scripts/itl_1467/reproduce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Reproduce both ITL-1467 symptoms on origin/main at 5eb327ad."""

from contextlib import chdir
from pathlib import Path
from tempfile import TemporaryDirectory

from orcapod import PipelineJob, function_pod
from orcapod.core.nodes import FunctionJobNode
from orcapod.databases import DeltaTableDatabase, InMemoryArrowDatabase
from orcapod.sources import DictSource


@function_pod(output_keys="total")
def total(x: int, y: int) -> int:
"""Add the two data values."""
return x + y


def make_job(database: InMemoryArrowDatabase | DeltaTableDatabase) -> None:
"""Run and save a job over a source whose data is not saved."""
source = DictSource(
[{"id": 1, "group": "a", "x": 2, "y": 3}],
tag_columns=["id", "group"],
tag_only_columns=True,
source_id="memory",
)
job = PipelineJob(name="small", database=database)
with job:
_ = total.pod(source, label="total")
_ = job.run()
job.save("job.json")


def main() -> None:
"""Show the load-only summary and the creation of a missing Delta root."""
with TemporaryDirectory() as directory, chdir(directory):
for database in (InMemoryArrowDatabase(), DeltaTableDatabase("store")):
make_job(database)
loaded = PipelineJob.load("job.json", database=database)
print(type(database).__name__, loaded.unbound_sources)
print(loaded.run(load_only=True))
node = loaded.nodes["total"]
assert isinstance(node, FunctionJobNode)
print("function rows:", node.as_table().num_rows)

_ = Path("store").rename("moved")
print("store exists before load:", Path("store").exists())
loaded = PipelineJob.load("job.json")
print("store exists after load:", Path("store").exists())
node = loaded.nodes["total"]
assert isinstance(node, FunctionJobNode)
print("stored rows:", node.as_source().as_table().num_rows)


if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ and what the pipeline imports must be there.
- The job was read with `PipelineJob.load()`. A loaded job's nodes read empty until
`loaded.run(load_only=True)`.
- A source of the job is not bound. `job.unbound_sources` lists such sources; the nodes
below them do not run.
below them do not run. The run summary's `skipped_unbound_sources` field names the
skipped nodes and which slots to bind.

**Fix.** Call `job.run()`, then read `job.nodes[label]`. To see everything the database
holds for a node, whatever run it came from, use `job.nodes[label].as_source()`.
Expand Down
44 changes: 23 additions & 21 deletions src/orcapod/core/nodes/function_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def run_job_node(
sources the check could not check; returns its ``RunSummary`` or ``None``.
caller: The frame of the ``run()`` caller.
"""
from orcapod.core.sources.cached_source import stored_source_caches
from orcapod.pipeline.node_run import (
check_sources,
depends_on_job_nodes,
Expand All @@ -385,27 +386,28 @@ def run_job_node(
from orcapod.pipeline.restrictions import refuse_restriction_conflicts
from orcapod.pipeline.run_summary import warn_row_failures

# A source read under two restrictions, or a caching operator over a restricted
# source, is refused before any source is checked and before anything is
# computed or written (ITL-1218).
refuse_restriction_conflicts([node])
# Every source feeding the run first takes in any new data (ITL-1102).
unchecked = check_sources([node])
if node.holds_current_run(load_only=load_only):
return
if depends_on_job_nodes(node):
summary = run_with_dependencies(
node, load_only=load_only, unchecked_sources=unchecked
)
else:
if load_only:
refuse_unloadable_inputs(node)
summary = run_alone(unchecked)
if summary is None:
return
node._last_run = summary
if not summary.ok:
warn_row_failures(summary, caller)
with stored_source_caches(load_only):
# A source read under two restrictions, or a caching operator over a restricted
# source, is refused before any source is checked and before anything is
# computed or written (ITL-1218).
refuse_restriction_conflicts([node])
# Every source feeding the run first takes in any new data (ITL-1102).
unchecked = check_sources([node])
if node.holds_current_run(load_only=load_only):
return
if depends_on_job_nodes(node):
summary = run_with_dependencies(
node, load_only=load_only, unchecked_sources=unchecked
)
else:
if load_only:
refuse_unloadable_inputs(node)
summary = run_alone(unchecked)
if summary is None:
return
node._last_run = summary
if not summary.ok:
warn_row_failures(summary, caller)


class FunctionNodeBase(StreamBase):
Expand Down
15 changes: 14 additions & 1 deletion src/orcapod/core/nodes/operator_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
logger = logging.getLogger(__name__)

if TYPE_CHECKING:
from types import FrameType
from orcapod.protocols.observability_protocols import ExecutionObserverProtocol


Expand Down Expand Up @@ -1882,6 +1883,18 @@ def run(self, *, load_only: bool = False) -> StreamView:
ValueError: If this node or one it depends on caches (``LOG`` or
``REPLAY``) over a restricted source (ITL-1218); nothing has run.
"""
from orcapod.core.sources.cached_source import stored_source_caches

with stored_source_caches(load_only):
return self._run_in_source_context(
load_only=load_only,
caller=sys._getframe(1), # pyright: ignore[reportPrivateUsage] # warning belongs at the caller's line
)

def _run_in_source_context(
self, *, load_only: bool, caller: FrameType
) -> StreamView:
"""Run with the source cache policy chosen by ``run()``."""
from orcapod.pipeline.node_run import (
check_sources,
depends_on_job_nodes,
Expand All @@ -1907,7 +1920,7 @@ def run(self, *, load_only: bool = False) -> StreamView:
)
self._last_run = summary
if not summary.ok:
warn_row_failures(summary, sys._getframe(1)) # pyright: ignore[reportPrivateUsage] # the caller's line is where the warning is shown
warn_row_failures(summary, caller)
return self._run_view(computed=False)
if self._loaded:
raise self._cannot_compute_error()
Expand Down
Loading
Loading