Skip to content

Commit 917102d

Browse files
omkar-fossLiam Brannigan
authored andcommitted
docs: add doc loading delta table from UC
Signed-off-by: Omkar P <[email protected]> Signed-off-by: Liam Brannigan <[email protected]>
1 parent 2389cfa commit 917102d

File tree

2 files changed

+94
-18
lines changed

2 files changed

+94
-18
lines changed

docs/usage/loading-table.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,40 @@ version number or datetime string:
191191
Previous table versions may not exist if they have been vacuumed, in
192192
which case an exception will be thrown. See [Vacuuming
193193
tables](managing-tables.md#vacuuming-tables) for more information.
194+
195+
## Load table from Unity Catalog
196+
197+
You may load a Delta Table from your Databricks or Open Source Unity Catalog using a `uc://` URL of format `uc://<catalog-name>.<db-name>.<table-name>`. Example as follows:
198+
199+
=== "Python"
200+
201+
```python
202+
import os
203+
from deltalake import DeltaTable
204+
205+
# Set your Unity Catalog workspace URL in the
206+
# DATABRICKS_WORKSPACE_URL environment variable.
207+
os.environ["DATABRICKS_WORKSPACE_URL"] = "https://adb-1234567890.XX.azuredatabricks.net"
208+
209+
# Set your Unity Catalog access token in the
210+
# DATABRICKS_ACCESS_TOKEN environment variable.
211+
os.environ["DATABRICKS_ACCESS_TOKEN"] = "<unity-catalog-access-token-here>"
212+
213+
# Your Unity Catalog name here
214+
catalog_name = "unity"
215+
216+
# Your UC database name here
217+
db_name = "my_database"
218+
219+
# Your table name in the UC database here
220+
table_name = "my_table"
221+
222+
# Full UC URL in required format
223+
uc_full_url = f"{catalog_name}.{db_name}.{table_name}"
224+
225+
# This should load the valid delta table at specified location,
226+
# and you can start using it.
227+
dt = DeltaTable(uc_full_url)
228+
dt.is_deltatable(dt.table_uri)
229+
# True
230+
```

python/docs/source/usage.rst

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,24 @@ You can check whether or not a Delta table exists at a particular path by using
9797
the :meth:`DeltaTable.is_deltatable()` method.
9898

9999
.. code-block:: python
100-
from deltalake import DeltaTable
101-
102-
table_path = "<path/to/valid/table>"
103-
DeltaTable.is_deltatable(table_path)
104-
# True
105-
106-
invalid_table_path = "<path/to/nonexistent/table>"
107-
DeltaTable.is_deltatable(invalid_table_path)
108-
# False
109-
110-
bucket_table_path = "<path/to/valid/table/in/bucket>"
111-
storage_options = {
112-
"AWS_ACCESS_KEY_ID": "THE_AWS_ACCESS_KEY_ID",
113-
"AWS_SECRET_ACCESS_KEY": "THE_AWS_SECRET_ACCESS_KEY",
114-
...
115-
}
116-
DeltaTable.is_deltatable(bucket_table_path)
117-
# True
100+
>>>from deltalake import DeltaTable
101+
>>>
102+
>>>table_path = "<path/to/valid/table>"
103+
>>>DeltaTable.is_deltatable(table_path)
104+
>>># True
105+
>>>
106+
>>>invalid_table_path = "<path/to/nonexistent/table>"
107+
>>>DeltaTable.is_deltatable(invalid_table_path)
108+
>>># False
109+
>>>
110+
>>>bucket_table_path = "<path/to/valid/table/in/bucket>"
111+
>>>storage_options = {
112+
>>> "AWS_ACCESS_KEY_ID": "THE_AWS_ACCESS_KEY_ID",
113+
>>> "AWS_SECRET_ACCESS_KEY": "THE_AWS_SECRET_ACCESS_KEY",
114+
>>> ...
115+
>>>}
116+
>>>DeltaTable.is_deltatable(bucket_table_path)
117+
>>># True
118118
119119
Custom Storage Backends
120120
~~~~~~~~~~~~~~~~~~~~~~~
@@ -176,6 +176,45 @@ number or datetime string:
176176
Previous table versions may not exist if they have been vacuumed, in which
177177
case an exception will be thrown. See `Vacuuming tables`_ for more information.
178178

179+
Load table from Unity Catalog
180+
~~~~~~~~~~~~~~~~~~~~~~~~
181+
182+
You may load a Delta Table from your Databricks or Open Source Unity Catalog
183+
using a ``uc://`` URL of format ``uc://<catalog-name>.<db-name>.<table-name>``.
184+
Example as follows:
185+
186+
.. code-block:: python
187+
188+
>>> import os
189+
>>> from deltalake import DeltaTable
190+
>>>
191+
>>> # Set your Unity Catalog workspace URL in the
192+
>>> # DATABRICKS_WORKSPACE_URL environment variable.
193+
>>> os.environ["DATABRICKS_WORKSPACE_URL"] = "https://adb-1234567890.XX.azuredatabricks.net"
194+
>>>
195+
>>> # Set your Unity Catalog access token in the
196+
>>> # DATABRICKS_ACCESS_TOKEN environment variable.
197+
>>> os.environ["DATABRICKS_ACCESS_TOKEN"] = "<unity-catalog-access-token-here>"
198+
>>>
199+
>>> # Your Unity Catalog name here
200+
>>> catalog_name = "unity"
201+
>>>
202+
>>> # Your UC database name here
203+
>>> db_name = "my_database"
204+
>>>
205+
>>> # Your table name in the UC database here
206+
>>> table_name = "my_table"
207+
>>>
208+
>>> # Full UC URL in required format
209+
>>> uc_full_url = f"{catalog_name}.{db_name}.{table_name}"
210+
>>>
211+
>>> # This should load the valid delta table at specified location,
212+
>>> # and you can start using it.
213+
>>> dt = DeltaTable(uc_full_url)
214+
>>> dt.is_deltatable(dt.table_uri)
215+
>>> # True
216+
```
217+
179218
Examining a Table
180219
-----------------
181220

0 commit comments

Comments
 (0)