cryogenic22 commited on
Commit
3fe86f7
·
verified ·
1 Parent(s): 961da88

Create ui/db_explorer

Browse files
Files changed (1) hide show
  1. ui/db_explorer +69 -0
ui/db_explorer ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Database explorer UI component for the pharmaceutical data management agent.
3
+ """
4
+
5
+ import streamlit as st
6
+ import pandas as pd
7
+
8
+ def render_db_explorer_tab(session_state):
9
+ """
10
+ Render the database explorer tab in the UI.
11
+
12
+ Args:
13
+ session_state: Streamlit session state
14
+ """
15
+ st.subheader("Database Explorer")
16
+
17
+ # Get tables by category
18
+ tables = session_state.db.get_tables()
19
+
20
+ # Display tables by category
21
+ col1, col2 = st.columns(2)
22
+
23
+ with col1:
24
+ st.markdown("### Raw Data Tables")
25
+ for table in tables["raw_tables"]:
26
+ with st.expander(table):
27
+ sample = session_state.db.get_table_sample(table, 3)
28
+ st.dataframe(pd.DataFrame(sample))
29
+
30
+ st.markdown("### Staging Tables")
31
+ for table in tables["staging_tables"]:
32
+ with st.expander(table):
33
+ sample = session_state.db.get_table_sample(table, 3)
34
+ st.dataframe(pd.DataFrame(sample))
35
+
36
+ with col2:
37
+ st.markdown("### Analytics Ready Data")
38
+ for table in tables["ard_tables"]:
39
+ with st.expander(table):
40
+ sample = session_state.db.get_table_sample(table, 3)
41
+ st.dataframe(pd.DataFrame(sample))
42
+
43
+ st.markdown("### Data Products")
44
+ for table in tables["data_products"]:
45
+ with st.expander(table):
46
+ sample = session_state.db.get_table_sample(table, 3)
47
+ st.dataframe(pd.DataFrame(sample))
48
+
49
+ # SQL Query Executor
50
+ st.markdown("### Query Explorer")
51
+ with st.form(key="sql_form"):
52
+ sql_query = st.text_area("Enter SQL Query", height=100,
53
+ placeholder="SELECT * FROM ARD_SALES_PERFORMANCE WHERE region = 'North' LIMIT 5")
54
+ run_sql = st.form_submit_button("Run Query")
55
+
56
+ if run_sql and sql_query:
57
+ with st.spinner("Executing query..."):
58
+ result = session_state.db.execute_query(sql_query)
59
+
60
+ if "error" in result:
61
+ st.error(f"Error executing query: {result['error']}")
62
+ elif "data" in result:
63
+ st.dataframe(pd.DataFrame(result["data"]))
64
+ st.success(f"Query returned {len(result['data'])} rows")
65
+ elif "tables" in result:
66
+ st.write(result["tables"])
67
+ elif "schema" in result:
68
+ st.write(f"Schema for {result['table']}:")
69
+ st.dataframe(pd.DataFrame(result["schema"]))