Register a vector function that returns a struct array
()
| 346 | |
| 347 | @pytest.fixture(scope="session") |
| 348 | def struct_vector_func_fixture(): |
| 349 | """ |
| 350 | Register a vector function that returns a struct array |
| 351 | """ |
| 352 | def pivot(ctx, k, v, c): |
| 353 | df = pa.RecordBatch.from_arrays([k, v, c], names=['k', 'v', 'c']).to_pandas() |
| 354 | df_pivot = df.pivot(columns='c', values='v', index='k').reset_index() |
| 355 | return pa.RecordBatch.from_pandas(df_pivot).to_struct_array() |
| 356 | |
| 357 | func_name = "y=pivot(x)" |
| 358 | doc = empty_udf_doc |
| 359 | pc.register_vector_function( |
| 360 | pivot, func_name, doc, |
| 361 | {'k': pa.int64(), 'v': pa.float64(), 'c': pa.utf8()}, |
| 362 | pa.struct([('k', pa.int64()), ('v1', pa.float64()), ('v2', pa.float64())]) |
| 363 | ) |
| 364 | |
| 365 | return pivot, func_name |
| 366 | |
| 367 | |
| 368 | def check_scalar_function(func_fixture, |
nothing calls this directly
no outgoing calls
no test coverage detected