diff --git a/src/orcapod/core/nodes/source_node.py b/src/orcapod/core/nodes/source_node.py index 76736f987..2ecc0262b 100644 --- a/src/orcapod/core/nodes/source_node.py +++ b/src/orcapod/core/nodes/source_node.py @@ -7,7 +7,6 @@ from __future__ import annotations -from collections import deque import contextlib import dataclasses @@ -30,16 +29,16 @@ from orcapod.core.streams.arrow_table_stream import ArrowTableStream from orcapod.core.streams.base import ( ZERO_ROW_INPUT_COLUMNS, + CompleteStreamFeed, keys_of_rows, system_tags_as_rows_give, - row_built_columns, stream_arrow_schema, schema_requires_io, typed_arrow_schemas, typed_zero_row_input, typed_zero_row_table, ) -from orcapod.core.streams.record_batch_input import SOURCE_BATCH_ROWS, InputChannel +from orcapod.core.streams.record_batch_input import InputChannel from orcapod.core.streams.view import ( ViewStatus, StreamView, @@ -427,42 +426,52 @@ def _require_stream_arrow_types(stream: Any, slot: str) -> None: class _ExecuteOutputFeed: """The record batches of a source node's own ``execute()`` output. - Built at the first read from the output stream ``execute()`` gives (ITL-1347, - stage 2: the table a job hands on, already in the row-built form). One binding is - read, at that moment. A batch is dropped once delivered. + The channel of the output stream ``execute()`` gives (ITL-1347, stage 2: the table + a job hands on, already in the row-built form), built at the first read: one + binding is read, at that moment. A batch is dropped once delivered. """ def __init__(self, node: SourceNodeBase) -> None: - """Make the feed; nothing is read until the first ``next``. + """Make the feed; nothing is read until the first read. Args: node: The source node whose output it delivers. """ self._node = node - self._batches: deque[pa.RecordBatch] | None = None + self._output: StreamProtocol | None = None + self._feed: CompleteStreamFeed | None = None + + def _output_feed(self) -> CompleteStreamFeed: + """The feed of the node's output stream, made on the first read.""" + if self._feed is None: + self._output = self._node.execute() + self._feed = CompleteStreamFeed(self._output) + return self._feed async def next(self) -> pa.RecordBatch | None: """Return the next record batch of the node's output, or ``None`` at the end.""" - if self._batches is None: - output = self._node.execute() - table = row_built_columns( - output.as_table(columns=ZERO_ROW_INPUT_COLUMNS), output.keys() - ) - self._batches = deque( - batch - for batch in table.to_batches(max_chunksize=SOURCE_BATCH_ROWS) - if batch.num_rows - ) - return self._batches.popleft() if self._batches else None + return await self._output_feed().next() def close(self) -> None: """Stop reading: the batches not read are dropped.""" - self._batches = deque() + if self._feed is not None: + self._feed.close() + else: + self._feed = _closed_feed(self._node) @property def opened_on(self) -> StreamProtocol | None: - """``None``: the node is not the stream its batches rebuild.""" - return None + """The node's output stream, read on this first access (a conversion's first + read): a channel not read yet gives it as it is when it is a complete output + in the row-built form.""" + return self._output_feed().opened_on + + +def _closed_feed(node: SourceNodeBase) -> CompleteStreamFeed: + """A feed closed before its first read: it reads nothing and delivers nothing.""" + feed = CompleteStreamFeed(node) + feed.close() + return feed class SourceNodeBase(TraceableBase, ABC): diff --git a/src/orcapod/core/operators/batch.py b/src/orcapod/core/operators/batch.py index e17e28fd4..59b970577 100644 --- a/src/orcapod/core/operators/batch.py +++ b/src/orcapod/core/operators/batch.py @@ -18,7 +18,7 @@ from orcapod.core.operators.base import UnaryOperator from orcapod.core.operators.static_output_pod import ( close_inputs, - with_open_provenance_flags, + concatenate_batches, ) from orcapod.core.data_tags import stream_data_tags from orcapod.core.streams import ArrowTableStream @@ -301,14 +301,15 @@ async def async_execute_batches( 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)) + waiting.append(batch) rows += batch.num_rows full = rows - rows % self.batch_size if not full: continue - arrived = pa.Table.from_batches(waiting) + # Arrived batches may differ in their provenance fields: put them + # under one another as a complete table settles them. + arrived = concatenate_batches(waiting) + assert arrived is not None # they hold rows await self._send_processed( arrived.slice(0, full).to_batches(), channel.stream, output ) diff --git a/src/orcapod/core/operators/static_output_pod.py b/src/orcapod/core/operators/static_output_pod.py index fbc698435..2764dfca2 100644 --- a/src/orcapod/core/operators/static_output_pod.py +++ b/src/orcapod/core/operators/static_output_pod.py @@ -8,6 +8,7 @@ Collection, Iterable, Iterator, + Mapping, Sequence, ) from datetime import datetime, timezone @@ -1175,51 +1176,6 @@ async def _streams_of(inputs: Sequence[RecordBatchInput]) -> list[StreamProtocol # --------------------------------------------------------------------------- -def transport_schema(stream: StreamProtocol) -> pa.Schema | None: - """Return the schema ``stream``'s record batches have, from its description. - - Never computes, reads or polls a row: the stream's zero-row input with the columns - of F in F's order (``row_built_names``) and its provenance fields as a row builds - them (``row_built_provenance``), as ``stream_arrow_schema`` of stage 2 gives it. A - ``null`` type is kept, as the description declares it (record batches carry it as - ``large_string``, holding only nulls). The flags of system-tag and source-info - fields are not part of it: they follow the values of the complete table. - - Args: - stream: The describing stream. - - Returns: - The schema, or ``None`` for a stream that cannot say its Arrow types without - rows (an unbound input slot, a source that has not polled yet, a description - whose types are undeclared: ``arrow_types_declared`` false). - """ - # TODO(ITL-1360): ``stream.arrow_schema()``, once every stream has it. - from orcapod.core.streams.base import row_built_names, row_built_provenance - from orcapod.utils import arrow_utils - - if not getattr(stream, "arrow_types_declared", True): - # The rows decide the types (and the column order) of a description whose - # types are undeclared (a narrower bind, ``RowsOnRead``): the first batch sets - # them. - return None - typed = StaticOutputOperatorPod._zero_row_input(stream) # pyright: ignore[reportPrivateUsage] # the zero-row form of an input - if typed is None: - return None - zero_rows = typed.as_table(columns=ZERO_ROW_INPUT_COLUMNS) - zero_rows = zero_rows.cast( - pa.schema( - [ - field.with_type( - arrow_utils.normalize_to_large_types(field.type, keep_null=True) - ) - for field in zero_rows.schema - ] - ) - ) - names = row_built_names(zero_rows.column_names, stream.keys()) - return row_built_provenance(zero_rows.select(names)).schema - - ROW_BUILT_OUTPUT = "_orcapod_row_built_output" """The attribute that marks a complete node output in the row-built form (ITL-1347). @@ -1256,7 +1212,9 @@ def stream_from_batches( """ if not batches: return StaticOutputOperatorPod._materialize_upstream([], stream) # pyright: ignore[reportPrivateUsage] # the zero-row input of an operator - table = pa.Table.from_batches([with_open_provenance_flags(b) for b in batches]) + table = concatenate_batches(batches) + if table is None: + return StaticOutputOperatorPod._materialize_upstream([], stream) # pyright: ignore[reportPrivateUsage] # the zero-row input of an operator return StaticOutputOperatorPod._output_stream( # pyright: ignore[reportPrivateUsage] # F and the identity, stage 2's table, _keys_in_delivered_order(stream.keys(), table.column_names), stream ) @@ -1292,28 +1250,119 @@ def _keys_in_delivered_order( return ordered_tags, data_tags + plain -def with_open_provenance_flags(batch: pa.RecordBatch) -> pa.RecordBatch: - """Flag every system-tag and source-info field of ``batch`` nullable. +def settle_token_types( + batch: pa.RecordBatch, accepted: Mapping[str, pa.DataType] +) -> dict[str, pa.DataType]: + """Each source-info column's token type, settled with the batches accepted so far. - Record batches of one channel differ at most in these flags: each is built from its - own rows (``row_built_columns`` leaves them, ``_flag_by_values`` sets them over a - complete table). Opened, they have one schema and can be put under one another; - the complete table's flags are then set by its values. The same arrays. + A source-info column's type follows its tokens over the complete table, as a row + types each token from its value (``arrow_utils.source_info_arrow_type``, the one + rule ``_type_source_info_by_values`` applies). A batch with no rows has no token + and settles nothing. Every token of the batch must then be representable in its + column's settled type, so that the complete table can be built. Args: batch: A record batch of a stream's rows. + accepted: Each column's token type from the batches accepted so far. + + Returns: + The token types with this batch accepted. + + Raises: + SourceInfoTypesDisagree: If the batch's tokens give a column two types, or a + type other than the accepted batches'. + RowBuiltFormUnavailable: If a token cannot be represented in its column's + settled type. + """ + from orcapod.utils import arrow_utils + + settled = dict(accepted) + if not batch.num_rows: + return settled # no token: nothing to learn + for field, column in zip(batch.schema, batch.columns, strict=True): + if not field.name.startswith(constants.SOURCE_PREFIX): + continue + kinds: set[pa.DataType] + if pa.types.is_large_string(field.type): + kinds = {pa.large_string()} + else: + kinds = { + arrow_utils.source_info_arrow_type(value) + for value in column.to_pylist() + } + if field.name in settled: + kinds.add(settled[field.name]) + if len(kinds) > 1: + raise SourceInfoTypesDisagree(field.name) + (kind,) = kinds + _ = _tokens_as(column, kind, field.name) # representable, or refused + settled[field.name] = kind + return settled + + +def _tokens_as( + column: pa.Array[Any], + kind: pa.DataType, + name: str, # pyright: ignore[reportExplicitAny] # any column +) -> pa.Array[Any]: # pyright: ignore[reportExplicitAny] # any column + """``column``'s tokens as an array of ``kind``: the same array when it has that type. + + Raises: + RowBuiltFormUnavailable: If a token cannot be represented as ``kind``. + """ + if column.type == kind: + return column + try: + return pa.array(column.to_pylist(), type=kind) + except (pa.ArrowInvalid, pa.ArrowTypeError, TypeError, ValueError) as error: + raise RowBuiltFormUnavailable( + f"{name}: a token cannot be represented as {kind} ({error})" + ) from error + + +def concatenate_batches(batches: Sequence[pa.RecordBatch]) -> pa.Table | None: + """Put a stream's record batches under one another, or ``None`` with no row. + + Batches built from different rows may differ in their provenance fields: a + system-tag or source-info field's nullability, and a source-info column's token + type, follow each batch's own values. Each source-info column is brought to the + type its tokens settle over all the batches (``settle_token_types``), and every + provenance field is flagged nullable, so that the batches have one schema; the + complete table's flags and types are then set by its values (``_row_built_form``). + A batch with no rows is left out. The values are unchanged. + + Args: + batches: Record batches of one stream's rows, in order. Returns: - The batch with those fields nullable. + The table, or ``None`` when no batch has a row. + + Raises: + SourceInfoTypesDisagree: If the tokens give a source-info column two types. + RowBuiltFormUnavailable: If a token cannot be represented in its column's + settled type. """ + rows = [batch for batch in batches if batch.num_rows] + if not rows: + return None + settled: dict[str, pa.DataType] = {} + for batch in rows: + settled = settle_token_types(batch, settled) prefixes = (constants.SYSTEM_TAG_PREFIX, constants.SOURCE_PREFIX) - schema = pa.schema( - [ - field.with_nullable(True) if field.name.startswith(prefixes) else field - for field in batch.schema - ] - ) - return pa.RecordBatch.from_arrays(batch.columns, schema=schema) + opened: list[pa.RecordBatch] = [] + for batch in rows: + columns: list[Any] = [] # pyright: ignore[reportExplicitAny] # any column + fields: list[pa.Field[Any]] = [] # pyright: ignore[reportExplicitAny] # any field + for field, column in zip(batch.schema, batch.columns, strict=True): + if field.name in settled: + column = _tokens_as(column, settled[field.name], field.name) + field = pa.field(field.name, settled[field.name]) + if field.name.startswith(prefixes): + field = field.with_nullable(True) + columns.append(column) + fields.append(field) + opened.append(pa.RecordBatch.from_arrays(columns, schema=pa.schema(fields))) + return pa.Table.from_batches(opened) class RowsOnRead: diff --git a/src/orcapod/core/record_batch_channels.py b/src/orcapod/core/record_batch_channels.py index d744f3c22..3135f3f15 100644 --- a/src/orcapod/core/record_batch_channels.py +++ b/src/orcapod/core/record_batch_channels.py @@ -22,9 +22,8 @@ from orcapod.channels import ChannelClosed from orcapod.core.operators.static_output_pod import ( - SourceInfoTypesDisagree, + settle_token_types, stream_from_batches, - transport_schema, ) from orcapod.core.streams.base import row_built_names from orcapod.core.streams.record_batch_input import InputChannel @@ -152,7 +151,7 @@ def __init__( self._schema: pa.Schema | None = None self._schema_known = False # Each source-info column's token type as the batches accepted so far settle it - # (``_settled_token_types``): a later batch must settle with it. + # (``settle_token_types``): a later batch must settle with it. self._token_types: dict[str, pa.DataType] = {} self._changed = asyncio.Event() @@ -188,8 +187,15 @@ def _raise_if_ended(self) -> None: def _check_schema(self, batch: pa.RecordBatch) -> None: """Raise unless ``batch`` has the schema of this channel's record batches.""" + names = batch.schema.names + if len(set(names)) != len(names): + repeated = sorted({name for name in names if names.count(name) > 1}) + raise ValueError( + f"A record batch sent as {_named(self._stream)} has a column more than " + + f"once: {repeated}." + ) if not self._schema_known: - self._schema = transport_schema(self._stream) + self._schema = _description(self._stream) self._schema_known = True schema = self._schema if schema is None: @@ -211,7 +217,7 @@ def _check_schema(self, batch: pa.RecordBatch) -> None: f"A record batch sent as {_named(self._stream)} does not have that " + f"stream's columns: {mismatch}." ) - token_types = _settled_token_types(batch, self._token_types) + token_types = settle_token_types(batch, self._token_types) self._schema = schema self._token_types = token_types @@ -356,53 +362,28 @@ def result(self) -> StreamProtocol: return self._result -def _named(stream: Any) -> str: # pyright: ignore[reportExplicitAny] # any stream or node - """How an error names a stream: its label, or what it prints as.""" - label = getattr(stream, "label", None) - return repr(label) if label else repr(stream) - +def _description(stream: StreamProtocol) -> pa.Schema | None: + """The Arrow schema the stream declares for its record batches, or ``None``. -def _settled_token_types( - batch: pa.RecordBatch, accepted: dict[str, pa.DataType] -) -> dict[str, pa.DataType]: - """Each source-info column's token type, settled with the batches already accepted. - - A source-info column's type follows its tokens over the complete table - (``StaticOutputOperatorPod._type_source_info_by_values``): the description leaves it - open, but the channel's batches must settle together, or their result could not be - built. A batch whose tokens give a column a type the accepted batches do not is - refused at send, with the error the complete table would raise. + ``stream.arrow_schema()``: never computes, reads or polls a row. ``None`` when its + types are not declared (``arrow_types_declared`` is false: an unbound slot, a + source not polled yet, a narrower bind whose rows decide), or when its columns + are known only from rows (an empty schema): the first batch then sets the types, + and the names are checked against the stream's keys. Args: - batch: The batch being sent. - accepted: Each column's token type from the batches accepted so far. + stream: The describing stream. + """ + if not stream.arrow_types_declared: + return None + schema = stream.arrow_schema() + return schema if len(schema) else None - Returns: - The token types with this batch accepted. - Raises: - SourceInfoTypesDisagree: If the batch's tokens give a column two types, or a - type other than the accepted batches'. - """ - settled = dict(accepted) - for field, column in zip(batch.schema, batch.columns, strict=True): - if not field.name.startswith(constants.SOURCE_PREFIX): - continue - kinds: set[pa.DataType] - if pa.types.is_large_string(field.type): - kinds = {pa.large_string()} - else: - kinds = { - arrow_utils.source_info_arrow_type(value) - for value in column.to_pylist() - } - if field.name in settled: - kinds.add(settled[field.name]) - if len(kinds) > 1: - raise SourceInfoTypesDisagree(field.name) - if kinds: - (settled[field.name],) = kinds - return settled +def _named(stream: Any) -> str: # pyright: ignore[reportExplicitAny] # any stream or node + """How an error names a stream: its label, or what it prints as.""" + label = getattr(stream, "label", None) + return repr(label) if label else repr(stream) def _schema_mismatch(declared: pa.Schema, batch: pa.RecordBatch) -> str | None: diff --git a/src/orcapod/core/streams/base.py b/src/orcapod/core/streams/base.py index d2ec40632..3fc99d3ca 100644 --- a/src/orcapod/core/streams/base.py +++ b/src/orcapod/core/streams/base.py @@ -537,7 +537,9 @@ async def next(self) -> pa.RecordBatch | None: # The table first: reading it is the stream's one read (an unpolled # source polls here), and its keys are then known without another. table = self._stream.as_table(columns=ZERO_ROW_INPUT_COLUMNS) - table = row_built_columns(table, self._stream.keys()) + # The rows' keys: a source whose keys() states its declared order has + # rows in its table's order (``keys_of_rows``). + table = row_built_columns(table, keys_of_rows(table, self._stream.keys())) self._batches = deque( batch for batch in table.to_batches(max_chunksize=SOURCE_BATCH_ROWS) diff --git a/tests/test_channels/test_record_batch_channels.py b/tests/test_channels/test_record_batch_channels.py index e2836eddf..c9aafc50d 100644 --- a/tests/test_channels/test_record_batch_channels.py +++ b/tests/test_channels/test_record_batch_channels.py @@ -32,12 +32,18 @@ ReadableChannel, WritableChannel, ) -from orcapod.core.operators import MapData, PolarsFilter, SelectDataColumns, SemiJoin +from orcapod.core.operators import ( + Batch, + MapData, + PolarsFilter, + SelectDataColumns, + SemiJoin, +) from orcapod.core.operators.static_output_pod import ( ROW_BUILT_OUTPUT, + RowBuiltFormUnavailable, StaticOutputOperatorPod, stream_from_batches, - transport_schema, ) from orcapod.core.record_batch_channels import ( BATCH_BUFFER_SIZE, @@ -306,14 +312,6 @@ async def read() -> tuple[list[str], list[str]]: assert rebuilt == delivered -@pytest.mark.xfail( - strict=True, - raises=ValueError, - reason="ITL-1365: a source node whose plain tags are declared in another order " - "than their columns (x, j, k, y with tags k, j) describes itself in the slot's " - "order (keys() j, k; its zero-row input too, as on main), while its rows are in " - "the bound source's order, so its own description refuses its batches", -) def test_a_source_nodes_description_takes_its_rows_in_their_own_order() -> None: """Plain tags declared ``k, j`` over physical columns ``x, j, k, y``: the node's own output channel takes the batches its channel delivers.""" @@ -1432,7 +1430,7 @@ def test_without_arrow_types_the_names_are_still_the_streams() -> None: stream = _UntypedStream( table, tag_columns=["subject", "trial"], data_tags=["trial"] ) - assert transport_schema(stream) is None + assert not stream.arrow_types_declared # no Arrow types without rows (batch,) = batches_of(stream) renamed = batch.rename_columns( ["other" if name == "note" else name for name in batch.schema.names] @@ -1924,7 +1922,7 @@ async def write() -> None: output = OutputChannel(stream) await output.send(doubled) - with pytest.raises(ValueError, match="the stream's keys are"): + with pytest.raises(ValueError, match="a column more than once"): run(write) @@ -1954,3 +1952,149 @@ async def write() -> None: with pytest.raises(SourceInfoTypesDisagree, match=column): run(write) + + +# --- Batches that settle together (Codex on PR #485, final check, findings 3-5) ------------ + +TOKEN = pa.large_string() +TOKENS = pa.large_list(TOKEN) +TOKEN_LISTS = pa.large_list(TOKENS) + + +def _with_amplitude_tokens( + batch: pa.RecordBatch, start: int, values: list[Any], kind: pa.DataType +) -> pa.RecordBatch: + """Rows ``start ...`` of ``batch`` with ``_source_amplitude`` carried as ``kind`` + holding ``values`` (tokens of one row each).""" + part = batch.slice(start, len(values)) + index = part.schema.get_field_index("_source_amplitude") + return pa.RecordBatch.from_arrays( + [ + *part.columns[:index], + pa.array(values, type=kind), + *part.columns[index + 1 :], + ], + schema=part.schema.set(index, pa.field("_source_amplitude", kind)), + ) + + +SETTLING_CASES: dict[ + str, tuple[list[tuple[int, list[Any], pa.DataType]], pa.DataType, list[Any]] +] = { + # An empty token list carried two levels deep, then a token list: both settle as + # one level of tokens. + "list_depth": ([(0, [[]], TOKEN_LISTS), (1, [["b"]], TOKENS)], TOKENS, [[], ["b"]]), + # A null token carried as a list, then a string token: both settle as strings. + "null_then_string": ([(0, [None], TOKENS), (1, ["b"], TOKEN)], TOKEN, [None, "b"]), + # Lists that differ only in their item field's nullability. + "item_nullability": ( + [ + (0, [["a"]], pa.large_list(pa.field("item", TOKEN, nullable=False))), + (1, [["b"]], TOKENS), + ], + TOKENS, + [["a"], ["b"]], + ), + # A batch with no rows has no token and fixes no type. + "zero_rows_first": ( + [(0, [], TOKEN), (0, [["a"]], TOKENS), (1, [["b"]], TOKENS)], + TOKENS, + [["a"], ["b"]], + ), +} + + +@pytest.mark.parametrize("case", list(SETTLING_CASES)) +def test_batches_send_accepts_are_assembled(case: str) -> None: + """What ``send`` accepts can be assembled: ``result()`` and ``to_stream()`` build + the complete table, each source-info column of the type its tokens settle.""" + stream = source(2) + (batch,) = batches_of(stream) + parts, settled, tokens = SETTLING_CASES[case] + + async def write() -> tuple[Any, Any]: + output = OutputChannel(stream) + reader = output.open_reader() + for start, values, kind in parts: + await output.send(_with_amplitude_tokens(batch, start, values, kind)) + await output.close() + return output.result(), await reader.to_stream() + + result, converted = run(write) + for assembled in (result, converted): + table = assembled.as_table(columns=ALL) + assert table.schema.field("_source_amplitude").type == settled + assert table.column("_source_amplitude").to_pylist() == tokens + + +def test_a_token_that_cannot_be_represented_is_refused_at_send() -> None: + """A token that has no place in its column's settled type (``[[], [[]]]`` carried + three levels deep) is refused at send; the channel takes valid batches after it.""" + stream = source(2) + (batch,) = batches_of(stream) + deep = pa.large_list(TOKEN_LISTS) + + async def write() -> list[Any]: + output = OutputChannel(stream) + with pytest.raises(RowBuiltFormUnavailable, match="cannot be represented"): + await output.send(_with_amplitude_tokens(batch, 0, [[[], [[]]]], deep)) + await output.send(_with_amplitude_tokens(batch, 0, [["a"]], TOKENS)) + await output.close() + return ( + output.result() + .as_table(columns=ALL) + .column("_source_amplitude") + .to_pylist() + ) + + assert run(write) == [["a"]] + + +def test_a_duplicate_system_tag_column_is_refused_on_a_declared_stream() -> None: + """A batch with a system-tag column twice is refused, whatever the description.""" + stream = source(2) + (batch,) = batches_of(stream) + name = next(n for n in batch.schema.names if n.startswith("_tag")) + doubled = batch.append_column(batch.schema.field(name), batch.column(name)) + + async def write() -> None: + await OutputChannel(stream).send(doubled) + + with pytest.raises(ValueError, match="a column more than once"): + run(write) + + +def test_batch_puts_arrivals_with_differing_token_types_together() -> None: + """``Batch(2)`` over arrivals whose source-info tokens are carried in two types (an + empty list two levels deep, then a token list): it groups them, as a complete table + settles them.""" + stream = source(2) + (batch,) = batches_of(stream) + op = Batch(batch_size=2) + + async def go() -> Any: + feed = OutputChannel(stream) + reader = feed.open_reader() + await feed.send(_with_amplitude_tokens(batch, 0, [[]], TOKEN_LISTS)) + await feed.send(_with_amplitude_tokens(batch, 1, [["b"]], TOKENS)) + await feed.close() + output = OutputChannel(op(stream)) + await op.async_execute_batches([reader], output) + return output.result() + + table = run(go).as_table(columns=ALL) + assert table.num_rows == 1 + assert table.column("_source_amplitude").to_pylist() == [[[], ["b"]]] + + +def test_a_source_nodes_channel_gives_its_output_stream_as_it_is() -> None: + """A source node's channel reads its ``execute()`` output stream, a complete output + in the row-built form, which ``to_stream()`` gives as it is.""" + node = SourceJobNode.from_stream(source(2), name="events") + + async def read() -> Any: + return await node.open_channel().to_stream() + + output = run(read) + assert getattr(output, ROW_BUILT_OUTPUT, False) + assert same(output.as_table(columns=ALL), R(node))