Skip to content

Commit 1b0aa94

Browse files
authored
Merge pull request #9 from Query-farm/unify-protocol-input
refactor: unify ProtocolInput classes with shared base
2 parents 319ccc6 + 3f7059c commit 1b0aa94

4 files changed

Lines changed: 34 additions & 22 deletions

File tree

‎.beads/issues.jsonl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{"id":"vgi-python-5er","title":"Extract _should_terminate into shared base class","description":"Identical _should_terminate method is copy-pasted in all three function modules. Implementation is always: check if log_message exists and level is EXCEPTION. Move to shared base class (Function or new ProcessingMixin) to eliminate duplication.","status":"closed","priority":3,"issue_type":"task","created_at":"2026-01-04T20:06:41.190482-05:00","created_by":"rusty","updated_at":"2026-01-04T21:49:59.765614-05:00","closed_at":"2026-01-04T21:49:59.765614-05:00","close_reason":"Completed as part of PR #8 - _should_terminate moved to Function base class","dependencies":[{"issue_id":"vgi-python-5er","depends_on_id":"vgi-python-6o0","type":"blocks","created_at":"2026-01-04T20:07:49.283865-05:00","created_by":"rusty"}]}
66
{"id":"vgi-python-67w","title":"Create example function using DuckDB settings","description":"Create an example function that demonstrates using DuckDB settings to determine its output.\n\nRequirements:\n- Function declares required_settings in Meta\n- Output schema depends on a setting value (e.g., include extra column based on setting)\n- Clear documentation showing the pattern\n\nExample ideas:\n1. TimezoneAwareFunction: Output includes timezone info based on 'timezone' setting\n2. VerboseOutput: Adds debug columns when 'debug_mode' setting is true\n3. NumericPrecision: Uses 'numeric_precision' to determine output type precision\n\nAdd to vgi/examples/ and register in ExampleWorker.","status":"closed","priority":2,"issue_type":"task","created_at":"2026-01-04T13:05:48.503681-05:00","created_by":"rusty","updated_at":"2026-01-04T13:22:23.779895-05:00","closed_at":"2026-01-04T13:22:23.779895-05:00","close_reason":"Added SettingsAwareFunction example","dependencies":[{"issue_id":"vgi-python-67w","depends_on_id":"vgi-python-c2b","type":"blocks","created_at":"2026-01-04T13:06:13.865474-05:00","created_by":"rusty"},{"issue_id":"vgi-python-67w","depends_on_id":"vgi-python-ivf","type":"blocks","created_at":"2026-01-04T13:06:13.890269-05:00","created_by":"rusty"},{"issue_id":"vgi-python-67w","depends_on_id":"vgi-python-bqb","type":"blocks","created_at":"2026-01-04T13:06:13.912531-05:00","created_by":"rusty"},{"issue_id":"vgi-python-67w","depends_on_id":"vgi-python-a99","type":"blocks","created_at":"2026-01-04T13:06:13.936552-05:00","created_by":"rusty"},{"issue_id":"vgi-python-67w","depends_on_id":"vgi-python-j4t","type":"blocks","created_at":"2026-01-04T13:06:13.958494-05:00","created_by":"rusty"}]}
77
{"id":"vgi-python-6o0","title":"Consolidate _OutputComplete classes into shared module","description":"Three nearly identical _OutputComplete classes exist in scalar_function.py:168-197 (_ScalarOutputComplete), table_function.py:136-175 (_OutputComplete), and table_in_out_function.py:356-400 (_OutputComplete). All are frozen dataclasses with batch field, log_message field, and from_process_result() classmethod. Extract to shared module (e.g., vgi/protocol_types.py) with a single parameterized class.","status":"closed","priority":2,"issue_type":"task","created_at":"2026-01-04T20:06:40.893139-05:00","created_by":"rusty","updated_at":"2026-01-04T21:18:34.529683-05:00","closed_at":"2026-01-04T21:18:34.529683-05:00","close_reason":"PR #5 created: https://github.com/Query-farm/vgi-python/pull/5"}
8-
{"id":"vgi-python-79e","title":"Unify ProtocolInput classes with shared base","description":"ProtocolInput classes in scalar_function.py:151-166 and table_in_out_function.py:109-142 have similar structure with batch and metadata fields. The table_in_out version adds is_finalize logic. Create shared base ProtocolInput in protocol_types.py with table_in_out extending it.","status":"closed","priority":3,"issue_type":"task","created_at":"2026-01-04T20:06:41.31917-05:00","created_by":"rusty","updated_at":"2026-01-04T21:53:26.965345-05:00","closed_at":"2026-01-04T21:53:26.965345-05:00","close_reason":"PR #9 created - unified ProtocolInput with shared base in protocol_types.py"}
8+
{"id":"vgi-python-79e","title":"Unify ProtocolInput classes with shared base","description":"ProtocolInput classes in scalar_function.py:151-166 and table_in_out_function.py:109-142 have similar structure with batch and metadata fields. The table_in_out version adds is_finalize logic. Create shared base ProtocolInput in protocol_types.py with table_in_out extending it.","status":"in_progress","priority":3,"issue_type":"task","created_at":"2026-01-04T20:06:41.31917-05:00","created_by":"rusty","updated_at":"2026-01-04T21:51:05.655788-05:00"}
99
{"id":"vgi-python-a99","title":"Add settings accessor to function base classes","description":"Add a property to access DuckDB settings values in function implementations.\n\nChanges needed:\n- Add 'settings: dict[str, str]' property to Function base class\n- Property should return self.invocation.duckdb_settings or empty dict\n- Add convenience method like 'get_setting(name, default=None)'\n- Update ScalarFunction, TableFunctionGenerator, TableInOutFunction\n\nExample usage in function:\ndef compute(self, batch):\n tz = self.get_setting('timezone', 'UTC')\n # or\n tz = self.settings.get('timezone', 'UTC')","status":"closed","priority":2,"issue_type":"task","created_at":"2026-01-04T13:05:48.221602-05:00","created_by":"rusty","updated_at":"2026-01-04T13:20:41.171991-05:00","closed_at":"2026-01-04T13:20:41.171991-05:00","close_reason":"Implementation complete, all tests pass","dependencies":[{"issue_id":"vgi-python-a99","depends_on_id":"vgi-python-aad","type":"blocks","created_at":"2026-01-04T13:06:13.738212-05:00","created_by":"rusty"}]}
1010
{"id":"vgi-python-aad","title":"Design: DuckDB settings/pragmas access for VGI functions","description":"Design how VGI functions can declare required DuckDB settings/pragmas in their Meta class, and how these settings values should be passed during the bind phase.\n\nKey design decisions:\n1. How to declare required settings in function Meta (e.g., required_settings = ['timezone', 'threads'])\n2. How to add settings to Invocation dataclass\n3. How settings values should be accessed in function code\n4. Serialization format for settings in Arrow IPC\n\nRecommendation: Add 'duckdb_settings: dict[str, str] | None' to Invocation and 'required_settings: list[str]' to Meta class.","status":"closed","priority":1,"issue_type":"task","created_at":"2026-01-04T13:05:47.619105-05:00","created_by":"rusty","updated_at":"2026-01-04T13:11:13.197139-05:00","closed_at":"2026-01-04T13:11:13.197139-05:00","close_reason":"Design document created at docs/design-duckdb-settings.md"}
1111
{"id":"vgi-python-bi8","title":"Extract common _process_with_exception_handling into mixin","description":"The _process_with_exception_handling and _process_and_validate methods are duplicated across scalar_function.py:296-346, table_function.py:386-438, and table_in_out_function.py:586-642. All follow same pattern: try _process_and_validate, catch exceptions, return OutputComplete with error message. Extract to ProcessingMixin that all function types inherit from.","status":"closed","priority":2,"issue_type":"task","created_at":"2026-01-04T20:06:41.02111-05:00","created_by":"rusty","updated_at":"2026-01-04T21:49:46.320532-05:00","closed_at":"2026-01-04T21:49:46.320532-05:00","close_reason":"PR #8 created - extracted _should_terminate and added _create_error_output to Function base class","dependencies":[{"issue_id":"vgi-python-bi8","depends_on_id":"vgi-python-6o0","type":"blocks","created_at":"2026-01-04T20:07:49.181408-05:00","created_by":"rusty"}]}

