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
16 changes: 16 additions & 0 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,22 @@ data. The rules:
datagrams' Arrow tables (as_table()), never from as_dict() values, and take the data
context from those datagrams (data_context_key). Add new async operators to
tests/test_core/operators/test_async_sync_equivalence.py.
- Record-batch channels (ITL-1347, ITL-1362; not wired into nodes or orchestrators yet):
orcapod.core.record_batch_channels.InputChannel / OutputChannel carry a stream's rows as
Arrow record batches; operators see them only through the protocols RecordBatchInput /
RecordBatchOutput of protocols/core_protocols/record_batch_channels.py, which imports no
concrete core module (keep modules interacting through protocols: basedpyright counts local
and TYPE_CHECKING imports as import cycles). A channel owns no description: an input channel
refers to its stream (channel_from_stream(stream)), an output channel to the stream it
produces, and OutputChannel.result() closes it into that stream. The conversions are in one
place, core/operators/static_output_pod.py (stream_from_batches, transport_schema, and F,
_row_built_form); never build a stream from record batches elsewhere. An operator's
record-batch form (async_execute_batches, renamed async_execute when wired) applies its one
static_process body: per record batch when the class declares ROW_BY_ROW = True (each output
row comes from one input row), otherwise as a barrier over the whole input (to_stream());
Batch with a size has its own form, grouping rows by arrival. A new operator whose output
rows each come from one input row declares ROW_BY_ROW; write no other per-operator batch
code.
- The type converter keys synthesized struct classes by the large-normalized struct, so
struct<b: string> and struct<b: large_string> are one Python type (a workaround,
TODO(ITL-841)).
Expand Down
16 changes: 16 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,22 @@ data. The rules:
datagrams' Arrow tables (`as_table()`), never from `as_dict()` values, and take the data
context from those datagrams (`data_context_key`). Add new async operators to
`tests/test_core/operators/test_async_sync_equivalence.py`.
- Record-batch channels (ITL-1347, ITL-1362; not wired into nodes or orchestrators yet):
`orcapod.core.record_batch_channels.InputChannel` / `OutputChannel` carry a stream's rows as
Arrow record batches; operators see them only through the protocols `RecordBatchInput` /
`RecordBatchOutput` of `protocols/core_protocols/record_batch_channels.py`, which imports no
concrete core module (keep modules interacting through protocols: basedpyright counts local
and `TYPE_CHECKING` imports as import cycles). A channel owns no description: an input
channel refers to its stream (`channel_from_stream(stream)`), an output channel to the
stream it produces, and `OutputChannel.result()` closes it into that stream. The conversions
are in one place, `core/operators/static_output_pod.py` (`stream_from_batches`,
`transport_schema`, and F, `_row_built_form`); never build a stream from record batches
elsewhere. An operator's record-batch form (`async_execute_batches`, renamed `async_execute`
when wired) applies its one `static_process` body: per record batch when the class declares
`ROW_BY_ROW = True` (each output row comes from one input row), otherwise as a barrier over
the whole input (`to_stream()`); `Batch` with a size has its own form, grouping rows by
arrival. A new operator whose output rows each come from one input row declares
`ROW_BY_ROW`; write no other per-operator batch code.
- The type converter keys synthesized struct classes by the large-normalized struct, so
`struct<b: string>` and `struct<b: large_string>` are one Python type (a workaround,
`TODO(ITL-841)`).
Expand Down
2 changes: 2 additions & 0 deletions src/orcapod/core/operators/add_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class AddTags(UnaryOperator):
PROVISIONAL: ClassVar[bool] = True

# Data-tags pass through as they are; the new tags are plain (ITL-1023).
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(self, tags: Mapping[str, TagConstant], **kwargs: Any):
Expand Down
63 changes: 62 additions & 1 deletion src/orcapod/core/operators/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@
import pyarrow as pa

