Skip to content

Commit ad53710

Browse files
scottDBX1886scottDBX1886
authored andcommitted
new updates
1 parent 5c58198 commit ad53710

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

streamlit/view_groups.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,16 @@
122122
},
123123
],
124124
},
125+
126+
{
127+
"title": "Unity Catalog",
128+
"views": [
129+
{
130+
"label": "Get Catalogs",
131+
"help": "Get meta data.",
132+
"page": "views/unity_catalog_get.py",
133+
"icon": ":material/lan:",
134+
},
135+
],
136+
}
125137
]
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
workspace = WorkspaceClient()
75+
def get_catalogs():
76+
catalogs = workspace.catalogs.list()
77+
# Parse metadata into a list of dictionaries
78+
catalogs_data = []
79+
for catalog in catalogs:
80+
catalogs_data.append({
81+
"Catalog Name": catalog.name,
82+
"Owner": catalog.owner,
83+
"Comment": catalog.comment,
84+
"Created At": datetime.datetime.fromtimestamp(catalog.created_at/1000),
85+
"Updated At": datetime.datetime.fromtimestamp(catalog.updated_at/1000),
86+
})
87+
return pd.DataFrame(catalogs_data)
88+
st.write('### Databricks Catalogs')
89+
st.dataframe(get_catalogs())
90+
```
91+
""",
92+
},
93+
{
94+
"type": "Get Schemas",
95+
"param": "get_schemas",
96+
"description": "Get the schemas",
97+
"code": """
98+
```python
99+
from databricks.sdk import WorkspaceClient
100+
101+
workspace = WorkspaceClient()
102+
103+
def get_schemas():
104+
schema_data = []
105+
for catalog in workspace.catalogs.list():
106+
schemas = workspace.schemas.list(catalog_name=catalog.name)
107+
for schema in schemas:
108+
print(schema.catalog_name)
109+
print(schema)
110+
schema_data.append({
111+
"Catalog Name": schema.catalog_name,
112+
"Catalog Type": schema.catalog_type,
113+
"Schema Name": schema.full_name,
114+
"Owner": schema.owner,
115+
"Comment": schema.comment,
116+
"Created At": datetime.datetime.fromtimestamp(schema.created_at/1000),
117+
"Updated At": datetime.datetime.fromtimestamp(schema.updated_at/1000),
118+
"Effective Predictive Optimization": schema.effective_predictive_optimization_flag,
119+
"Properites": schema.properties
120+
})
121+
return pd.DataFrame(schema_data)
122+
schemas = get_schemas()
123+
st.dataframe(schemas)
124+
```
125+
""",
126+
},
127+
]
128+
129+
with tab_b:
130+
for i, row in enumerate(table):
131+
with st.expander(f"**{row['type']} ({row['param']})**", expanded=(i == 0)):
132+
st.markdown(f"**Description**: {row['description']}")
133+
st.markdown(row["code"])

0 commit comments

Comments
 (0)