Skip to content

Commit e4c214b

Browse files
committed
Add a working, more complete example of using a catalog
1 parent 1160d5a commit e4c214b

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

docs/source/user-guide/data-sources.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,30 @@ a :py:class:`~datafusion.context.SessionContext` comes with a single Catalog and
227227
with the names ``datafusion`` and ``default``, respectively.
228228

229229
The default implementation uses an in-memory approach to the catalog and schema. We have support
230-
for adding additional in-memory catalogs and schemas. This can be done like in the following
230+
for adding additional in-memory catalogs and schemas. You can access tables registered in a schema
231+
either through the Dataframe API or vial sql commands. This can be done like in the following
231232
example:
232233

233234
.. code-block:: python
234235
235236
from datafusion.catalog import Catalog, Schema
237+
from datafusion import SessionContext
238+
239+
ctx = SessionContext()
236240
237-
my_catalog = Catalog.memory_catalog()
238-
my_schema = Schema.memory_schema()
241+
my_catalog = Catalog.memory_catalog()
242+
my_schema = Schema.memory_schema()
239243
240244
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")
248+
249+
my_schema.register_table('pokemon',df)
241250
242-
ctx.register_catalog("my_catalog_name", my_catalog)
251+
pokemon = ctx.sql("SELECT * FROM my_catalog_name.my_schema_name.pokemon")
243252
244-
You could then register tables in ``my_schema`` and access them either through the DataFrame
245-
API or via sql commands such as ``"SELECT * from my_catalog_name.my_schema_name.my_table"``.
253+
pokemon.show()
246254
247255
User Defined Catalog and Schema
248256
-------------------------------

0 commit comments

Comments
 (0)