Skip to content

Commit 70f88ef

Browse files
Final updates on Tutorial. Creates days to billion folder
1 parent 0ac97e9 commit 70f88ef

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

days_to_billion/manifest.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
manifest_version: 1
2+
artifacts:
3+
setup_script: scripts/setup.sql
4+
readme: readme.md

tutorial/python/hello_python.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def multiply(num1, num2):
2+
return num1*num2

tutorial/scripts/setup.sql

+38-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,41 @@ CREATE OR REPLACE PROCEDURE CORE.HELLO()
1313
RETURN 'Hello Snowflake!';
1414
END;
1515

16-
GRANT USAGE ON PROCEDURE core.hello() TO APPLICATION ROLE app_public;
16+
GRANT USAGE ON PROCEDURE core.hello() TO APPLICATION ROLE app_public;
17+
18+
CREATE OR ALTER VERSIONED SCHEMA code_schema;
19+
GRANT USAGE ON SCHEMA code_schema TO APPLICATION ROLE app_public;
20+
21+
CREATE VIEW IF NOT EXISTS code_schema.accounts_view
22+
AS SELECT ID, NAME, VALUE
23+
FROM shared_data.accounts;
24+
GRANT SELECT ON VIEW code_schema.accounts_view TO APPLICATION ROLE app_public;
25+
26+
CREATE OR REPLACE FUNCTION code_schema.addone(i int)
27+
RETURNS INT
28+
LANGUAGE PYTHON
29+
RUNTIME_VERSION = '3.8'
30+
HANDLER = 'addone_py'
31+
AS
32+
$$
33+
def addone_py(i):
34+
return i+1
35+
$$;
36+
37+
GRANT USAGE ON FUNCTION code_schema.addone(int) TO APPLICATION ROLE app_public;
38+
39+
CREATE or REPLACE FUNCTION code_schema.multiply(num1 float, num2 float)
40+
RETURNS float
41+
LANGUAGE PYTHON
42+
RUNTIME_VERSION=3.8
43+
IMPORTS = ('/python/hello_python.py')
44+
HANDLER='hello_python.multiply';
45+
46+
GRANT USAGE ON FUNCTION code_schema.multiply(FLOAT, FLOAT) TO APPLICATION ROLE app_public;
47+
48+
CREATE STREAMLIT code_schema.hello_snowflake_streamlit
49+
FROM '/streamlit'
50+
MAIN_FILE = '/hello_snowflake.py'
51+
;
52+
53+
GRANT USAGE ON STREAMLIT code_schema.hello_snowflake_streamlit TO APPLICATION ROLE app_public;

tutorial/streamlit/hello_snowflake.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Import python packages
2+
import streamlit as st
3+
from snowflake.snowpark.context import get_active_session
4+
5+
# Write directly to the app
6+
st.title("Hello Snowflake - Streamlit Edition")
7+
st.write(
8+
"""The following data is from the accounts table in the application package.
9+
However, the Streamlit app queries this data from a view called
10+
code_schema.accounts_view.
11+
"""
12+
)
13+
14+
# Get the current credentials
15+
session = get_active_session()
16+
17+
# Create an example data frame
18+
data_frame = session.sql("SELECT * FROM code_schema.accounts_view;")
19+
20+
# Execute the query and convert it into a Pandas data frame
21+
queried_data = data_frame.to_pandas()
22+
23+
# Display the Pandas data frame as a Streamlit data frame.
24+
st.dataframe(queried_data, use_container_width=True)

0 commit comments

Comments
 (0)