
Answer-first summary for fast verification
Answer: CREATE FUNCTION custom_logic(city STRING) RETURNS STRING BEGIN RETURN UPPER(city); END;
The correct way to define a SQL user-defined function (UDF) in Databricks is by using the CREATE FUNCTION syntax. Option A follows this syntax correctly by creating a function named custom_logic, taking a string argument city, and returning the uppercase version of the input string. Other options either use incorrect syntax (e.g., CREATE UDF instead of CREATE FUNCTION) or incorrect logic (e.g., RETURNS CASE WHEN).
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
As a data engineer, you are given a table named stores that contains a column named city, which holds string values representing the names of cities. You need to apply some custom logic to the city column as part of a specific data processing use case. To implement this custom logic efficiently across the dataset within Databricks, you want to create a SQL user-defined function (UDF). Which of the following code blocks will allow you to create this SQL UDF?
A
CREATE FUNCTION custom_logic(city STRING) RETURNS STRING BEGIN RETURN UPPER(city); END;
B
CREATE UDF custom_logic(city STRING) RETURNS STRING BEGIN RETURN UPPER(city); END;
C
CREATE FUNCTION UDF custom_logic(city STRING) RETURNS STRING BEGIN RETURN UPPER(city); END;
D
CREATE FUNCTION custom_logic(city STRING) RETURNS CASE WHEN city IS NOT NULL THEN UPPER(city) ELSE city END;
E
CREATE UDF custom_logic(city STRING) RETURNS CASE WHEN city IS NOT NULL THEN UPPER(city) ELSE city END;
No comments yet.