
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 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
SELECT
store_id,
employees,
FILTER (employees, years_exp > 5) AS exp_employees
FROM stores;
SELECT
store_id,
employees,
FILTER (employees, years_exp > 5) AS exp_employees
FROM stores;
D
SELECT
store_id,
employees,
CASE WHEN employees.years_exp > 5 THEN employees
ELSE NULL
END AS exp_employees
FROM stores;
SELECT
store_id,
employees,
CASE WHEN employees.years_exp > 5 THEN employees
ELSE NULL
END AS exp_employees
FROM stores;
E
SELECT
store_id,
employees,
FILTER (exp_employees, i -> i.years_exp > 5) AS exp_employees
FROM stores;
SELECT
store_id,
employees,
FILTER (exp_employees, i -> i.years_exp > 5) AS exp_employees
FROM stores;
Explanation:
Option A is correct because it properly uses the FILTER higher-order function with the correct syntax:
FILTER(array, lambda_function)employees array columni -> i.years_exp > 5 where i represents each element in the array, and i.years_exp accesses the years_exp field of each employee objectWhy other options are incorrect:
exp_employees in the FILTER function before it's created. Also missing the lambda expression syntax.exp_employees before it's created and uses incorrect syntax.Key concepts:
element -> condition