Week 45 - Snowpark & Python

This week we're creating permanent UDFs via Snowpark and giving them a whiz!

Run this in the Snowflake console

CREATE OR REPLACE TABLE website_clicks (id INTEGER,user_id INTEGER,page_url STRING,click_time TIMESTAMP,click_location STRING);INSERT INTO website_clicks VALUES (1, 101, 'https://www.example.com/home', '2023-05-12 08:00:00', '<div id="header" class="header">');INSERT INTO website_clicks VALUES (2, 102, 'https://www.example.com/products', '2023-05-12 08:05:00', '<main class="content">');INSERT INTO website_clicks VALUES (3, 101, 'https://www.example.com/about', '2023-05-12 08:10:00', '<footer class="site-footer">');INSERT INTO website_clicks VALUES (4, 103, 'https://www.example.com/home', '2023-05-12 08:15:00', '<section class="main-content">');INSERT INTO website_clicks VALUES (5, 102, 'https://www.example.com/contact', '2023-05-12 08:20:00', '<header class="site-header">');
  1. Download this file
  2. Place that file into an internal stage
  3. Create a UDF from that stage called exctract_class_value
  4. Run the below code and check that you've done it correctly
clean_data = (session.table("website_clicks").withColumn("click_location",call_udf("extract_class_value", col("click_location"))))

P.S. I'll be speaking about all things Snowpark at a panel discussion at Summit!

Remember, if you want to participate:

  1. Sign up as a member of Frosty Friday. You can do this by clicking on the sidebar, and then going to ‘REGISTER
  2. Post your code to GitHub and make it publicly available (Check out our guide if you don’t know how to here)
  3. Post the URL in the comments of the challenge
Previous
Previous

Week 46 - SQL & Query Techniques

Next
Next

Week 44 – Security & Governance