Skip to content

Commit

Permalink
Check for default schema and schema name in streamlit session
Browse files Browse the repository at this point in the history
  • Loading branch information
sultaniman committed Apr 16, 2024
1 parent 0abad12 commit ba6c206
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
53 changes: 27 additions & 26 deletions dlt/helpers/streamlit_app/blocks/load_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,34 @@


def last_load_info(pipeline: dlt.Pipeline) -> None:
loads_df = query_data_live(
pipeline,
f"SELECT load_id, inserted_at FROM {pipeline.default_schema.loads_table_name} WHERE"
" status = 0 ORDER BY inserted_at DESC LIMIT 101 ",
)

if loads_df is None:
st.error(
"Load info is not available",
icon="🚨",
if pipeline.default_schema_name:
loads_df = query_data_live(
pipeline,
f"SELECT load_id, inserted_at FROM {pipeline.default_schema.loads_table_name} WHERE"
" status = 0 ORDER BY inserted_at DESC LIMIT 101 ",
)
else:
loads_no = loads_df.shape[0]
if loads_df.shape[0] > 0:
rel_time = (
humanize.naturaldelta(
pendulum.now() - pendulum.from_timestamp(loads_df.iloc[0, 1].timestamp())
)
+ " ago"

if loads_df is None:
st.error(
"Load info is not available",
icon="🚨",
)
last_load_id = loads_df.iloc[0, 0]
if loads_no > 100:
loads_no = "> " + str(loads_no)
else:
rel_time = "---"
last_load_id = "---"
loads_no = loads_df.shape[0]
if loads_df.shape[0] > 0:
rel_time = (
humanize.naturaldelta(
pendulum.now() - pendulum.from_timestamp(loads_df.iloc[0, 1].timestamp())
)
+ " ago"
)
last_load_id = loads_df.iloc[0, 0]
if loads_no > 100:
loads_no = "> " + str(loads_no)
else:
rel_time = "---"
last_load_id = "---"

stat("Last load time", rel_time, border_left_width=4)
stat("Last load id", last_load_id)
stat("Total number of loads", loads_no)
stat("Last load time", rel_time, border_left_width=4)
stat("Last load id", last_load_id)
stat("Total number of loads", loads_no)
14 changes: 9 additions & 5 deletions dlt/helpers/streamlit_app/pages/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ def write_data_explorer_page(

st.subheader("Schemas and tables", divider="rainbow")
schema_picker(pipeline)
tables = sorted(
st.session_state["schema"].data_tables(),
key=lambda table: table["name"],
)
if schema := st.session_state["schema"]:
tables = sorted(
schema.data_tables(),
key=lambda table: table["name"],
)

list_table_hints(pipeline, tables)
else:
st.warning("No schemas found")

list_table_hints(pipeline, tables)
maybe_run_query(
pipeline,
show_charts=show_charts,
Expand Down
2 changes: 1 addition & 1 deletion dlt/helpers/streamlit_app/widgets/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def schema_picker(pipeline: dlt.Pipeline) -> None:
)
schema = pipeline.schemas.get(selected_schema_name)

st.session_state["schema"] = schema
if schema:
st.subheader(f"Schema: {schema.name}")
st.session_state["schema"] = schema

0 comments on commit ba6c206

Please sign in to comment.