简体   繁体   English

Snowflake Procedure可以写成python而不是javascript吗?

[英]Can Snowflake Procedure can be written in python instead of javascript?

Can Snowflake Procedure can be written in python instead of javascript? Snowflake Procedure可以写成python而不是javascript吗?

I went through Snowflake document it says javascript but was looking for options other then javascript.我浏览了 Snowflake 文档,上面写着 javascript,但我正在寻找 javascript 以外的选项。

Snowflake recently introduced External functions which gives user ability to write UDFS in python. More details on following link Snowflake 最近引入了外部功能,使用户能够在 python 中编写 UDFS。有关以下链接的更多详细信息

https://docs.snowflake.com/en/sql-reference/external-functions-introduction.html https://docs.snowflake.com/en/sql-reference/external-functions-introduction.html

https://community.snowflake.com/s/article/Snowflake-External-Function https://community.snowflake.com/s/article/Snowflake-外部函数

As of Sept 2022, Snowflake has added Python 3.8 support to Functions and Procedures in Snowflake now with packages like Pandas preinstalled.截至 2022 年 9 月,Snowflake 已为 Snowflake 中的函数和过程添加了 Python 3.8 支持,现在预装了 Pandas 等软件包。

To see what python packages you can use inside Snowflake:要查看您可以在 Snowflake 中使用哪些 python 包:

select * from information_schema.packages where language = 'python';

To have your Python code directly in snowflake running, you can create a Python UDF:要让您的 Python 代码直接在雪花运行中,您可以创建一个 Python UDF:

-- Creates the function that adds 1 to 2 integers you pass it.
create or replace function add_one_to_inputs(x number(10, 0), y number(10, 0))
returns number(10, 0)
language python
runtime_version = 3.8
packages = ('pandas')
handler = 'add_one_to_inputs'
as
$$
import pandas

def add_one_to_inputs(df):
  return df[0] + df[1] + 1

add_one_to_inputs._sf_vectorized_input = pandas.DataFrame
$$;

-- After function creation to run call it
select add_one_to_inputs(2,4);

Not only that, you can also execute python code from a stage.不仅如此,您还可以从一个阶段执行 python 代码。 You can execute the CREATE PROCEDURE command, pointing to the Python file on the stage.您可以执行 CREATE PROCEDURE 命令,指向舞台上的 Python 文件。 For example:例如:

CREATE OR REPLACE PROCEDURE MYPROC(from_table STRING, to_table STRING, count INT)
  RETURNS INT
  LANGUAGE PYTHON
  RUNTIME_VERSION = '3.8'
  PACKAGES = ('snowflake-snowpark-python')
  IMPORTS = ('@mystage/my_py_file.py')
  HANDLER = 'my_py_file.run';

You can read more about Python UDFs here: https://docs.snowflake.com/en/developer-guide/udf/python/udf-python.html#python-udfs您可以在此处阅读有关 Python UDF 的更多信息: https://docs.snowflake.com/en/developer-guide/udf/python/udf-python.html#python-udfs

Writing Stored Procedures in Python: https://docs.snowflake.com/en/sql-reference/stored-procedures-python.html Python中编写存储过程: https://docs.snowflake.com/en/sql-reference/stored-procedures-python.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM