DEA-C02 Data Transformation Practice Question
A data engineer is working with a table that has a VARIANT column containing JSON objects. Some objects have a key 'discount' with a numeric value, while others have it as a string, and some lack the key entirely. The engineer needs to produce a numeric column 'discount_amount' where missing keys are treated as 0 and string values are cast to numbers. Which expression correctly achieves this?
⚠ Common exam trap
The trap here is using TO_NUMBER or CAST instead of TRY_TO_NUMBER, which can cause query failures when encountering non-numeric or missing values in semi-structured data.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
COALESCE(TRY_TO_NUMBER(raw:discount), 0)
The correct expression uses TRY_TO_NUMBER to safely convert both numeric and string discount values to a number, returning NULL on failure, which COALESCE then replaces with 0. This handles missing keys and invalid strings without causing errors. The other options either use error-prone functions or unnecessary casting steps, making them less reliable for this transformation.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
COALESCE(TRY_TO_NUMBER(raw:discount), 0)
Why this is correct
This expression uses TRY_TO_NUMBER on the VARIANT value, which attempts to convert it to a number regardless of whether it is stored as a number or a string. If the conversion fails (e.g., missing key or non-numeric string), it returns NULL, and COALESCE replaces it with 0. This directly handles both numeric and string types and missing keys, making it the correct and efficient solution.
- ✗
COALESCE(CAST(raw:discount AS NUMBER), 0)
Why it's wrong here
CAST will also error on invalid conversions, similar to TO_NUMBER. It does not provide the safe error handling of TRY_TO_NUMBER. Additionally, CAST might not handle string representations of numbers as gracefully. For robust transformation of semi-structured data with varying types, TRY_TO_NUMBER is the recommended function.
- ✗
COALESCE(TO_NUMBER(raw:discount), 0)
Why it's wrong here
TO_NUMBER will raise an error if the value cannot be converted, such as when the key is missing or the string is not a valid number. This would cause the query to fail for rows with missing or invalid discounts. TRY_TO_NUMBER is needed to safely handle such cases by returning NULL instead of erroring.
- ✗
COALESCE(TRY_TO_NUMBER(raw:discount::STRING), 0)
Why it's wrong here
This expression attempts to cast the discount to a string first, then to a number. However, if the discount is already numeric, casting to string and then to number is redundant and may cause precision loss. Additionally, TRY_TO_NUMBER on a string that is not a valid number returns NULL, which COALESCE then replaces with 0. But it does not handle numeric values directly efficiently. It works but is not the most direct.
About these practice questions
One of 229 original DEA-C02 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Snowflake exam blueprint
This DEA-C02 practice question is part of Courseiva's free Snowflake certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DEA-C02 exam.