How Can We Create a Snowflake Python Worksheet?
How Can We Create a Snowflake Python Worksheet? | Factspan

How Can We Create a Snowflake Python Worksheet?

Snowflake has recently released the Snowflake Python Worksheets which is in public preview at present. This will make it much more easier than ever to integrate Snowpark Python directly into your?Snowflake environment.

Today, we will cover how to set up your Python worksheets, write Python code, run it efficiently, and deploy it as a stored procedure within your Snowflake environment.

Prerequisites

  1. Login to Snowflake using an admin account and switch to the ORGADMIN role. This role is required to enable Python packages.
  2. Under “Admin” section and click on “Billing & Terms”
  3. Under “Anaconda –> Anaconda Python Packages”, click “Enable”
  4. Click on “Acknowledge & Continue”, This will enable the Python feature for the Snowflake worksheets

Creating Python Worksheets in Snowflake

STEP 1: Log in to the Snowflake (Snowsight UI) and navigate to the Worksheets located in the left-side panel. Click on “+” button and select the “Python Worksheet”.

STEP 2:?Select the Database & Virtual Warehouse for the worksheet.

STEP 3:?Now, write some python code inside the Snowflake Python worksheet. In the example below, we are generating the five employee records using a random function. Copy the below sample code into your worksheet and click on Run button.?

How Do We Add Custom Python Packages?

What if you can’t find the package in the Snowflake Anaconda? Or, you have created a custom Python file or package and wanted to import it into your Snowflake worksheet? Stated below are the steps to import custom packages:

Step 1:?In the worksheet tab, under the “Packages”, select “Stage Packages” and import the required Python file or package which is stage location.

For example, @YourStage/path/to/package.py

Step 2:?Now, select Import to add your package to the list of installed packages. You can now use import statements to use the package in your Python worksheet.

How Do We Deploy the Python Worksheet as Snowflake Stored Procedure?

Step 1:?On the right-hand corner of the worksheet, click on the “Deploy” and input stored procedure name. Then, click on the Deploy button to create as a Snowflake Stored Procedure.

Step 2:?Call the Stored Procedure as below once it is created successfully.

Command:?CALL TEST_DB1.PUBLIC.SAMPLE_EMPDATA ()?

Step 3:?Now, you have successfully deployed your python script as a Snowflake Stored Procedure.


[Click here to read the complete blog...]

要查看或添加评论,请登录

Factspan的更多文章

社区洞察

其他会员也浏览了