Skip to content

Commit 7714eda

Browse files
Add unity catalog section and add get catalogs
1 parent add6b81 commit 7714eda

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

streamlit/view_groups.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@
104104
"icon": ":material/lan:",
105105
},
106106
],
107+
},
108+
{
109+
"title": "Unity Catalog",
110+
"views": [
111+
{
112+
"label": "Get Catalogs",
113+
"help": "Get meta data.",
114+
"page": "views/unity_catalog_get.py",
115+
"icon": ":material/lan:",
116+
},
117+
],
107118
},
108119
{
109120
"title": "Authentication",
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import pandas as pd
2+
import streamlit as st
3+
import datetime
4+
import matplotlib.pyplot as plt
5+
from databricks.sdk import WorkspaceClient
6+
7+
8+
workspace = WorkspaceClient()
9+
10+
def get_catalogs():
11+
catalogs = workspace.catalogs.list()
12+
# Parse metadata into a list of dictionaries
13+
catalogs_data = []
14+
for catalog in catalogs:
15+
catalogs_data.append({
16+
"Catalog Name": catalog.name,
17+
"Owner": catalog.owner,
18+
"Comment": catalog.comment,
19+
"Created At": datetime.datetime.fromtimestamp(catalog.created_at/1000),
20+
"Updated At": datetime.datetime.fromtimestamp(catalog.updated_at/1000),
21+
})
22+
return pd.DataFrame(catalogs_data)
23+
24+
def get_schemas():
25+
schema_data = []
26+
for catalog in workspace.catalogs.list():
27+
schemas = workspace.schemas.list(catalog_name=catalog.name)
28+
for schema in schemas:
29+
print(schema.catalog_name)
30+
print(schema)
31+
schema_data.append({
32+
"Catalog Name": schema.catalog_name,
33+
"Catalog Type": schema.catalog_type,
34+
"Schema Name": schema.full_name,
35+
"Owner": schema.owner,
36+
"Comment": schema.comment,
37+
"Created At": datetime.datetime.fromtimestamp(schema.created_at/1000),
38+
"Updated At": datetime.datetime.fromtimestamp(schema.updated_at/1000),
39+
"Effective Predictive Optimization": schema.effective_predictive_optimization_flag,
40+
"Properites": schema.properties
41+
42+
})
43+
return pd.DataFrame(schema_data)
44+
45+
46+
47+
st.header(body="Unity Catalog", divider=True)
48+
st.subheader("Get catalog and schema information")
49+
st.write(
50+
"This receipt gets the meta data for the catalogs and the schemas."
51+
)
52+
53+
tab_a, tab_b = st.tabs(["**Try it**", "**Code snippets**"])
54+
55+
with tab_a:
56+
if st.button("Try It"):
57+
st.write('### Databricks Catalogs')
58+
st.dataframe(get_catalogs())
59+
60+
st.write('### Databricks Schema')
61+
62+
schemas = get_schemas()
63+
st.dataframe(schemas)
64+
65+
66+
table = [
67+
{
68+
"type": "Get Catalog",
69+
"param": "get_catalog",
70+
"description": "Get the catalogs.",
71+
"code": """
72+
```python
73+
from databricks.sdk import WorkspaceClient
74+
75+
76+
workspace = WorkspaceClient()
77+
78+
def get_catalogs():
79+
catalogs = workspace.catalogs.list()
80+
# Parse metadata into a list of dictionaries
81+
catalogs_data = []
82+
for catalog in catalogs:
83+
catalogs_data.append({
84+
"Catalog Name": catalog.name,
85+
"Owner": catalog.owner,
86+
"Comment": catalog.comment,
87+
"Created At": datetime.datetime.fromtimestamp(catalog.created_at/1000),
88+
"Updated At": datetime.datetime.fromtimestamp(catalog.updated_at/1000),
89+
})
90+
return pd.DataFrame(catalogs_data)
91+
st.write('### Databricks Catalogs')
92+
st.dataframe(get_catalogs())
93+
```
94+
""",
95+
},
96+
{
97+
"type": "Get Schemas",
98+
"param": "get_schemas",
99+
"description": "Get the schemas",
100+
"code": """
101+
```python
102+
from databricks.sdk import WorkspaceClient
103+
104+
workspace = WorkspaceClient()
105+
106+
def get_schemas():
107+
schema_data = []
108+
for catalog in workspace.catalogs.list():
109+
schemas = workspace.schemas.list(catalog_name=catalog.name)
110+
for schema in schemas:
111+
print(schema.catalog_name)
112+
print(schema)
113+
schema_data.append({
114+
"Catalog Name": schema.catalog_name,
115+
"Catalog Type": schema.catalog_type,
116+
"Schema Name": schema.full_name,
117+
"Owner": schema.owner,
118+
"Comment": schema.comment,
119+
"Created At": datetime.datetime.fromtimestamp(schema.created_at/1000),
120+
"Updated At": datetime.datetime.fromtimestamp(schema.updated_at/1000),
121+
"Effective Predictive Optimization": schema.effective_predictive_optimization_flag,
122+
"Properites": schema.properties
123+
124+
})
125+
return pd.DataFrame(schema_data)
126+
schemas = get_schemas()
127+
st.dataframe(schemas)
128+
```
129+
""",
130+
},
131+
]
132+
133+
with tab_b:
134+
for i, row in enumerate(table):
135+
with st.expander(f"**{row['type']} ({row['param']})**", expanded=(i == 0)):
136+
st.markdown(f"**Description**: {row['description']}")
137+
st.markdown(row["code"])

0 commit comments

Comments
 (0)