from orcapod.core.operators.meta_columns import WithoutMetaWriter
from orcapod.channels import ReadableChannel, WritableChannel
from orcapod.protocols.core_protocols.record_batch_channels import (
RecordBatchInput,
RecordBatchOutput,
)
from orcapod.channels import (
ReadableChannel,
WritableChannel,
)
from orcapod.core.operators.base import UnaryOperator
from orcapod.core.operators.static_output_pod import (
close_inputs,
with_open_provenance_flags,
)
from orcapod.core.data_tags import stream_data_tags
from orcapod.core.streams import ArrowTableStream
from orcapod.protocols.core_protocols import DataProtocol, StreamProtocol, TagProtocol
Expand Down Expand Up @@ -264,6 +275,56 @@ async def async_execute(
finally:
await output.close()

async def async_execute_batches(
self, inputs: Sequence[RecordBatchInput], output: RecordBatchOutput
) -> None:
"""Batch the rows of an input channel as they arrive.

The Arrow-record-batch form of ``async_execute`` (ITL-1347). With a
``batch_size``, every ``batch_size`` rows that have arrived are batched and
sent at once, whatever record batches they came in, so a batch holds
consecutive arrivals, as on the row path; the rows left at the end make the
last, smaller batch unless ``drop_partial_batch``. With ``batch_size == 0``
(every row in one batch) all of the input is read first.

Args:
inputs: The one input channel.
output: The channel the batched rows are sent into.
"""
if self.batch_size == 0:
await super().async_execute_batches(inputs, output)
return
(channel,) = inputs
try:
waiting: list[pa.RecordBatch] = []
rows = 0
async for batch in channel:
if not batch.num_rows:
continue # nothing to batch, nothing to hold
# Arrived batches may differ in their provenance flags: open them so
# they concatenate (the flags are set again by the values).
waiting.append(with_open_provenance_flags(batch))
rows += batch.num_rows
full = rows - rows % self.batch_size
if not full:
continue
arrived = pa.Table.from_batches(waiting)
await self._send_processed(
arrived.slice(0, full).to_batches(), channel.stream, output
)
waiting = arrived.slice(full).to_batches()
rows -= full
# The rows left over are fewer than one batch: the sync rule decides
# whether they make a last one.
if rows:
await self._send_processed(waiting, channel.stream, output)
await output.close()
except BaseException as error:
output.fail(error)
await close_inputs(inputs, error)
raise
await close_inputs(inputs)

def to_config(self) -> dict[str, Any]:
"""Serialize this Batch operator to a config dict.

Expand Down
10 changes: 10 additions & 0 deletions src/orcapod/core/operators/column_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class SelectTagColumns(UnaryOperator):
"""

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(self, columns: str | Collection[str], strict: bool = True, **kwargs):
Expand Down Expand Up @@ -195,6 +197,8 @@ class SelectDataColumns(UnaryOperator):
"""

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(self, columns: str | Collection[str], strict: bool = True, **kwargs):
Expand Down Expand Up @@ -349,6 +353,8 @@ class DropTagColumns(UnaryOperator):
"""

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(self, columns: str | Collection[str], strict: bool = True, **kwargs):
Expand Down Expand Up @@ -491,6 +497,8 @@ class DropDataColumns(UnaryOperator):
"""

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(self, columns: str | Collection[str], strict: bool = True, **kwargs):
Expand Down Expand Up @@ -669,6 +677,8 @@ class _TagAndDataColumnsOperator(UnaryOperator, ABC):
"""

# Data-tags: handled (ITL-1022). A name acts on both roles alike.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

_verb: ClassVar[str] = ""
Expand Down
2 changes: 2 additions & 0 deletions src/orcapod/core/operators/drop_nulls.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class DropNulls(UnaryOperator):
"""

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(
Expand Down
2 changes: 2 additions & 0 deletions src/orcapod/core/operators/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Index(UnaryOperator):
PROVISIONAL: ClassVar[bool] = True

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(
Expand Down
6 changes: 6 additions & 0 deletions src/orcapod/core/operators/mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class MapData(UnaryOperator):
"""

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(
Expand Down Expand Up @@ -332,6 +334,8 @@ class MapTags(UnaryOperator):
PROVISIONAL: ClassVar[bool] = True

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(
Expand Down Expand Up @@ -618,6 +622,8 @@ class MapColumns(UnaryOperator):
"""

# Provisional: its identity is not frozen with data context v1 (ITL-1279).
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
PROVISIONAL: ClassVar[bool] = True

def __init__(
Expand Down
2 changes: 2 additions & 0 deletions src/orcapod/core/operators/pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Pick(UnaryOperator):
PROVISIONAL: ClassVar[bool] = True

# Data-tags (ITL-1023): handled.
# Each output row comes from one input row (ITL-1347).
ROW_BY_ROW: ClassVar[bool] = True
DATA_TAGS_ISSUE: ClassVar[str | None] = None

def __init__(
Expand Down
Loading
Loading