What you will be able to do
- Build GEOGRAPHY or GEOMETRY values and measure distance, containment and intersection with ST_ functions
- Choose the Cortex AI function for a text task and estimate what drives its token cost
- Match a business question to Forecasting, Anomaly Detection, Classification or Top Insights
1.Spatial values and ST_ functions
Snowflake stores locations and shapes in two data types, GEOGRAPHY and GEOMETRY. The geospatial functions, most of them prefixed ST_, build those values, measure them, and test how they relate to each other. The two types answer distance questions differently, and a scenario often hinges on which one is in use. For GEOGRAPHY, ST_DISTANCE returns the great-circle distance in meters. For GEOMETRY, it returns the Euclidean distance in whatever units the coordinates were defined in. It raises an error if two GEOMETRY inputs have different SRIDs.
WITH d AS
( ST_DISTANCE(ST_MAKEPOINT(0, 0), ST_MAKEPOINT(1, 0)) )
SELECT d / 1000 AS kilometers, d / 1609 AS miles;Some functions work with only one of the two types, so pick the constructor that matches the type you need. ST_MAKEPOINT builds a GEOGRAPHY point, and ST_MAKEGEOMPOINT builds a GEOMETRY point. To parse stored text or binary, use TO_GEOGRAPHY or ST_GEOGRAPHYFROMWKT. The TRY_ variants work the same way when the source data may be malformed. Once you have values, the relationship functions answer the usual business questions.
| Question | Function | Type support |
|---|---|---|
| Build a point from coordinates | ST_MAKEPOINT / ST_MAKEGEOMPOINT | GEOGRAPHY / GEOMETRY |
| Parse WKT text into a shape | ST_GEOGRAPHYFROMWKT, TO_GEOGRAPHY | GEOGRAPHY |
| How far apart are two shapes? | ST_DISTANCE | Both |
| Are they within a given distance? | ST_DWITHIN | GEOGRAPHY only |
| Does one shape contain the other? | ST_CONTAINS, ST_WITHIN, ST_COVERS | Both |
| Do two shapes overlap at all? | ST_INTERSECTS | Both |
| Size of a polygon or line | ST_AREA, ST_LENGTH, ST_PERIMETER | Both |
| Bucket points into hexagonal cells | H3_POINT_TO_CELL | GEOGRAPHY only |
Most ST_ functions are scalar and return one value per row. ST_COLLECT, ST_UNION_AGG and ST_INTERSECTION_AGG also have aggregate forms, which combine the shapes from many rows into a single value.
Checkpoint 1 of 5· Check yourself
A table holds customer and store locations as GEOGRAPHY points. You want a TRUE/FALSE flag for whether a store lies within 500 meters of a customer. Which function fits?
ST_DWITHIN takes two GEOGRAPHY values and a distance in meters and returns a BOOLEAN. ST_CONTAINS tests containment of one shape in another, and ST_AREA measures a polygon.
“Returns TRUE if the minimum great circle distance between two points (two GEOGRAPHY objects) is within the specified distance.”Source: docs.snowflake.com
2.Cortex AI functions on text columns
Cortex AI functions run large language models from inside a SQL statement, so you can score, translate or summarize a text column without moving the data out of Snowflake. To call them, a role needs the USE AI FUNCTIONS account-level privilege and either the CORTEX_USER or the AI_FUNCTIONS_USER database role. Most of them work like scalar functions, returning one result per row. AI_AGG and AI_SUMMARIZE_AGG are aggregates: they read many rows and return one result, and they aren't limited by the model's context window.
| Task on a text column | Function |
|---|---|
| Score how positive or negative each review is | AI_SENTIMENT |
| Shorten each document | AI_SUMMARIZE |
| One summary across all tickets | AI_SUMMARIZE_AGG |
| Translate each message | AI_TRANSLATE |
| Assign each row one of your own labels | AI_CLASSIFY |
| Pull named fields out of text or files | AI_EXTRACT |
| Keep only rows that meet a plain-language condition | AI_FILTER |
| Mask PII | AI_REDACT |
| Any other generative prompt | AI_COMPLETE |
AI_FILTER returns TRUE or FALSE, so you can use it in a WHERE clause or a JOIN … ON condition. AI_COMPLETE takes the model name as its first argument, and each model in a query shows up on its own row in the usage history.
SELECT AI_COMPLETE('mistral-7b', 'Is a hot dog a sandwich'), AI_COMPLETE('mistral-large', 'Is a hot dog a sandwich');Cost depends on tokens, and a token is roughly four characters of text. Functions that generate text, such as AI_COMPLETE, AI_SUMMARIZE and AI_TRANSLATE, bill both input and output tokens. The task-specific functions also add a hidden prompt to your text, so you're billed for more tokens than you supplied. You also keep paying for the warehouse while the query runs. A larger warehouse doesn't make these calls faster, so Snowflake recommends nothing larger than MEDIUM. To check a prompt's size before a large run, use AI_COUNT_TOKENS. To see where credits went, query CORTEX_FUNCTIONS_USAGE_HISTORY in ACCOUNT_USAGE.
Checkpoint 2 of 5· Check yourself
A support team wants a single summary drawn from tens of thousands of ticket rows, and the combined text is far larger than a model's context window. Which function suits this?
AI_SUMMARIZE_AGG aggregates a text column into one summary across rows, and it is not limited by the context window. AI_SUMMARIZE returns one summary per row.
“Aggregates a text column and returns a summary across multiple rows. This function isn’t subject to context window limitations.”Source: docs.snowflake.com
3.Choosing an ML function for the question
Snowflake's ML functions train a model on your data and return predictions or insights. Snowflake picks a suitable type of model for each feature, so you don't need to be a machine-learning expert. The deciding factor is the question being asked. Two of the features work on time series and learn how a metric changes over time. The other two don't need time-series data.
| Question | ML function | Needs time-series data |
|---|---|---|
| What will next quarter's sales be? | Forecasting | Yes |
| Which daily values look unusual? | Anomaly Detection | Yes |
| Which category will this customer fall into? | Classification | No |
| Which segments drove the change in the metric? | Top Insights | No |
Forecasting projects future metric values from past trends. Anomaly Detection flags values that differ from what the model expects. Classification sorts rows into two or more classes using their most predictive features. Top Insights finds the dimensions and values that affect a metric in surprising ways, which makes it the answer to 'why did revenue drop in March?'
ML Classification and AI_CLASSIFY both produce labels, but they work differently. Classification trains a model on the features in your rows. AI_CLASSIFY asks a language model to put text or images into categories you name. ML functions cost both storage and compute: storage for the model instances created during training, and compute that grows with the amount of data used to train and predict.
Checkpoint 3 of 5· Exam question
An analyst queries a table orders (customer_id, order_id, order_ts, amount) and needs exactly one row per customer: the most recent order. The team wants a single query block with no subquery or CTE. Which change achieves this?
Correct answer: A — Append QUALIFY ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_ts DESC) = 1 to the query so the window result filters rows after evaluation.
- A. Correct: QUALIFY filters on window function results after they are computed, so ROW_NUMBER() = 1 per customer partition keeps the latest order without a subquery or CTE.
- B. Incorrect: window functions are not allowed in the WHERE clause because WHERE is evaluated before windows are computed, so the query fails with an error.
- C. Incorrect:
order_tsis neither grouped nor aggregated in the SELECT list, so the query is invalid, and even a valid form would drop the other columns of the latest row. - D. Incorrect:
DISTINCT ONis PostgreSQL syntax and Snowflake does not support it, so the statement fails to parse. Snowflake uses QUALIFY with ROW_NUMBER for this pattern.
Checkpoint 4 of 5· 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)
Correct answers: A, B — Use AVG(COALESCE(amount, 0)) so that pending rows enter the denominator with a value of zero instead of being skipped by the aggregate.; Use COUNT(amount) so that only rows holding a non-NULL amount are counted, which excludes the pending payments from the tally.
- A. Correct: COALESCE replaces NULL with 0 before AVG runs, so pending rows count in the denominator as zero, which is exactly the requested treatment.
- B. Correct: COUNT with a column argument counts only non-NULL values, so it returns the number of payments that have a recorded amount.
- C. Incorrect: AVG ignores NULL inputs, so pending rows are excluded from both sum and denominator and the average is higher than the business wants.
- D. Incorrect: COUNT(*) counts every row including those with a NULL amount, so it does not isolate payments with a recorded amount.
- E. Incorrect: SUM ignores NULLs and COUNT(amount) skips them, so this ratio equals a plain AVG(amount) and never treats pending payments as zero.
Checkpoint 5 of 5· 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?
Correct answer: A — Join with LATERAL FLATTEN(input => e.payload:items) f and read f.value:sku::STRING and f.value:qty::NUMBER for each element row.
- A. Correct: FLATTEN is a table function, and LATERAL lets it reference the outer row, producing one row per array element with
valueholding each object. - B. Incorrect: PARSE_JSON converts a string into a VARIANT but returns a single value per input row, so the array is not expanded into separate rows.
- C. Incorrect: ARRAY_SIZE is a scalar function that returns the number of elements as one number per row, and it cannot be used in FROM to produce rows.
- D. Incorrect: SPLIT_TO_TABLE splits a string on a delimiter, so it is meant for text and does not iterate the elements of a VARIANT array of objects.
Sources5
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Geospatial functions operate on GEOGRAPHY and GEOMETRY and convert GEOGRAPHY and GEOMETRY values to and from other representations (such as VARCHAR).”
↩︎ Spatial values and ST_ functions - 2.
“Returns the minimum great circle distance between two GEOGRAPHY or the minimum Euclidean distance between two GEOMETRY objects.”
↩︎ Spatial values and ST_ functions“For GEOGRAPHY input values, the distance is in meters.”
↩︎ Spatial values and ST_ functions“For GEOMETRY input values, the distance is computed with the same units used to define the input coordinates.”
↩︎ Exam trap 1 - 3.
“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 on text columns“AI_SUMMARIZE_AGG: Aggregates a text column and returns a summary across multiple rows.”
↩︎ Cortex AI functions on text columns“Cortex AI Functions are optimized for throughput.”
↩︎ Cortex AI functions on text columns“Aggregates a text column and returns a summary across multiple rows. This function isn’t subject to context window limitations.”
↩︎ Checkpoint - 4.
“Snowflake Cortex AI functions incur compute cost based on the number of tokens processed.”
↩︎ Cortex AI functions on text columns“As a result, the billed token count is higher than the number of tokens in the text you provide.”
↩︎ Cortex AI functions on text columns“Snowflake recommends using a warehouse size no larger than MEDIUM when calling Snowflake Cortex AI Functions.”
↩︎ Cortex AI functions on text columns“Using a larger warehouse than necessary does not increase performance, but can result in unnecessary costs.”
↩︎ Exam trap 2“AI_CLASSIFY labels, descriptions, and examples are counted as input tokens for each record processed, not just once for each AI_CLASSIFY call.”
↩︎ Prediction - 5.
“Forecasting predicts future metric values from past trends in time-series data.”
↩︎ Choosing an ML function for the question“Anomaly Detection flags metric values that differ from typical expectations.”
↩︎ Choosing an ML function for the question“Classification sort rows into two or more classes based on their most predictive features.”
↩︎ Choosing an ML function for the question“The storage costs you incur reflect storage of the ML model instances created during the training step.”
↩︎ Choosing an ML function for the question“Top Insights helps you find dimensions and values that affect the metric in surprising ways.”
↩︎ Exam trap 3
Also cited
“Returns TRUE if the minimum great circle distance between two points (two GEOGRAPHY objects) is within the specified distance.”
↩︎ Checkpoint