
Ultimate access to all questions.
Deep dive into the quiz with AI chat providers.
We prepare a focused prompt with your quiz and certificate details so each AI can offer a more tailored, in-depth explanation.
A data engineer needs to apply custom logic to string column city in table stores for a specific use case. In order to apply this custom logic at scale, the data engineer wants to create a SQL user-defined function (UDF). Which of the following code blocks creates this SQL UDF?
A
CREATE FUNCTION combine_nyc(city STRING)
RETURNS STRING
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
CREATE FUNCTION combine_nyc(city STRING)
RETURNS STRING
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
B
CREATE UDF combine_nyc(city STRING)
RETURNS STRING
CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
CREATE UDF combine_nyc(city STRING)
RETURNS STRING
CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
C
CREATE UDF combine_nyc(city STRING)
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
CREATE UDF combine_nyc(city STRING)
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
D
(No code provided)
Explanation:
The correct answer is Option A.
CREATE FUNCTION syntax, not CREATE UDF.CREATE FUNCTION statementcombine_nyc(city STRING)RETURNS STRINGRETURN keyword before the CASE expressionCREATE UDF instead of CREATE FUNCTION, which is not valid SQL syntax in Databricks.CREATE UDF and also misses the RETURNS STRING clause and the RETURN keyword before the CASE expression.CREATE FUNCTION statementRETURNSRETURN keyword before the function body