From d925c697fab52edaebdba87acb454f46cfce4f79 Mon Sep 17 00:00:00 2001 From: Sultan Iman Date: Wed, 27 Mar 2024 11:58:26 +0100 Subject: [PATCH] Check for default schema and schema name in streamlit session --- dlt/helpers/streamlit_app/blocks/load_info.py | 53 ++++++++++--------- dlt/helpers/streamlit_app/pages/dashboard.py | 14 +++-- dlt/helpers/streamlit_app/widgets/schema.py | 2 +- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/dlt/helpers/streamlit_app/blocks/load_info.py b/dlt/helpers/streamlit_app/blocks/load_info.py index 134b5ad5a4..d120cc092d 100644 --- a/dlt/helpers/streamlit_app/blocks/load_info.py +++ b/dlt/helpers/streamlit_app/blocks/load_info.py @@ -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) diff --git a/dlt/helpers/streamlit_app/pages/dashboard.py b/dlt/helpers/streamlit_app/pages/dashboard.py index 656dd6ecdf..420c9b2021 100644 --- a/dlt/helpers/streamlit_app/pages/dashboard.py +++ b/dlt/helpers/streamlit_app/pages/dashboard.py @@ -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, diff --git a/dlt/helpers/streamlit_app/widgets/schema.py b/dlt/helpers/streamlit_app/widgets/schema.py index f7883bc45e..c9dd87097e 100644 --- a/dlt/helpers/streamlit_app/widgets/schema.py +++ b/dlt/helpers/streamlit_app/widgets/schema.py @@ -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