Snowflake - SnowPro Advanced Data Engineer Study Guide

    2: Data Transformation

    This chapter covers the transformation surface of the DEA-C02 exam, including every variant of user-defined function, external functions, stored procedures across three runtimes, semi-structured and unstructured processing, Snowflake Cortex AI primitives, and the Snowpark DataFrame engine. The material assumes the ingestion patterns from Chapter 1 are already in place and focuses on how data is reshaped, enriched, and prepared for downstream consumption once it sits inside Snowflake-managed storage.

    Learning Objectives

    By the end of this chapter, you will be able to:

    • Define user-defined functions, including Snowpark UDFs (Java, Python, Scala), Secure UDFs, SQL UDFs, JavaScript UDFs, UDTFs, and UDAFs.
    • Create external functions and implement secure external functions.
    • Design stored procedures using Snowpark, Snowflake Scripting, and JavaScript; manage transactions inside procedures.
    • Traverse and transform semi-structured and structured data.
    • Process unstructured data using directory tables, the REST API, and semantic views.
    • Use Snowflake Cortex for categorization, multimedia extraction, semantic analysis, text analytics, multimodal AI, and cost management of AI workloads.
    • Implement modern development workflows using Snowsight Workspaces, Snowflake Notebooks, Git integration, dbt Projects on Snowflake, deployment pipelines, and testing frameworks.
    • Use Snowpark: understand the architecture, query and filter data, perform transformations and aggregations, and manipulate DataFrames.

    Executive Summary

    • The transformation surface of Snowflake spans five execution models: SQL UDFs that inline into the query optimizer, JavaScript UDFs that run in a sandboxed V8 process, Snowpark UDFs that ship serialized callables into a Snowpark sandbox, external functions that route a payload over an API gateway, and Snowpark stored procedures that own a session and can issue arbitrary SQL.
    • Choosing the right primitive is a decision about pushdown, side effects, and isolation. SQL UDFs preserve constant folding and pruning; Snowpark UDFs lose pushdown but gain Python or JVM logic; stored procedures own the session and can mutate state but cannot be called inline in a SELECT.
    • Semi-structured traversal is built on VARIANT, OBJECT, and ARRAY with the : and [] path operators, FLATTEN, GET_PATH, and the schema discovery functions INFER_SCHEMA and SCHEMA_OF_JSON. Unstructured workflows extend this with directory tables, scoped file URLs, and Cortex multimodal functions.
    • Snowflake Cortex exposes managed inference through SQL functions (COMPLETE, CLASSIFY_TEXT, EXTRACT_ANSWER, SUMMARIZE, TRANSLATE, SENTIMENT, EMBED_TEXT_768, EMBED_TEXT_1024, PARSE_DOCUMENT, AI_TRANSCRIBE) and a Cortex REST API. Cost is governed by token consumption per model, surfaced through the CORTEX_FUNCTIONS_USAGE_HISTORY view.
    • Modern development workflow on Snowflake is anchored by Snowsight Workspaces, Snowflake Notebooks with three runtime targets (warehouse, container, Snowpark Container Services), Git integration via API and repository objects, dbt Projects on Snowflake for native dbt execution, and deployment pipelines built on Snowflake CLI plus the snowflake.yml project file.

    Assumptions

    • The reader holds an active SnowPro Core credential and has practical experience writing SQL, Python, and at least one JVM language on a production Snowflake account.
    • Ingestion-side terminology defined in Chapter 1 (named internal stage, external stage, directory table, Snowpipe, Snowpipe Streaming, Stream, Task, Dynamic Table, VARIANT, file format object, scoped file URL) is used here without restatement.
    • All examples assume an Enterprise-edition account with Cortex enabled in the regional deployment and standard RBAC privileges granted to a DATA_ENGINEER role.
    • All identifiers are written in upper case unless the runtime forces case sensitivity; database, schema, and warehouse names in examples are fictional (ANALYTICS_DB, ENG_SCHEMA, TRANSFORM_WH).

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account
    4. Free with account
    5. Free with account
    6. Free with account
    7. Free with account
    8. Free with account
    9. Free with account