Databricks Data Engineer Professional · Section 3 · 12% of the exam
Develop a model and query semi-structured data using the VARIANT data type and related functions (e.g., parse_json, variant_get).
One of the objectives of the Databricks Certified Data Engineer Professional exam, in the section “Data Manipulation”. Here is what it covers, the points to remember and a question to try.
What it covers
Use the VARIANT type to store JSON-like data without a fixed schema and query it fast: create values with parse_json, extract and cast with the : path syntax and variant_get, flatten with variant_explode, ingest straight into VARIANT, and design hybrid tables that rely on shredding for performance.
Points to remember
- VARIANT stores JSON-shaped data in a binary encoding with no schema; GA since July 2026 (type available from DBR 15.3, use 15.4 LTS+).
- Model hybrid tables: typed columns for filter, join and cluster keys; a VARIANT column for the long tail.
parse_jsonerrors on malformed input;try_parse_jsonreturns NULL;to_variant_objectconverts STRUCT and MAP.v:a.b[0]returns VARIANT; cast with::type.variant_get(v, '$.a.b', 'type')is the function form.- Missing path returns NULL; impossible cast raises INVALID_VARIANT_CAST;
try_variant_getreturns NULL instead.
Try a question
Each checkout event in prod.silver.events stores its basket in the VARIANT column attrs as an array items of objects with sku and qty fields. Analysts need one row per item with event_id, sku and qty. Which query returns that?
- A
SELECT e.event_id, i.value:sku::STRING, i.value:qty::INT FROM prod.silver.events e, LATERAL variant_explode(e.attrs:items) AS i - B
SELECT event_id, attrs:items[*].sku::STRING AS sku, attrs:items[*].qty::INT AS qty FROM prod.silver.events - C
SELECT event_id, explode(attrs:items) AS item FROM prod.silver.events, then readitem.skuanditem.qty - D
SELECT event_id, variant_get(attrs, '$.items', 'STRING') AS items FROM prod.silver.events
Show the answer
A. variant_explode is a table-valued function, called with LATERAL, that returns one row per array element or object field, with pos, key and value columns; value is still VARIANT, so cast the extracted fields. Exploding changes the grain to one row per item.
Written for practice in the style of the exam: never a question from the real exam.
In the course
The lesson Modeling and Querying Semi-Structured Data with VARIANT teaches this objective (about 45 minutes), and 12 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.
More in this section
- Apply advanced data transformations, including window functions, joins, and aggregations, using Spark SQL and PySpark to process large datasets.
- Apply AI functions, including ai_query, to perform model inference within data pipelines for enrichment and classification tasks.
- Implement data quality expectations in Lakeflow Pipelines to quarantine, drop, or fail on bad records.