Databricks-Spark-Assoc Using Spark SQL Practice Question
A developer is working with a Spark SQL DataFrame that contains a column 'tags' which is an array of strings. The developer needs to filter rows where the array contains the string 'spark' and also transform the array to uppercase. Which TWO Spark SQL functions should be used to achieve these requirements? (Choose two.)
⚠ Common exam trap
It's easy for candidates to confuse element-level filtering within an array (using filter) with row-level filtering based on array contents (using array_contains).
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
✓
array_contains(tags, 'spark')
To filter rows where the array contains 'spark', array_contains is the direct and efficient function. To transform each element of the array to uppercase, transform with a lambda using upper is the correct approach. Together, they satisfy both requirements without altering the DataFrame's structure.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
upper(tags)
Why it's wrong here
The upper function operates on a string, not an array. Applying it to an array column would result in an error or unexpected behavior. To uppercase each element in an array, you need a higher-order function like transform. Thus, this option is incorrect.
- ✓
array_contains(tags, 'spark')
Why this is correct
The array_contains function checks if a given value exists in an array. It returns a boolean, which can be used in a filter condition. This directly addresses the requirement to filter rows where the array contains 'spark'. It is the standard function for this purpose in Spark SQL.
- ✓
transform(tags, x -> upper(x))
Why this is correct
The transform function applies a lambda function to each element of an array, returning a new array. Using upper(x) converts each string to uppercase. This meets the requirement to transform the array to uppercase. It is a higher-order function available in Spark SQL 2.4+ and is efficient for such transformations.
- ✗
filter(tags, x -> x = 'spark')
Why it's wrong here
The filter function returns a new array containing only elements that satisfy the predicate. While it can be used to check for presence by checking if the resulting array is not empty, it is not the direct function for filtering rows based on array containment. The requirement is to filter rows, not to filter elements within the array. Using array_contains is more straightforward and efficient.
- ✗
explode(tags)
Why it's wrong here
The explode function creates a new row for each element in the array, which changes the granularity of the DataFrame. This is not suitable for filtering rows while preserving the original row structure. It would result in multiple rows per original row, complicating further transformations. Therefore, it is not appropriate for this scenario.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
About these practice questions
Courseiva writes every Databricks-Spark-Assoc question from scratch — 295 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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 Databricks exam blueprint
This Databricks-Spark-Assoc practice question is part of Courseiva's free Databricks 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 Databricks-Spark-Assoc exam.