@@ -233,24 +233,28 @@ example:
233233
234234.. code-block :: python
235235
236+ import pyarrow as pa
236237 from datafusion.catalog import Catalog, Schema
237238 from datafusion import SessionContext
238239
239240 ctx = SessionContext()
240241
241- my_catalog = Catalog.memory_catalog()
242- my_schema = Schema.memory_schema()
243-
244- my_catalog.register_schema(" my_schema_name" , my_schema)
245- ctx.register_catalog_provider(" my_catalog_name" , my_catalog)
246-
247- df = ctx.read_csv(" pokemon.csv" )
242+ my_catalog = Catalog.memory_catalog()
243+ my_schema = Schema.memory_schema()
244+ my_catalog.register_schema(' my_schema_name' , my_schema)
245+ ctx.register_catalog_provider(' my_catalog_name' , my_catalog)
248246
249- my_schema.register_table(' pokemon' ,df)
247+ # Create an in-memory table
248+ table = pa.table({
249+ ' name' : [' Bulbasaur' , ' Charmander' , ' Squirtle' ],
250+ ' type' : [' Grass' , ' Fire' , ' Water' ],
251+ ' hp' : [45 , 39 , 44 ],
252+ })
253+ df = ctx.create_dataframe([table.to_batches()], name = ' pokemon' )
250254
251- pokemon = ctx.sql( " SELECT * FROM my_catalog_name.my_schema_name. pokemon" )
255+ my_schema.register_table( ' pokemon' , df )
252256
253- pokemon.show()
257+ ctx.sql( ' SELECT * FROM my_catalog_name.my_schema_name. pokemon' ) .show()
254258
255259 User Defined Catalog and Schema
256260-------------------------------
0 commit comments