
Ultimate access to all questions.
A data engineer needs to apply custom logic to identify employees with more than 5 years of experience in array column employees in table stores. The custom logic should create a new column exp_employees that is an array of all of the employees with more than 5 years of experience for each row. In order to apply this custom logic at scale, the data engineer wants to use the FILTER higher-order function.
Which of the following code blocks successfully completes this task?
A
SELECT
store_id,
employees,
FILTER (employees, i -> i.years_exp > 5) AS exp_employees
FROM stores;
SELECT
store_id,
employees,
FILTER (employees, i -> i.years_exp > 5) AS exp_employees
FROM stores;
B
SELECT
store_id,
employees,
FILTER (exp_employees, years_exp > 5) AS exp_employees
FROM stores;
SELECT
store_id,
employees,
FILTER (exp_employees, years_exp > 5) AS exp_employees
FROM stores;
C
(Incomplete — no code provided)
Explanation:
Option A is correct because it properly uses the FILTER higher-order function with the correct syntax:
FILTER(array, lambda_function) where the lambda function takes each element of the array and returns a boolean.i -> i.years_exp > 5 - This correctly references the array element i and accesses its years_exp field.employees array to create a new array exp_employees containing only employees with more than 5 years of experience.Option B is incorrect because:
exp_employees which doesn't exist yet (it's being created in the same expression).Key concepts:
i) represents each element in the array.i.years_exp).