CertSafari
    Snowflake SnowPro Advanced: Data Analyst (DAA-C01)· Lessons

    Domain 1 · Lesson 7/19

    Snowflake Geospatial, AI, UDF and ML Functions

    Given a scenario, use Snowflake functions.

    13 min read
    2.43% of exam
    13 sources
    Published 5 Oct 2026
    Docs as of 4 Oct 2026

    What you will be able to do

    • Pick geospatial functions to work with GEOGRAPHY and GEOMETRY values
    • Match a text-analysis task to the right Cortex AI function, and name the privileges it needs
    • Choose a UDF variation and handler language, keeping data sharing in mind
    • Tell Classification, Top Insights and Anomaly Detection apart and describe how each one is called

    1.Geospatial functions

    Geospatial functions work on the GEOGRAPHY and GEOMETRY data types. They also convert those values to and from other formats, such as VARCHAR. The catalogue is grouped by job:

    - Input/parsing: TO_GEOGRAPHY, TRY_TO_GEOGRAPHY, ST_GEOGRAPHYFROMWKT. - Output/formatting: ST_ASGEOJSON, ST_ASWKT, ST_GEOHASH. - Constructors: ST_MAKEPOINT, ST_MAKELINE, ST_MAKEPOLYGON. - Accessors: ST_X, ST_Y, ST_SRID. - Relationships and measurements: ST_DISTANCE, ST_CONTAINS, ST_INTERSECTS, ST_DWITHIN, HAVERSINE, ST_AREA. - Transformations: ST_BUFFER, ST_UNION_AGG, ST_TRANSFORM. - H3 grid indexing: H3_LATLNG_TO_CELL, H3_POLYGON_TO_CELLS.

    Some functions only accept one of the two types. For example, ST_MAKEPOINT, ST_DWITHIN and all the H3 functions are GEOGRAPHY-only, while ST_BUFFER, ST_TRANSFORM and ST_SETSRID are GEOMETRY-only. Exam scenarios can turn on that difference.

    The GEOGRAPHY/GEOMETRY split shows up as paired functions. To build a point, ST_MAKEPOINT (alias ST_POINT) gives a GEOGRAPHY, while ST_MAKEGEOMPOINT (alias ST_GEOMPOINT) gives a GEOMETRY. To convert from other representations, TO_GEOGRAPHY, ST_GEOGRAPHYFROMWKT and ST_GEOGRAPHYFROMWKB are GEOGRAPHY-only, while TO_GEOMETRY, ST_GEOMETRYFROMWKT and ST_GEOMETRYFROMWKB are GEOMETRY-only. So a scenario that builds points and then measures them, for example with ST_DISTANCE, needs a constructor that matches the type of the data. ST_ASWKT (alias ST_ASTEXT) turns either type back into text.

    Checkpoint 1 of 7· Check yourself

    A pipeline stores delivery points as GEOGRAPHY, and a downstream tool needs them as text. Which statement about geospatial functions applies?

    Sources1

    2.Cortex AI functions

    Cortex AI Functions run LLM-powered analysis on text and images as ordinary SQL functions. They are also available in Python. To call them, your role needs the USE AI FUNCTIONS account-level privilege plus either the CORTEX_USER or the AI_FUNCTIONS_USER database role.

    Each task-specific function maps to one job. AI_COMPLETE handles general generative work. AI_CLASSIFY puts text or images into categories you define. AI_FILTER returns True or False, so you can use it in SELECT, WHERE or JOIN … ON clauses. AI_EXTRACT pulls information out of text, images and documents. The others are AI_SENTIMENT, AI_TRANSLATE, AI_REDACT (removes PII), AI_EMBED, AI_SIMILARITY, AI_TRANSCRIBE and AI_PARSE_DOCUMENT. AI_AGG and AI_SUMMARIZE_AGG are aggregates that work across many rows, and they are not subject to context window limits. There are also helper functions: AI_COUNT_TOKENS, TO_FILE and PROMPT.

    These functions are built for throughput, so they suit batch processing over large tables. For interactive work where latency matters, Snowflake points you to the REST API.

    Checkpoint 2 of 7· Match them up

    Match each AI function to the task it fits

    Tap a term, then the definition that fits it.

    Sources2

    3.User-defined functions (UDFs)

    When no built-in function does what you need, or your organisation wants a standard calculation in one place, write a UDF. You call it the same way as a built-in function. You choose a variation based on what goes in and what comes out, and you write the logic, called the handler, in one of the supported languages.

    UDF variations, and handler languages compared by handler location and sharability
    ItemWhat it means
    UDF (scalar)One output row, with a single value, per input row
    UDAFAggregates values across multiple rows
    UDTFReturns a tabular value for each input row
    Vectorized UDF / UDTFReceive batches of rows as Pandas DataFrames
    SQL, JavaScript handlersIn-line only; sharable
    Java, Python, Scala handlersIn-line or staged; not sharable
    A Python scalar UDF with an in-line handlersql
    CREATE OR REPLACE FUNCTION addone(i INT)
      RETURNS INT
      LANGUAGE PYTHON
      RUNTIME_VERSION = '3.12'
      HANDLER = 'addone_py'
    AS $$
    def addone_py(i):
     return i+1
    $$;

    A few behaviours to remember. UDTFs can process staged files in parallel, but UDFs currently process them one at a time. A query that reads staged files through a UDF fails if the same statement also queries a view that calls any UDF or UDTF. If a handler calls CURRENT_DATABASE or CURRENT_SCHEMA, it gets the database or schema that contains the UDF, not the one the session is using.

    Checkpoint 3 of 7· Check yourself

    A provider wants to share a custom function with consumers through Secure Data Sharing. Which handler language works?

    Sources3

    4.ML functions: Classification, Top Insights, Anomaly Detection

    ML functions let you train a model on your own data without being a machine learning expert, because Snowflake chooses the type of model for each feature. They are SQL classes. You create an instance, which is a schema-level object, and then call that instance's methods with the ! syntax. ML functions incur compute and storage costs. The storage reflects the model instances created during training, so deleting unused models reduces it. Top Insights is the exception on storage: its instances store no data and have a negligible effect on storage costs, though it still uses compute.

    Anomaly Detection works on time series. It flags metric values that differ from what is expected. Classification sorts rows into two or more classes. Models are immutable, so to retrain you replace the model (CREATE OR REPLACE), and the target column can have at most 255 distinct classes. Top Insights does key driver analysis. It needs a Boolean label column that separates the control group (FALSE) from the test group (TRUE). It returns the segments that explain the change in a metric, with CONTRIBUTION, RELATIVE_CONTRIBUTION and GROWTH_RATE columns. The instance holds no state, so one instance is enough.

    The three ML functions this objective names
    FunctionQuestion it answersCreateUse
    ClassificationWhich class does this row belong to?CREATE SNOWFLAKE.ML.CLASSIFICATION<model_name>!PREDICT
    Top InsightsWhich dimensions drove the change in a metric?CREATE SNOWFLAKE.ML.TOP_INSIGHTS<instance_name>!GET_DRIVERS
    Anomaly DetectionWhich metric values are outliers over time?CREATE SNOWFLAKE.ML.ANOMALY_DETECTION<model_name>!DETECT_ANOMALIES

    Anomaly Detection in more detail. Training takes a reference to the training data (INPUT_DATA, a table, a view or a query, passed with TABLE(...), SYSTEM$REFERENCE or SYSTEM$QUERY_REFERENCE), a TIMESTAMP_COLNAME (TIMESTAMP_NTZ), a TARGET_COLNAME (the NUMERIC or FLOAT metric to analyse) and a LABEL_COLNAME. The label column holds Boolean values saying whether a row is a known anomaly. If you have no labelled data, pass an empty string, which gives unsupervised training. Supplying labels gives the supervised, labelled approach. SERIES_COLNAME is optional and identifies each series when you have several. You need at least 2 data points to train, at least 12 for non-naive results and at least 60 for non-linear results.

    You then call <model_name>!DETECT_ANOMALIES with INPUT_DATA, TIMESTAMP_COLNAME and TARGET_COLNAME. SERIES_COLNAME and CONFIG_OBJECT are optional, and the columns must match those used in training. The timestamps in the data to analyse must chronologically follow the training timestamps, without too large a gap. The method returns a table that labels each row as anomalous or not, with the columns SERIES, TS, Y, FORECAST, LOWER_BOUND, UPPER_BOUND, IS_ANOMALY, PERCENTILE and DISTANCE. In CONFIG_OBJECT, prediction_interval defaults to 0.99. Because the method returns a table, you can also select columns from it by calling it inside TABLE(...) in a FROM clause. Models cannot be updated in place, so you delete and retrain.

    Training an Anomaly Detection model on a view, with no labelssql
    CREATE OR REPLACE SNOWFLAKE.ML.ANOMALY_DETECTION sensor_model(
      INPUT_DATA => SYSTEM$REFERENCE('VIEW', 'sensor_data_view'),
      TIMESTAMP_COLNAME => 'timestamp',
      TARGET_COLNAME => 'temperature',
      LABEL_COLNAME => '');
    Detecting anomalies in newer rows with the trained modelsql
    CALL sensor_model!DETECT_ANOMALIES(
      INPUT_DATA => SYSTEM$REFERENCE('TABLE', 'sensor_data_device3'),
      TIMESTAMP_COLNAME => 'timestamp',
      TARGET_COLNAME => 'temperature'
    );
    Training a binary Classification model from a view referencesql
    CREATE OR REPLACE SNOWFLAKE.ML.CLASSIFICATION model_binary(
        INPUT_DATA => SYSTEM$REFERENCE('view', 'binary_classification_view'),
        TARGET_COLNAME => 'label'
    );

    For Classification, every column not named as the target is a feature. Feature columns must be STRING, NUMERIC or BOOLEAN. STRING and BOOLEAN features are treated as categorical and NUMERIC ones as continuous, so cast a number to STRING to make it categorical. PREDICT takes an INPUT_DATA object of feature names and values, and returns the predicted class (the label with the highest probability), a probability object with a probability for each class, and LOGS with any error or warning messages. To evaluate a model, call SHOW_EVALUATION_METRICS, SHOW_GLOBAL_EVALUATION_METRICS, SHOW_THRESHOLD_METRICS and SHOW_CONFUSION_MATRIX. SHOW_FEATURE_IMPORTANCE ranks the features, and SHOW_TRAINING_LOGS shows the training logs.

    Running PREDICT over a table, using wildcard expansionsql
    SELECT model_binary!PREDICT(INPUT_DATA => {*}) as prediction from prediction_purchase_data;
    Calling Top Insights on a labelled table (the capitalisation of METRIC_COLNAMe is exactly as the docs print it; the argument names the metric column)sql
    CALL my_insights!get_drivers (
      INPUT_DATA => TABLE(my_table),
      LABEL_COLNAME => 'label',
      METRIC_COLNAMe => 'sales');

    Checkpoint 4 of 7· Check yourself

    You want Top Insights to explain why this month's revenue differs from earlier months. What must the data you pass to GET_DRIVERS contain?

    Checkpoint 5 of 7· Check yourself

    A trained Classification model needs new training data added. What should you do?

    Sources45678910

    5.Review: NULLs in aggregates and table functions

    These two practice questions are about general function behaviour, not about AI or ML functions.

    NULLs in aggregates. Some aggregate functions ignore NULL values. AVG of 1, 5 and NULL is 3, because only the two non-NULL values count in both the numerator and the denominator. If every value passed to an aggregate is NULL, the aggregate returns NULL. When an aggregate such as COUNT is passed more than one column, it ignores a row if any of those columns is NULL.

    Table functions. A table function returns a set of rows for each input row, and you use it in the FROM clause. FLATTEN is a built-in table function for semi-structured data. Snowflake requires the table function call to be wrapped in the TABLE() keyword, and the arguments can be columns from a table that comes earlier in the FROM clause.

    Checkpoint 6 of 7· Exam question

    A finance dashboard reads table `payments` where some rows have a NULL `amount` because the charge is still pending. The business wants the average ticket to treat pending payments as zero, and also a count of payments that already have a recorded amount. Select TWO expressions that together meet both requirements.(Select 2)

    Checkpoint 7 of 7· Exam question

    A table `events` has a VARIANT column `payload` whose `items` key holds an array of objects, each with `sku` and `qty`. An analyst must return one output row per array element together with the parent `event_id`. Which approach does this?

    Sources1112

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.Any UDF can be shared with consumers, whatever language its handler is written in.Why is that wrong?

      Only UDFs with SQL or JavaScript handlers are sharable. Java, Python and Scala UDFs are not.

      Covered in User-defined functions (UDFs)

    2. 2.All Snowflake ML functions need time-series data.Why is that wrong?

      Anomaly Detection (and Forecasting) are time-series functions. Classification and Top Insights work without time-series data.

      Covered in ML functions: Classification, Top Insights, Anomaly Detection

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Geospatial functions operate on GEOGRAPHY and GEOMETRY and convert GEOGRAPHY and GEOMETRY values to and from other representations (such as VARCHAR).”
      ↩︎ Geospatial functions
    2. 2.
      “To call any of these functions, your role needs the USE AI FUNCTIONS account-level privilege and one of the CORTEX_USER or AI_FUNCTIONS_USER database roles.”
      ↩︎ Cortex AI functions
      “Batch processing is typically better suited for AI Functions.”
      ↩︎ Cortex AI functions
      “AI_AGG: Aggregates a text column and returns insights across multiple rows based on a user-defined prompt.”
      ↩︎ Checkpoint
    3. 3.
      “to extend the system to perform operations that are not available through the built-in system-defined functions”
      ↩︎ User-defined functions (UDFs)
      “UDTFs can process multiple files in parallel; however, UDFs currently process files serially.”
      ↩︎ User-defined functions (UDFs)
      “A sharable UDF can be used with the Snowflake Secure Data Sharing feature.”
      ↩︎ Exam trap 1
      “A sharable UDF can be used with the Snowflake Secure Data Sharing feature.”
      ↩︎ Checkpoint
    4. 4.
      “Classification sort rows into two or more classes based on their most predictive features.”
      ↩︎ ML functions: Classification, Top Insights, Anomaly Detection
      “Anomaly Detection flags metric values that differ from typical expectations.”
      ↩︎ ML functions: Classification, Top Insights, Anomaly Detection
      “These features don’t require time series data.”
      ↩︎ Exam trap 2
    5. 5.
      “A Top Insights model is a schema-level object. You only need one instance, since the instance does not hold any state.”
      ↩︎ ML functions: Classification, Top Insights, Anomaly Detection
      “a Boolean label column that distinguishes rows that are part of the control group (labeled FALSE) from rows in the test group (labeled TRUE)”
      ↩︎ ML functions: Classification, Top Insights, Anomaly Detection
      “they do not store any data and have negligible impact on storage costs”
      ↩︎ ML functions: Classification, Top Insights, Anomaly Detection
    6. 6.
      “You use CREATE SNOWFLAKE.ML.ANOMALY_DETECTION to create and train a detection model, and then use the <model_name>!DETECT_ANOMALIES method to detect anomalies.”
      ↩︎ ML functions: Classification, Top Insights, Anomaly Detection
      “Anomaly detection allows you to detect outliers in your time series data by using a machine learning algorithm.”
      ↩︎ Prediction
    7. 9.
      “You need at least 2 data points to train a model, at least 12 for non-naive results, and at least 60 for non-linear results.”
      ↩︎ ML functions: Classification, Top Insights, Anomaly Detection
    8. 11.
      “If all of the values passed to the aggregate function are NULL, then the aggregate function returns NULL.”
      ↩︎ Review: NULLs in aggregates and table functions
    9. 12.
      “Snowflake requires that the table function call be wrapped by the TABLE() keyword.”
      ↩︎ Review: NULLs in aggregates and table functions

    Also cited

    Ready to test yourself?

    Practise the 8 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.