File tree 4 files changed +68
-1
lines changed
4 files changed +68
-1
lines changed Original file line number Diff line number Diff line change
1
+ manifest_version : 1
2
+ artifacts :
3
+ setup_script : scripts/setup.sql
4
+ readme : readme.md
Original file line number Diff line number Diff line change
1
+ def multiply (num1 , num2 ):
2
+ return num1 * num2
Original file line number Diff line number Diff line change @@ -13,4 +13,41 @@ CREATE OR REPLACE PROCEDURE CORE.HELLO()
13
13
RETURN ' Hello Snowflake!' ;
14
14
END;
15
15
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;
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments