1+ import io
12from typing import Any , Literal , TypeVar , get_args , get_origin # noqa: UP035
23
3- import io
44import msgpack
55import pyarrow as pa
66import pyarrow .flight as flight
@@ -84,7 +84,7 @@ def deserialize_flight_descriptor(cls: Any, value: Any) -> flight.FlightDescript
8484 raise ValueError (f"Invalid Flight descriptor: { e } " ) from e
8585
8686
87- class CreateTableParameters (BaseModel ):
87+ class CreateTable (BaseModel ):
8888 model_config = ConfigDict (arbitrary_types_allowed = True ) # for Pydantic v2
8989 catalog_name : str
9090 schema_name : str
@@ -103,7 +103,7 @@ class CreateTableParameters(BaseModel):
103103T = TypeVar ("T" , bound = BaseModel )
104104
105105
106- def unpack_with_model ( action : flight . Action , model_cls : type [T ]) -> T :
106+ def unpack_bytes_with_model ( value : bytes , model_cls : type [T ]) -> T :
107107 decode_fields : set [str ] = set ()
108108 for name , field in model_cls .model_fields .items ():
109109 if isinstance (field .annotation , str ) or (
@@ -114,7 +114,7 @@ def unpack_with_model(action: flight.Action, model_cls: type[T]) -> T:
114114 decode_fields .add (name )
115115
116116 unpacked = msgpack .unpackb (
117- action . body . to_pybytes () ,
117+ value ,
118118 raw = True ,
119119 object_hook = lambda s : {
120120 k .decode ("utf8" ): v .decode ("utf8" ) if k .decode ("utf8" ) in decode_fields else v
@@ -124,7 +124,11 @@ def unpack_with_model(action: flight.Action, model_cls: type[T]) -> T:
124124 return model_cls .model_validate (unpacked )
125125
126126
127- class DropObjectParameters (BaseModel ):
127+ def unpack_with_model (action : flight .Action , model_cls : type [T ]) -> T :
128+ return unpack_bytes_with_model (action .body .to_pybytes (), model_cls )
129+
130+
131+ class DropObject (BaseModel ):
128132 type : Literal ["table" , "schema" ]
129133 catalog_name : str
130134 schema_name : str
@@ -139,19 +143,19 @@ class AlterBase(BaseModel):
139143 ignore_not_found : bool
140144
141145
142- class AddColumnParameters (AlterBase ):
146+ class AddColumn (AlterBase ):
143147 model_config = ConfigDict (arbitrary_types_allowed = True ) # for Pydantic v2
144148 column_schema : pa .Schema
145149 if_column_not_exists : bool
146150
147151 _validate_column_schema = field_validator ("column_schema" , mode = "before" )(deserialize_schema )
148152
149153
150- class AddConstraintParameters (AlterBase ):
154+ class AddConstraint (AlterBase ):
151155 constraint : str
152156
153157
154- class AddFieldParameters (AlterBase ):
158+ class AddField (AlterBase ):
155159 model_config = ConfigDict (arbitrary_types_allowed = True ) # for Pydantic v2
156160 column_path : list [str ]
157161 column_schema : pa .Schema
@@ -160,15 +164,15 @@ class AddFieldParameters(AlterBase):
160164 _validate_field_schema = field_validator ("column_schema" , mode = "before" )(deserialize_schema )
161165
162166
163- class ChangeColumnTypeParameters (AlterBase ):
167+ class ChangeColumnType (AlterBase ):
164168 model_config = ConfigDict (arbitrary_types_allowed = True ) # for Pydantic v2
165169 column_schema : pa .Schema
166170 expression : str
167171
168172 _validate_column_schema = field_validator ("column_schema" , mode = "before" )(deserialize_schema )
169173
170174
171- class ColumnStatisticsParameters (AlterBase ):
175+ class ColumnStatistics (AlterBase ):
172176 model_config = ConfigDict (arbitrary_types_allowed = True ) # for Pydantic v2
173177 flight_descriptor : flight .FlightDescriptor
174178 column_name : str
@@ -179,23 +183,35 @@ class ColumnStatisticsParameters(AlterBase):
179183 )
180184
181185
182- class CreateSchemaParameters (BaseModel ):
186+ class CreateSchema (BaseModel ):
183187 catalog_name : str
184188 schema_name : str = Field ("schema_name" , alias = "schema" )
185189
186190 comment : str | None = None
187191 tags : dict [str , str ]
188192
189193
190- class CreateTransactionParameters (BaseModel ):
194+ class CreateTransaction (BaseModel ):
191195 catalog_name : str
192196
193197
194- class DropNotNullParameters (AlterBase ):
198+ class DropNotNull (AlterBase ):
195199 column_name : str
196200
197201
198- class EndpointsParametersParameters (BaseModel ):
202+ class TableFunctionInOut (BaseModel ):
203+ model_config = ConfigDict (arbitrary_types_allowed = True ) # for Pydantic v2
204+
205+ json_filters : str
206+ column_ids : list [int ]
207+ parameters : pa .RecordBatch | None
208+
209+ _validate_parameters = field_validator ("parameters" , mode = "before" )(
210+ deserialize_record_batch_or_none
211+ )
212+
213+
214+ class EndpointsParameters (BaseModel ):
199215 model_config = ConfigDict (arbitrary_types_allowed = True ) # for Pydantic v2
200216
201217 json_filters : str
@@ -213,59 +229,59 @@ class EndpointsParametersParameters(BaseModel):
213229 )(deserialize_schema_or_none )
214230
215231
216- class EndpointsParameters (BaseModel ):
232+ class Endpoints (BaseModel ):
217233 model_config = ConfigDict (arbitrary_types_allowed = True ) # for Pydantic v2
218234 descriptor : flight .FlightDescriptor
219235 _validate_descriptor = field_validator ("descriptor" , mode = "before" )(
220236 deserialize_flight_descriptor
221237 )
222- parameters : EndpointsParametersParameters
238+ parameters : EndpointsParameters
223239
224240
225- class ListSchemasParameters (BaseModel ):
241+ class ListSchemas (BaseModel ):
226242 catalog_name : str
227243
228244
229- class RemoveColumnParameters (AlterBase ):
245+ class RemoveColumn (AlterBase ):
230246 removed_column : str
231247 if_column_exists : bool
232248 cascade : bool
233249
234250
235- class RemoveFieldParameters (AlterBase ):
251+ class RemoveField (AlterBase ):
236252 column_path : list [str ]
237253 if_column_exists : bool
238254 cascade : bool
239255
240256
241- class RenameColumnParameters (AlterBase ):
257+ class RenameColumn (AlterBase ):
242258 old_name : str
243259 new_name : str
244260
245261
246- class RenameFieldParameters (AlterBase ):
262+ class RenameField (AlterBase ):
247263 column_path : list [str ]
248264 new_name : str
249265
250266
251- class RenameTableParameters (AlterBase ):
267+ class RenameTable (AlterBase ):
252268 new_table_name : str
253269
254270
255- class SetDefaultParameters (AlterBase ):
271+ class SetDefault (AlterBase ):
256272 column_name : str
257273 expression : str
258274
259275
260- class SetNotNullParameters (AlterBase ):
276+ class SetNotNull (AlterBase ):
261277 column_name : str
262278
263279
264- class CatalogVersionParameters (BaseModel ):
280+ class CatalogVersion (BaseModel ):
265281 catalog_name : str
266282
267283
268- class TableFunctionFlightInfoParameters (BaseModel ):
284+ class TableFunctionFlightInfo (BaseModel ):
269285 """
270286 Parameters for a table function flight info request.
271287 """
@@ -293,89 +309,93 @@ class TableFunctionFlightInfoParameters(BaseModel):
293309 )
294310
295311
296- def table_function_flight_info (action : flight .Action ) -> TableFunctionFlightInfoParameters :
297- return unpack_with_model (action , TableFunctionFlightInfoParameters )
312+ def table_function_flight_info (action : flight .Action ) -> TableFunctionFlightInfo :
313+ return unpack_with_model (action , TableFunctionFlightInfo )
314+
315+
316+ def table_function_in_out (value : bytes ) -> TableFunctionInOut :
317+ return unpack_bytes_with_model (value , TableFunctionInOut )
298318
299319
300- def catalog_version (action : flight .Action ) -> CatalogVersionParameters :
301- return unpack_with_model (action , CatalogVersionParameters )
320+ def catalog_version (action : flight .Action ) -> CatalogVersion :
321+ return unpack_with_model (action , CatalogVersion )
302322
303323
304- def add_column (action : flight .Action ) -> AddColumnParameters :
305- return unpack_with_model (action , AddColumnParameters )
324+ def add_column (action : flight .Action ) -> AddColumn :
325+ return unpack_with_model (action , AddColumn )
306326
307327
308- def add_constraint (action : flight .Action ) -> AddConstraintParameters :
309- return unpack_with_model (action , AddConstraintParameters )
328+ def add_constraint (action : flight .Action ) -> AddConstraint :
329+ return unpack_with_model (action , AddConstraint )
310330
311331
312- def add_field (action : flight .Action ) -> AddFieldParameters :
313- return unpack_with_model (action , AddFieldParameters )
332+ def add_field (action : flight .Action ) -> AddField :
333+ return unpack_with_model (action , AddField )
314334
315335
316- def change_column_type (action : flight .Action ) -> ChangeColumnTypeParameters :
317- return unpack_with_model (action , ChangeColumnTypeParameters )
336+ def change_column_type (action : flight .Action ) -> ChangeColumnType :
337+ return unpack_with_model (action , ChangeColumnType )
318338
319339
320- def create_table (action : flight .Action ) -> CreateTableParameters :
321- return unpack_with_model (action , CreateTableParameters )
340+ def create_table (action : flight .Action ) -> CreateTable :
341+ return unpack_with_model (action , CreateTable )
322342
323343
324- def column_statistics (action : flight .Action ) -> ColumnStatisticsParameters :
325- return unpack_with_model (action , ColumnStatisticsParameters )
344+ def column_statistics (action : flight .Action ) -> ColumnStatistics :
345+ return unpack_with_model (action , ColumnStatistics )
326346
327347
328- def create_schema (action : flight .Action ) -> CreateSchemaParameters :
329- return unpack_with_model (action , CreateSchemaParameters )
348+ def create_schema (action : flight .Action ) -> CreateSchema :
349+ return unpack_with_model (action , CreateSchema )
330350
331351
332- def create_transaction (action : flight .Action ) -> CreateTransactionParameters :
333- return unpack_with_model (action , CreateTransactionParameters )
352+ def create_transaction (action : flight .Action ) -> CreateTransaction :
353+ return unpack_with_model (action , CreateTransaction )
334354
335355
336- def drop_not_null (action : flight .Action ) -> DropNotNullParameters :
337- return unpack_with_model (action , DropNotNullParameters )
356+ def drop_not_null (action : flight .Action ) -> DropNotNull :
357+ return unpack_with_model (action , DropNotNull )
338358
339359
340- def drop_schema (action : flight .Action ) -> DropObjectParameters :
341- return unpack_with_model (action , DropObjectParameters )
360+ def drop_schema (action : flight .Action ) -> DropObject :
361+ return unpack_with_model (action , DropObject )
342362
343363
344- def drop_table (action : flight .Action ) -> DropObjectParameters :
345- return unpack_with_model (action , DropObjectParameters )
364+ def drop_table (action : flight .Action ) -> DropObject :
365+ return unpack_with_model (action , DropObject )
346366
347367
348- def endpoints (action : flight .Action ) -> EndpointsParameters :
349- return unpack_with_model (action , EndpointsParameters )
368+ def endpoints (action : flight .Action ) -> Endpoints :
369+ return unpack_with_model (action , Endpoints )
350370
351371
352- def list_schemas (action : flight .Action ) -> ListSchemasParameters :
353- return unpack_with_model (action , ListSchemasParameters )
372+ def list_schemas (action : flight .Action ) -> ListSchemas :
373+ return unpack_with_model (action , ListSchemas )
354374
355375
356- def remove_column (action : flight .Action ) -> RemoveColumnParameters :
357- return unpack_with_model (action , RemoveColumnParameters )
376+ def remove_column (action : flight .Action ) -> RemoveColumn :
377+ return unpack_with_model (action , RemoveColumn )
358378
359379
360- def remove_field (action : flight .Action ) -> RemoveFieldParameters :
361- return unpack_with_model (action , RemoveFieldParameters )
380+ def remove_field (action : flight .Action ) -> RemoveField :
381+ return unpack_with_model (action , RemoveField )
362382
363383
364- def rename_column (action : flight .Action ) -> RenameColumnParameters :
365- return unpack_with_model (action , RenameColumnParameters )
384+ def rename_column (action : flight .Action ) -> RenameColumn :
385+ return unpack_with_model (action , RenameColumn )
366386
367387
368- def rename_field (action : flight .Action ) -> RenameFieldParameters :
369- return unpack_with_model (action , RenameFieldParameters )
388+ def rename_field (action : flight .Action ) -> RenameField :
389+ return unpack_with_model (action , RenameField )
370390
371391
372- def rename_table (action : flight .Action ) -> RenameTableParameters :
373- return unpack_with_model (action , RenameTableParameters )
392+ def rename_table (action : flight .Action ) -> RenameTable :
393+ return unpack_with_model (action , RenameTable )
374394
375395
376- def set_default (action : flight .Action ) -> SetDefaultParameters :
377- return unpack_with_model (action , SetDefaultParameters )
396+ def set_default (action : flight .Action ) -> SetDefault :
397+ return unpack_with_model (action , SetDefault )
378398
379399
380- def set_not_null (action : flight .Action ) -> SetNotNullParameters :
381- return unpack_with_model (action , SetNotNullParameters )
400+ def set_not_null (action : flight .Action ) -> SetNotNull :
401+ return unpack_with_model (action , SetNotNull )
0 commit comments