This week, we’re using a feature that, at the time of writing, is pretty hot off the press :
Python in Snowflake.
To start out create a simple table with a single column with a number, the size and amount are up to you,
After that we’ll start with a very basic function: multiply those numbers by 3.
The challenge here is not ‘build a very difficult python function’ but to build and use the function in Snowflake.
We can test the code with a simple select statement :
SELECT timesthree(start_int)
FROM FF_week_5
Remember if you want to participate:
- Sign up as a member of Frosty Friday. You can do this by clicking on the sidebar, and then going to ‘REGISTER‘ (note joining our mailing list does not give you a Frosty Friday account)
- Post your code to GitHub and make it publicly available (Check out our guide if you don’t know how to here)
- Post the URL in the comments of the challenge.
If you have any technical questions you’d like to pose to the community, you can ask here on our dedicated thread.
I’ve just spent two weeks practicing making Python UDFs for a customer, so this was oddly the easiest challenge so far for me!
Solution URL: https://github.com/ChrisHastieIW/Frosty-Friday/blob/main/Week%205%20-%20Basic%20-%20UDFs/Week%205%20-%20Basic%20-%20UDFs.sql
Reorganised my submission repo, new master solution URL here.
https://github.com/daanalytics/Snowflake/blob/master/FrostyFriday/ffc_challenge_5_basic.sql
I’m finding it very difficult to format answers in this comment box.
My approach:
1. Create a table with a single column
2. Create a view querying that table that uses an udf
2.1. Use a pre-hook to create the udf needed in the view.
dbt-docs: http://dvd-il-bucket-public.s3-website-eu-west-1.amazonaws.com/#!/model/model.frosty.challenge_05_01#code
My knowledge of Python is minimum, probably need to invest a lot more to make the function more useful.
https://github.com/EmoktayrE/Frosty_Friday_Challenges/blob/main/ffchallenge5.sql
Created 2 functions, basic SQL UDF and a Python one as well. In this case, a simple SQL one is simpler as you have less to define.
My solution for week 5
Check out Challenge 5 blog: https://theinformationlab.nl/en/2022/09/21/python-udfs-in-snowflake/
This was fast one to finish just by using Snowflake docs to get the create function syntax right!
Here’s my solution, which the docs made very easy!
Nice little intro, wasn’t aware you could do this is snowflake. My Solution ^
Solution
Lovely!