Skip to content

Commit a1bbc07

Browse files
rustyconoverclaude
andcommitted
table_buffering: surface client_log on TableBufferingParams
process() and combine() are unary RPCs and lack the OutputCollector that the streaming finalize() callback uses for in-band logging. Add a client_log: Callable on TableBufferingParams, wire it to ctx.client_log in _load_table_buffering_params, and migrate SumAllColumnsFunction off the stdlib logging.getLogger() call that never reached the wire. The wire mechanism was always there — ReadUnaryResponse on the C++ side dispatches 0-row vgi_rpc.log_level batches through HandleBatchLogMessage before AND after the data batch, surfacing them in duckdb_logs() with type='VGI'. What was missing was an entry point from the buffered user-callback layer; ``out.client_log`` exists for streaming flows but the unary flows had no analogue. ``params.client_log(level, message)`` fills that gap with the same call shape the streaming side uses. Side effect: ``logging.test`` (which asserted "Processing batch with N rows" reached duckdb_logs from sum_all_columns) now passes — the stdlib logging.info() call it relied on was never bridged to the RPC stream; the test was broken since the migration of sum_all_columns from TableInOutGenerator (streaming, had ``out``) to TableBufferingFunction (buffered, didn't). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d55e8ff commit a1bbc07

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

‎vgi/_test_fixtures/table_in_out.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import pyarrow as pa
4444
import pyarrow.compute as pc
4545
from vgi_rpc import ArrowSerializableDataclass, ArrowType
46+
from vgi_rpc.log import Level
4647
from vgi_rpc.rpc import OutputCollector
4748
from vgi_rpc.utils import empty_batch
4849

@@ -499,9 +500,16 @@ def process(
499500
Race-safe append (state_append is atomic). combine() reduces.
500501
"""
501502
if params.args.logging:
502-
import logging as _lg
503-
_lg.getLogger("vgi.fixture.sum_all_columns").info(
504-
"Processing batch with %d rows", batch.num_rows,
503+
# Goes through the same wire mechanism as the streaming
504+
# ``out.client_log()`` path — emits a 0-row log batch on the
505+
# ``table_buffering_process`` response stream that DuckDB
506+
# surfaces in ``duckdb_logs()`` with type='VGI'. The Python
507+
# stdlib ``logging.getLogger(...).info(...)`` we used before
508+
# didn't reach the wire and never showed up in duckdb_logs
509+
# (the framework provides no stdlib-logging-to-wire bridge).
510+
params.client_log(
511+
Level.INFO,
512+
f"Processing batch with {batch.num_rows} rows",
505513
)
506514

507515
# Compute partial sums for this batch only.

‎vgi/table_buffering_function.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
from __future__ import annotations
3131

3232
from abc import abstractmethod
33-
from dataclasses import dataclass
33+
from collections.abc import Callable
34+
from dataclasses import dataclass, field
3435
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, get_args, get_origin
3536

3637
import pyarrow as pa
@@ -156,6 +157,22 @@ class TableBufferingParams[TArgs](ProcessParams[TArgs]):
156157
function_name: str
157158
worker_path: str | None = None
158159

160+
# In-band log sink — emits a 0-row log batch on the RPC response stream,
161+
# which DuckDB surfaces as a row in ``duckdb_logs()`` with ``type='VGI'``.
162+
# Use this from ``process()`` and ``combine()`` (which are unary RPCs and
163+
# have no ``OutputCollector``). The streaming ``finalize(... out)``
164+
# callback should use ``out.client_log(...)`` instead — it goes through
165+
# the same wire mechanism but flows through the producer-mode stream.
166+
#
167+
# The worker handler wires this to ``ctx.client_log`` before invoking
168+
# the user callback; the default no-op is a safety net for unit-test
169+
# callers that build ``TableBufferingParams`` outside the RPC path.
170+
client_log: Callable[..., None] = field(
171+
default=lambda *_a, **_kw: None,
172+
repr=False,
173+
compare=False,
174+
)
175+
159176

160177
class TableBufferingFunction[TArgs, TFinalizeState = None](TableFunctionBase[TArgs]):
161178
"""Base class for table sink+source functions.

‎vgi/worker.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,12 @@ def _load_table_buffering_params(
25772577
transaction_id=transaction_id,
25782578
function_name=function_name,
25792579
worker_path=None,
2580+
# process() and combine() are unary RPCs and have no
2581+
# OutputCollector; expose ctx.client_log on params so they can
2582+
# emit log batches that surface in DuckDB's duckdb_logs() with
2583+
# type='VGI'. Mirrors out.client_log() on the streaming
2584+
# finalize() callback.
2585+
client_log=ctx.client_log,
25802586
)
25812587
return func_cls, params
25822588

0 commit comments

Comments
 (0)