|
27 | 27 | SessionConfig, |
28 | 28 | SessionContext, |
29 | 29 | SQLOptions, |
| 30 | + TableProvider, |
30 | 31 | column, |
31 | 32 | literal, |
32 | 33 | ) |
@@ -330,6 +331,35 @@ def test_deregister_table(ctx, database): |
330 | 331 | assert public.names() == {"csv1", "csv2"} |
331 | 332 |
|
332 | 333 |
|
| 334 | +def test_register_table_from_dataframe_into_view(ctx): |
| 335 | + df = ctx.from_pydict({"a": [1, 2]}) |
| 336 | + provider = df.into_view() |
| 337 | + ctx.register_table("view_tbl", provider) |
| 338 | + result = ctx.sql("SELECT * FROM view_tbl").collect() |
| 339 | + assert [b.to_pydict() for b in result] == [{"a": [1, 2]}] |
| 340 | + |
| 341 | + |
| 342 | +def test_table_provider_from_capsule(ctx): |
| 343 | + df = ctx.from_pydict({"a": [1, 2]}) |
| 344 | + provider = df.into_view() |
| 345 | + capsule = provider.__datafusion_table_provider__() |
| 346 | + provider2 = TableProvider.from_capsule(capsule) |
| 347 | + ctx.register_table("capsule_tbl", provider2) |
| 348 | + result = ctx.sql("SELECT * FROM capsule_tbl").collect() |
| 349 | + assert [b.to_pydict() for b in result] == [{"a": [1, 2]}] |
| 350 | + |
| 351 | + |
| 352 | +def test_table_provider_from_capsule_invalid(): |
| 353 | + with pytest.raises(Exception): # noqa: B017 |
| 354 | + TableProvider.from_capsule(object()) |
| 355 | + |
| 356 | + |
| 357 | +def test_register_table_with_dataframe_errors(ctx): |
| 358 | + df = ctx.from_pydict({"a": [1]}) |
| 359 | + with pytest.raises(Exception): # noqa: B017 |
| 360 | + ctx.register_table("bad", df) |
| 361 | + |
| 362 | + |
333 | 363 | def test_register_dataset(ctx): |
334 | 364 | # create a RecordBatch and register it as a pyarrow.dataset.Dataset |
335 | 365 | batch = pa.RecordBatch.from_arrays( |
|
0 commit comments