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

- Run pipeline store conformance tests against Delta, in-memory, SQLite and the disk-backed SpiralDB fake.
6 changes: 6 additions & 0 deletions docs/concepts/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ batch = Batch(batch_size=10, drop_partial_batch=True)
of tag values are the only thing that tells a batch's members apart. `GroupBy` (below) has a
key and keeps only that.

`Batch` uses the order in which its source supplies rows. Treat rows read from a database
as a set unless the database documents an ordering guarantee. A stored source read from
SpiralDB can therefore produce different batch members than the same rows read from Delta.
Reading the rows a node holds for its current synchronous run still gives the order in
which that run passed them downstream.

### GroupBy

Collapses every set of rows that share a tag tuple into a single row -- the one many-to-one
Expand Down
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
from __future__ import annotations

import os
from collections.abc import Callable, Iterator
from pathlib import Path
from typing import TYPE_CHECKING

import pytest

if TYPE_CHECKING:
from orcapod.protocols.database_protocols import ArrowDatabaseProtocol


def _running_in_ci() -> bool:
"""Whether the tests run in CI: ``CI`` is ``true`` (or ``1``), as GitHub Actions sets it."""
Expand Down Expand Up @@ -65,3 +71,26 @@ def pytest_collection_modifyitems(
for item in items:
if any(mark.name == "postgres" for mark in item.iter_markers()):
item.add_marker(skip_marker)


@pytest.fixture
def pipeline_store_factory(
request: pytest.FixtureRequest, tmp_path: Path
) -> Iterator[Callable[[str], ArrowDatabaseProtocol]]:
"""Open named, isolated stores of the same backend for one test.

Disk-backed stores return a fresh handle for an existing name. In-memory
stores keep their original handle so a second open can see the same data.
"""
from tests.pipeline_stores import open_stores

with open_stores(request.param, tmp_path) as factory:
yield factory


@pytest.fixture
def pipeline_store(
pipeline_store_factory: Callable[[str], ArrowDatabaseProtocol],
) -> ArrowDatabaseProtocol:
"""An empty store for tests that only need one handle."""
return pipeline_store_factory("store")
81 changes: 81 additions & 0 deletions tests/pipeline_stores.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Backend parameters for shared pipeline store tests."""

from __future__ import annotations

from collections.abc import Callable, Iterator
from contextlib import ExitStack, contextmanager
from pathlib import Path

import pytest

from orcapod.databases import (
ConnectorArrowDatabase,
DeltaTableDatabase,
InMemoryArrowDatabase,
SpiralDBConnector,
SQLiteConnector,
)
from orcapod.protocols.database_protocols import ArrowDatabaseProtocol
from tests.test_databases import fake_pyspiral

from orcapod.errors import UnstorableColumnError

STORE_KINDS = ("in_memory", "delta", "sqlite", "spiral")

_SPIRAL_RESERVED_COLUMNS = pytest.param(
"spiral",
marks=pytest.mark.xfail(
strict=True,
raises=UnstorableColumnError,
reason="TODO-ITL: SpiralDB reserves the '__' prefix on value columns.",
),
)
_SQLITE_EXECUTOR_INFO = pytest.param(
"sqlite",
marks=pytest.mark.xfail(
strict=True,
raises=UnstorableColumnError,
reason="TODO-ITL: SQLite cannot store the function executor's list of structs.",
),
)

function_store_cases = pytest.mark.parametrize(
"pipeline_store_factory",
("in_memory", "delta", _SQLITE_EXECUTOR_INFO, _SPIRAL_RESERVED_COLUMNS),
indirect=True,
)
cache_store_cases = pytest.mark.parametrize(
"pipeline_store_factory",
("in_memory", "delta", "sqlite", _SPIRAL_RESERVED_COLUMNS),
indirect=True,
)


@contextmanager
def open_stores(
kind: str, root: Path
) -> Iterator[Callable[[str], ArrowDatabaseProtocol]]:
"""Open stores of one kind, with named namespaces for isolation and reopening."""
with ExitStack() as resources:
if kind == "spiral":
resources.enter_context(fake_pyspiral.install(root / "spiral"))
memory: dict[str, InMemoryArrowDatabase] = {}

def open_store(name: str) -> ArrowDatabaseProtocol:
"""Open a store and register any connector for teardown."""
if kind == "in_memory":
if name not in memory:
memory[name] = InMemoryArrowDatabase()
return memory[name]
if kind == "delta":
return DeltaTableDatabase(root / name)
if kind == "sqlite":
connector = SQLiteConnector(root / f"{name}.db")
elif kind == "spiral":
connector = SpiralDBConnector("p", dataset=name)
else:
raise AssertionError(f"Unknown test store: {kind}")
resources.callback(connector.close)
return ConnectorArrowDatabase(connector)

yield open_store
Loading
Loading