Daft Sessions#
Warning
These APIs are early in their development. Please feel free to open feature requests and file issues. We'd love hear want you would like, thank you! 🤘
Sessions enable you to attach catalogs, tables, and create temporary objects which are accessible through both the Python and SQL APIs. Sessions hold configuration state such as current_catalog
and current_namespace
which are used in name resolution and can simplify your workflows.
Example#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Usage#
This section covers detailed usage of the current APIs with some code snippets.
Setup#
Note
For these examples, we are using sqlite Iceberg which requires pyiceberg[sql-sqlite]
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Session State#
Let's get started by creating an empty session and checking the state.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Attach & Detach#
The attach and detach methods make it easy to use catalogs and tables in a session. This example shows how we can attach our newly created catalog. When you attach a catalog to an empty session, it automatically becomes the current active catalog.
1 2 3 4 5 6 7 8 9 10 11 |
|
Create & Drop#
We can create tables and namespaces directly through a catalog or via our session.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
Read & Write#
Using sessions abstracts away underlying catalog and table implementations so you can easily read and write DataFrames.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
Using SQL#
The session enables executing Daft SQL against your catalogs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Note
We aim to support SQL DDL in future releases!
Reference#
For complete documentation, please see the Session API docs.
Method | Description |
---|---|
attach | Attaches a catalog, table, or function to this session. |
attach_catalog | Attaches an exiting catalog to this session |
attach_table | Attaches an existing table to this session |
attach_function | Attaches a user-defined function to this session |
create_namespace | Creates a new namespace |
create_namespace_if_not_exists | Creates a new namespace if it doesn't already exist |
create_table | Creates a new table from the source |
create_table_if_not_exists | Creates a new table from the source if it doesn't already exist |
create_temp_table | Creates a temp table scoped to this session from an existing view. |
current_catalog | Returns the session's current catalog. |
current_namespace | Returns the session's current namespace. |
detach_catalog | Detaches the catalog from this session |
detach_table | Detaches the table from this session |
drop_namespace | Drop the namespace in the session's current catalog |
drop_table | Drop the table in the session's current catalog |
get_catalog | Returns the catalog or an object not found error. |
get_table | Returns the table or an object not found error. |
has_catalog | Returns true iff the session has access to a matching catalog. |
has_namespace | Returns true iff the session has access to a matching namespace. |
has_table | Returns true iff the session has access to a matching table. |
list_catalogs | Lists all catalogs matching the pattern. |
list_namespaces | Lists all namespaces matching the pattern. |
list_tables | Lists all tables matching the pattern. |
read_table | Reads a table from the session. |
write_table | Writes a dataframe to the table. |
set_catalog | Sets the current catalog. |
set_namespace | Sets the current namespace. |
sql | Executes SQL against the session. |
use | Sets the current catalog and namespace. |