Skip to content
GoldNEW 6 min read 2 practice problems ↓

The VARIANT type

Store and query semi-structured JSON efficiently without declaring a schema up front.

Step 2 · Spark internals · Gold · Spark 4, lesson 3 of 5

Read first: ANSI mode by default (skip if you know it)

In plain words first

A filing box with labelled dividers that adapt to whatever you put in: a receipt, a letter, a photo. You can still find "the amount on the receipt" quickly, without deciding the dividers in advance.

VARIANT is that box for semi-structured data: flexible like a string, but fast to read fields from.

Unlock the full lesson

You have read the free part. The rest of this advanced lesson:

  • The problem
  • Using it
  • How it is stored
  • Where it works
  • When to use which
  • Try it yourself
  • Common mistakes
  • Key takeaways
  • Interview prep with 3 follow-up questions
  • Check yourself: 3 questions

Unlock it with the Complete pass (every advanced problem and lesson) or on its own.

Practise this

Interview problems on spark performance, graded on hidden tests

Keep going

Up next · Spark 4 · lesson 4 of 5 · 5 min read
SQL pipe syntax
Write SQL top to bottom with the |> operator, in the order the query actually runs.

Related lessons

Previous: ANSI mode by default

Primary sources: Spark SQL built-in functions · Parquet variant encoding