我创建了这个基本存储过程,用于基于客户id查询雪花表:
CREATE OR REPLACE PROCEDURE SP_Snowpark_Python_Revenue_2(site_id STRING)
RETURNS STRING
LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
PACKAGES = ('snowflake-snowpark-python')
HANDLER = 'run'
AS
$$
from snowflake.snowpark.functions import *
def run(session, site_id):
df_rev_tmp = session.table("revenue").select(col("site_id"), col("subscription_id"), col("country_name"), col("product_name"))
df_rev_final = df_rev_tmp.filter(col("site_id") == site_id)
return "SUCCESS"
$$;它可以正常工作,但我希望我的sproc为整个结果集返回一个JSON对象。我对它作了修改:
CREATE OR REPLACE PROCEDURE SP_Snowpark_Python_Revenue_3(site_id STRING)
RETURNS STRING
LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
PACKAGES = ('snowflake-snowpark-python')
HANDLER = 'run'
AS
$$
from snowflake.snowpark.functions import *
def run(session, site_id):
df_rev = session.table("revenue").select(col("site_id"), col("subscription_id"), col("country_name"), col("product_name"))
df_rev_tmp = df_rev.filter(col("site_id") == site_id)
df_rev_final = df_rev_tmp.to_pandas()
df_rev_json = df_rev_final.to_json(orient = 'columns')
return df_rev_json
$$;它编译时没有错误,但在运行时出现此错误时失败:
CALL SP_Snowpark_Python_Revenue_3('dfgerr6223').....
255002: Optional dependency: 'pyarrow' is not installed...我在这里错过了什么?
发布于 2022-11-02 03:57:34
您需要将pyarrow作为一个包来查询:
PACKAGES = ('snowflake-snowpark-python', 'pyarrow')但是要获得这些包,您的组织中的某个人需要批准Anaconda服务条款,否则您将得到以下错误:
SQL compilation error: Anaconda terms must be accepted by ORGADMIN to use Anaconda 3rd party packages. Please follow the instructions at https://…具有ORGADMIN角色的人可以执行以下步骤:
https://stackoverflow.com/questions/74281446
复制相似问题