Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DBT Semantic File Merging #132

Merged
merged 17 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions admin_apps/app.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import streamlit as st
from snowflake.connector import DatabaseError

from admin_apps.shared_utils import GeneratorAppScreen, get_snowflake_connection
from semantic_model_generator.snowflake_utils.env_vars import (
# set_page_config must be run as the first Streamlit command on the page, before any other streamlit imports.
st.set_page_config(layout="wide", page_icon="💬", page_title="Semantic Model Generator")

from admin_apps.shared_utils import ( # noqa: E402
GeneratorAppScreen,
get_snowflake_connection,
)
from semantic_model_generator.snowflake_utils.env_vars import ( # noqa: E402
SNOWFLAKE_ACCOUNT_LOCATOR,
SNOWFLAKE_HOST,
SNOWFLAKE_USER,
assert_required_env_vars,
)

# set_page_config must be run as the first Streamlit command on the page, before any other streamlit imports.
st.set_page_config(layout="wide", page_icon="💬", page_title="Semantic Model Generator")


@st.experimental_dialog(title="Setup")
@st.dialog(title="Setup")
def env_setup_popup(missing_env_vars: list[str]) -> None:
"""
Renders a dialog box to prompt the user to set the required environment variables.
Expand All @@ -28,7 +31,7 @@ def env_setup_popup(missing_env_vars: list[str]) -> None:
st.stop()


@st.experimental_dialog(title="Connection Error")
@st.dialog(title="Connection Error")
def failed_connection_popup() -> None:
"""
Renders a dialog box detailing that the credentials provided could not be used to connect to Snowflake.
Expand Down
2 changes: 1 addition & 1 deletion admin_apps/journeys/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def update_tables() -> None:
st.session_state["selected_tables"] = valid_selected_tables


@st.experimental_dialog("Selecting your tables", width="large")
@st.dialog("Selecting your tables", width="large")
def table_selector_dialog() -> None:
st.write(
"Please fill out the following fields to start building your semantic model."
Expand Down
32 changes: 20 additions & 12 deletions admin_apps/journeys/iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
download_yaml,
get_snowflake_connection,
init_session_states,
integrate_partner_semantics,
upload_yaml,
validate_and_upload_tmp_yaml,
)
Expand Down Expand Up @@ -135,7 +136,7 @@ def show_expr_for_ref(message_index: int) -> None:
st.dataframe(col_df, hide_index=True, use_container_width=True, height=250)


@st.experimental_dialog("Edit", width="large")
@st.dialog("Edit", width="large")
def edit_verified_query(
conn: SnowflakeConnection, sql: str, question: str, message_index: int
) -> None:
Expand Down Expand Up @@ -334,7 +335,7 @@ def chat_and_edit_vqr(_conn: SnowflakeConnection) -> None:
st.session_state.active_suggestion = None


@st.experimental_dialog("Upload", width="small")
@st.dialog("Upload", width="small")
def upload_dialog(content: str) -> None:
def upload_handler(file_name: str) -> None:
if not st.session_state.validated and changed_from_last_validated_model():
Expand Down Expand Up @@ -420,7 +421,7 @@ def update_container(
container.markdown(content)


@st.experimental_dialog("Error", width="small")
@st.dialog("Error", width="small")
def exception_as_dialog(e: Exception) -> None:
st.error(f"An error occurred: {e}")

Expand Down Expand Up @@ -450,12 +451,8 @@ def yaml_editor(yaml_str: str) -> None:
status_container = st.empty()

with button_container:
(
left,
middle,
right,
) = st.columns(3)
if left.button("Validate", use_container_width=True, help=VALIDATE_HELP):
(one, two, three, four) = st.columns(4)
if one.button("Validate", use_container_width=True, help=VALIDATE_HELP):
# Validate new content
try:
validate(
Expand Down Expand Up @@ -485,7 +482,7 @@ def yaml_editor(yaml_str: str) -> None:
st.rerun()

if content:
middle.download_button(
two.download_button(
label="Download",
data=content,
file_name="semantic_model.yaml",
Expand All @@ -494,12 +491,19 @@ def yaml_editor(yaml_str: str) -> None:
help=DOWNLOAD_HELP,
)

if right.button(
if three.button(
"Upload",
use_container_width=True,
help=UPLOAD_HELP,
):
upload_dialog(content)
if four.button(
"Partner Semantic",
use_container_width=True,
help=PARTNER_SEMANTIC_HELP,
disabled=not st.session_state["validated"],
):
integrate_partner_semantics()

# Render the validation state (success=True, failed=False, editing=None) in the editor.
if st.session_state.validated:
Expand Down Expand Up @@ -583,7 +587,7 @@ def stage_selector_container() -> None:
)


@st.experimental_dialog("Welcome to the Iteration app! 💬", width="large")
@st.dialog("Welcome to the Iteration app! 💬", width="large")
def set_up_requirements() -> None:
"""
Collects existing YAML location from the user so that we can download it.
Expand Down Expand Up @@ -642,6 +646,10 @@ def set_up_requirements() -> None:
you think your semantic model is doing great and should be pushed to prod! Note that
the semantic model must be validated to be uploaded."""

PARTNER_SEMANTIC_HELP = """Have an existing semantic layer in a partner tool that's integrated
with Snowflake? Use this feature to integrate partner semantic specs into Cortex Analyst's spec.
Note that the Cortex Analyst semantic model must be validated before integrating partner semantics."""


def show() -> None:
init_session_states()
Expand Down
2 changes: 1 addition & 1 deletion admin_apps/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ python-dotenv==1.0.1
urllib3==1.26.19
requests==2.32.3
sqlglot==23.17.0
streamlit==1.36.0
streamlit==1.37.1
streamlit-extras==0.4.3
streamlit-monaco==0.1.3
snowflake-connector-python[secure-local-storage]==3.11.0
Loading
Loading