Skip to content

Commit

Permalink
Merge branch 'Snowflake-Labs:main' into sfc-gh-rblum-patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-rblum authored Oct 22, 2024
2 parents 5d75ab1 + 9cf060b commit d29f95a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
4 changes: 2 additions & 2 deletions journeys/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def table_selector_dialog() -> None:

st.markdown("<div style='margin: 240px;'></div>", unsafe_allow_html=True)
experimental_features = st.checkbox(
"Enable experimental features (optional)",
help="Checking this box will enable generation of experimental features in the semantic model. If enabling this setting, please ensure that you have the proper parameters set on your Snowflake account. Some features (e.g. joins) are currently in Private Preview and available only to select accounts. Reach out to your account team for access.",
"Enable joins (optional)",
help="Checking this box will enable you to add/edit join paths in your semantic model. If enabling this setting, please ensure that you have the proper parameters set on your Snowflake account. Reach out to your account team for access.",
)

st.session_state["experimental_features"] = experimental_features
Expand Down
8 changes: 5 additions & 3 deletions journeys/iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ def set_up_requirements() -> None:
file_name = st.selectbox("File name", options=available_files, index=None)

experimental_features = st.checkbox(
"Enable experimental features (optional)",
help="Checking this box will enable generation of experimental features in the semantic model. If enabling this setting, please ensure that you have the proper parameters set on your Snowflake account. Some features (e.g. joins) are currently in Private Preview and available only to select accounts. Reach out to your account team for access.",
"Enable joins (optional)",
help="Checking this box will enable you to add/edit join paths in your semantic model. If enabling this setting, please ensure that you have the proper parameters set on your Snowflake account. Reach out to your account team for access.",
)

if st.button(
Expand Down Expand Up @@ -703,7 +703,9 @@ def show() -> None:
return_home_button()
if "yaml" not in st.session_state:
# Only proceed to download the YAML from stage if we don't have one from the builder flow.
yaml = download_yaml(st.session_state.file_name, st.session_state.snowflake_stage.stage_name)
yaml = download_yaml(
st.session_state.file_name, st.session_state.snowflake_stage.stage_name
)
st.session_state["yaml"] = yaml
st.session_state["semantic_model"] = yaml_to_semantic_model(yaml)
if "last_saved_yaml" not in st.session_state:
Expand Down
43 changes: 42 additions & 1 deletion journeys/joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import streamlit as st
from streamlit_extras.row import row

from app_utils.shared_utils import get_snowflake_connection
from semantic_model_generator.data_processing.cte_utils import (
fully_qualified_table_name,
)
from semantic_model_generator.protos import semantic_model_pb2
from semantic_model_generator.snowflake_utils.snowflake_connector import (
get_table_primary_keys,
)

SUPPORTED_JOIN_TYPES = [
join_type
Expand Down Expand Up @@ -167,7 +174,6 @@ def relationship_builder(

@st.experimental_dialog("Join Builder", width="large")
def joins_dialog() -> None:

if "builder_joins" not in st.session_state:
# Making a copy of the original relationships list so we can modify freely without affecting the original.
st.session_state.builder_joins = st.session_state.semantic_model.relationships[
Expand Down Expand Up @@ -210,6 +216,41 @@ def joins_dialog() -> None:
)
return

# Populate primary key information for each table in a join relationship.
left_table_object = next(
(
table
for table in st.session_state.semantic_model.tables
if table.name == relationship.left_table
)
)
right_table_object = next(
(
table
for table in st.session_state.semantic_model.tables
if table.name == relationship.right_table
)
)

with st.spinner("Fetching primary keys..."):
if not left_table_object.primary_key.columns:
primary_keys = get_table_primary_keys(
get_snowflake_connection(),
table_fqn=fully_qualified_table_name(
left_table_object.base_table
),
)
left_table_object.primary_key.columns.extend(primary_keys or [""])

if not right_table_object.primary_key.columns:
primary_keys = get_table_primary_keys(
get_snowflake_connection(),
table_fqn=fully_qualified_table_name(
right_table_object.base_table
),
)
right_table_object.primary_key.columns.extend(primary_keys or [""])

del st.session_state.semantic_model.relationships[:]
st.session_state.semantic_model.relationships.extend(
st.session_state.builder_joins
Expand Down
4 changes: 2 additions & 2 deletions partner/looker.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def set_looker_semantic() -> None:
sample_values = input_sample_value_num()

experimental_features = st.checkbox(
"Enable experimental features (optional)",
help="Checking this box will enable generation of experimental features in the semantic model. If enabling this setting, please ensure that you have the proper parameters set on your Snowflake account. Some features (e.g. joins) are currently in Private Preview and available only to select accounts. Reach out to your account team for access.",
"Enable joins (optional)",
help="Checking this box will enable you to add/edit join paths in your semantic model. If enabling this setting, please ensure that you have the proper parameters set on your Snowflake account. Reach out to your account team for access.",
)

if st.button("Continue", type="primary"):
Expand Down
13 changes: 13 additions & 0 deletions semantic_model_generator/snowflake_utils/snowflake_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ def _get_column_comment(
return ""


def get_table_primary_keys(
conn: SnowflakeConnection,
table_fqn: str,
) -> list[str] | None:
query = f"show primary keys in table {table_fqn};"
cursor = conn.cursor()
cursor.execute(query)
primary_keys = cursor.fetchall()
if primary_keys:
return [pk[3] for pk in primary_keys]
return None


def get_table_representation(
conn: SnowflakeConnection,
schema_name: str,
Expand Down

0 comments on commit d29f95a

Please sign in to comment.