‎vgi/protocol_types.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Shared protocol types for VGI function communication.
2+
3+
This module provides base classes for protocol messages used across
4+
different function types.
5+
"""
6+
7+
from dataclasses import dataclass
8+
9+
import pyarrow as pa
10+
11+
__all__ = ["ProtocolInput"]
12+
13+
14+
@dataclass(frozen=True, slots=True)
15+
class ProtocolInput:
16+
"""Base input sent to function generators via send().
17+
18+
Attributes:
19+
batch: The input RecordBatch to process.
20+
metadata: Optional metadata from the IPC stream.
21+
22+
"""
23+
24+
batch: pa.RecordBatch
25+
metadata: pa.KeyValueMetadata | None = None

‎vgi/scalar_function.py‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def compute(self, batch: pa.RecordBatch) -> pa.Array:
4141

4242
from abc import abstractmethod
4343
from collections.abc import Generator
44-
from dataclasses import dataclass
4544
from typing import Any, final
4645

4746
import pyarrow as pa
@@ -51,6 +50,7 @@ def compute(self, batch: pa.RecordBatch) -> pa.Array:
5150
import vgi.log
5251
from vgi.exceptions import SchemaValidationError
5352
from vgi.output_complete import OutputComplete
53+
from vgi.protocol_types import ProtocolInput
5454
from vgi.table_function import Output, ProtocolOutput
5555

5656
__all__ = [
@@ -149,21 +149,7 @@ def _build_detailed_message(
149149
ScalarOutputGenerator = Generator[vgi.log.Message | Output, pa.RecordBatch | None, None]
150150

151151

152-
@dataclass(frozen=True, slots=True)
153-
class ProtocolInput:
154-
"""Input sent to the scalar function generator via send().
155-
156-
Contains an input batch and optional metadata. The scalar function
157-
processes each batch and returns an output batch with the same row count.
158-
159-
Attributes:
160-
batch: The input RecordBatch to process.
161-
metadata: Optional metadata from the IPC stream.
162-
163-
"""
164-
165-
batch: pa.RecordBatch
166-
metadata: pa.KeyValueMetadata | None = None
152+
# ProtocolInput imported from vgi.protocol_types
167153

168154

169155
class ScalarFunctionGenerator(vgi.function.Function[vgi.function.FunctionInitInput]):

‎vgi/table_in_out_function.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def process(self, batch: pa.RecordBatch) -> OutputGenerator:
7979
import vgi.log
8080
import vgi.table_function
8181
from vgi.output_complete import OutputComplete
82+
from vgi.protocol_types import ProtocolInput as ProtocolInputBase
8283

8384
__all__ = [
8485
"ProtocolInput",
@@ -107,10 +108,13 @@ class _OutputStatus(Enum):
107108
FINISHED = "FINISHED"
108109

109110

110-
@dataclass(frozen=True, slots=True)
111-
class ProtocolInput:
111+
@dataclass(frozen=True)
112+
class ProtocolInput(ProtocolInputBase):
112113
"""Input sent to the generator via send().
113114
115+
Extends ProtocolInputBase with finalize phase signaling for table-in-out
116+
functions.
117+
114118
Attributes:
115119
batch: The input RecordBatch to process.
116120
metadata: Optional metadata; used to signal the FINALIZE phase.
@@ -120,9 +124,6 @@ class ProtocolInput:
120124
# pa.KeyValueMetadata uses bytes so we define signals as bytes
121125
_FINALIZE_SIGNAL: ClassVar[bytes] = b"FINALIZE"
122126

123-
batch: pa.RecordBatch
124-
metadata: pa.KeyValueMetadata | None = None
125-
126127
@property
127128
def is_finalize(self) -> bool:
128129
"""Check if this input signals the FINALIZE phase."""

0 commit comments

Comments
 (0)