@@ -348,6 +348,45 @@ def test_from_pandas(ctx):
348348 assert df .collect ()[0 ].num_rows == 3
349349
350350
351+ def test_sql_from_local_arrow_table (ctx ):
352+ arrow_table = pa .Table .from_pydict ({"a" : [1 , 2 ], "b" : ["x" , "y" ]})
353+
354+ result = ctx .sql ("SELECT * FROM arrow_table ORDER BY a" ).collect ()
355+ actual = pa .Table .from_batches (result )
356+ expected = pa .Table .from_pydict ({"a" : [1 , 2 ], "b" : ["x" , "y" ]})
357+
358+ assert actual .equals (expected )
359+
360+
361+ def test_sql_from_local_pandas_dataframe (ctx ):
362+ pd = pytest .importorskip ("pandas" )
363+ pandas_df = pd .DataFrame ({"a" : [3 , 1 ], "b" : ["z" , "y" ]})
364+
365+ result = ctx .sql ("SELECT * FROM pandas_df ORDER BY a" ).collect ()
366+ actual = pa .Table .from_batches (result )
367+ expected = pa .Table .from_pydict ({"a" : [1 , 3 ], "b" : ["y" , "z" ]})
368+
369+ assert actual .equals (expected )
370+
371+
372+ def test_sql_from_local_polars_dataframe (ctx ):
373+ pl = pytest .importorskip ("polars" )
374+ polars_df = pl .DataFrame ({"a" : [2 , 1 ], "b" : ["beta" , "alpha" ]})
375+
376+ result = ctx .sql ("SELECT * FROM polars_df ORDER BY a" ).collect ()
377+ actual = pa .Table .from_batches (result )
378+ expected = pa .Table .from_pydict ({"a" : [1 , 2 ], "b" : ["alpha" , "beta" ]})
379+
380+ assert actual .equals (expected )
381+
382+
383+ def test_sql_from_local_unsupported_object (ctx ):
384+ unsupported = object ()
385+
386+ with pytest .raises (Exception , match = "table 'unsupported' not found" ):
387+ ctx .sql ("SELECT * FROM unsupported" ).collect ()
388+
389+
351390def test_from_polars (ctx ):
352391 # create a dataframe from Polars dataframe
353392 pd = pytest .importorskip ("polars" )
0 commit comments