1

I utilized the Snowpark Python (private preview) to do some data engineering tasks (transform the data from a raw state to a clean state). How do I upload the Python code to Snowflake to then run it?

I think it needs to be a stored procedure but I can not find any documentation on how to create a stored procedure in Python.

halfwind22
  • 329
  • 4
  • 18
Grant Culp
  • 171
  • 9

2 Answers2

1

Snowpark Stored Procedures for Python — Preview was relased in June 2022.


Documentation is avaiable at Writing Stored Procedures in Snowpark (Python)

Example:

In an in-line stored procedure, you write your Python code in the AS clause of the CREATE PROCEDURE statement. For example:

CREATE OR REPLACE PROCEDURE MYPROC(from_table STRING, to_table STRING, count INT)
  RETURNS STRING
  LANGUAGE PYTHON
  RUNTIME_VERSION = '3.8'
  PACKAGES = ('snowflake-snowpark-python')
  HANDLER = 'run'
AS
$$
def run(session, from_table, to_table, count):
  session.table(from_table).limit(count).write.save_as_table(to_table)
  return "SUCCESS"
$$;
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
1

Adding to Lukasz Szozda's answer, we could write the python code in a file and upload it to a Snowflake stage. Then write a procedure to invoke the code from the stage. Attaching link for reference: Code uploaded from stage

halfwind22
  • 329
  • 4
  • 18