Skip to content

Commit

Permalink
Merge pull request #21 from Snowflake-Labs/jroes/new-streamlit-syntax
Browse files Browse the repository at this point in the history
new syntax for prpr
  • Loading branch information
sfc-gh-jroes authored Oct 21, 2022
2 parents 72a37ae + 63c387f commit 3adf7aa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/snowcli/cli/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def streamlit_deploy(environment: str = EnvironmentOption,
config.connectToSnowflake()
results = config.snowflake_connection.deployStreamlit(
name=name, file_path=str(file), stage_path='/',
role=env_conf.get('role'), overwrite=True)
role=env_conf.get('role'), database=env_conf.get('database'),
schema=env_conf.get('schema'),
overwrite=True)

url = results.fetchone()[0]
if open_:
Expand Down
12 changes: 7 additions & 5 deletions src/snowcli/snow_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def createProcedure(self, name: str, inputParameters: str, returnType: str, hand
'execute_as_caller': execute_as_caller
})

def uploadFileToStage(self, file_path, destination_stage, path, role, overwrite):
def uploadFileToStage(self, file_path, destination_stage, path, role, database, schema, overwrite):
self.cs.execute(f'use database {database}')
self.cs.execute(f'use role {role}')
self.cs.execute(f'use schema {schema}')
self.cs.execute(
f'create stage if not exists {destination_stage} comment="deployments managed by snowcli"')
self.cs.execute(
Expand Down Expand Up @@ -173,9 +175,9 @@ def createStreamlit(self, database="", schema="", role="", warehouse="", name=""
'file_name': file
})

def deployStreamlit(self, name, file_path, stage_path, role, overwrite):
self.uploadFileToStage(file_path, f"{name}_stage", stage_path, role, overwrite)
return self.runSql("get_streamlit_url", { "name": name })
def deployStreamlit(self, name, file_path, stage_path, role, database, schema, overwrite):
self.uploadFileToStage(file_path, f"{name}_stage", stage_path, role, database, schema, overwrite)
return self.runSql("get_streamlit_url", { "name": name, "role": role, "database": database, "schema": schema })

def runSql(self, command, context, show_exceptions=True) -> SnowflakeCursor:
sql = pkgutil.get_data(__name__, f"sql/{command}.sql").decode()
Expand All @@ -200,4 +202,4 @@ def runSql(self, command, context, show_exceptions=True) -> SnowflakeCursor:


def generate_signature_from_params(self, params: str) -> str:
return '(' + ' '.join(params.strip('()').split()[1::2]) + ')'
return '(' + ' '.join(params.strip('()').split()[1::2]) + ')'
5 changes: 3 additions & 2 deletions src/snowcli/sql/create_streamlit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use warehouse {warehouse};
create or replace stage {name}_stage;

create streamlit {name}
versions (main @st_db.st_schema.{name}_stage '/{file_name}')
warehouse=regress;
ROOT_LOCATION = @{database}.{schema}.{name}_stage
MAIN_FILE = '/{file_name}'
QUERY_WAREHOUSE = {warehouse};

show streamlits;
describe streamlit {name};
6 changes: 5 additions & 1 deletion src/snowcli/sql/get_streamlit_url.sql
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
CALL SYSTEM$GENERATE_STREAMLIT_URL('st_db.st_schema.{name}');
use database {database};
use schema {schema};
use role {role};

CALL SYSTEM$GENERATE_STREAMLIT_URL_FROM_NAME('{name}');

0 comments on commit 3adf7aa

Please sign in to comment.