I have created this basic stored procedure to query a Snowflake table based on a customer id:
JavaScript
x
15
15
1
CREATE OR REPLACE PROCEDURE SP_Snowpark_Python_Revenue_2(site_id STRING)
2
RETURNS STRING
3
LANGUAGE PYTHON
4
RUNTIME_VERSION = '3.8'
5
PACKAGES = ('snowflake-snowpark-python')
6
HANDLER = 'run'
7
AS
8
$$
9
from snowflake.snowpark.functions import *
10
def run(session, site_id):
11
df_rev_tmp = session.table("revenue").select(col("site_id"), col("subscription_id"), col("country_name"), col("product_name"))
12
df_rev_final = df_rev_tmp.filter(col("site_id") == site_id)
13
return "SUCCESS"
14
$$;
15
It works fine but I would like my sproc to return a JSON object for the whole result set. I modified it thusly:
JavaScript
1
17
17
1
CREATE OR REPLACE PROCEDURE SP_Snowpark_Python_Revenue_3(site_id STRING)
2
RETURNS STRING
3
LANGUAGE PYTHON
4
RUNTIME_VERSION = '3.8'
5
PACKAGES = ('snowflake-snowpark-python')
6
HANDLER = 'run'
7
AS
8
$$
9
from snowflake.snowpark.functions import *
10
def run(session, site_id):
11
df_rev = session.table("revenue").select(col("site_id"), col("subscription_id"), col("country_name"), col("product_name"))
12
df_rev_tmp = df_rev.filter(col("site_id") == site_id)
13
df_rev_final = df_rev_tmp.to_pandas()
14
df_rev_json = df_rev_final.to_json(orient = 'columns')
15
return df_rev_json
16
$$;
17
It compiles without errors but fails at runtime with this error:
JavaScript
1
3
1
CALL SP_Snowpark_Python_Revenue_3('dfgerr6223') ..
2
255002: Optional dependency: 'pyarrow' is not installed
3
What am I missing here?
Advertisement
Answer
You need to ask for pyarrow
as a package:
JavaScript
1
2
1
PACKAGES = ('snowflake-snowpark-python', 'pyarrow')
2
But to get these packages, someone in your org will need to approve the Anaconda terms of service, or you’ll get the following error:
JavaScript
1
2
1
SQL compilation error: Anaconda terms must be accepted by ORGADMIN to use Anaconda 3rd party packages. Please follow the instructions at https://…
2
Someone with ORGADMIN role can follow these steps: