Challenge - 5 Problems
UDF Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple UDF in Hive
Consider this Hive UDF written in Java. What will be the output when the UDF is applied to the input string
"hadoop"?Hadoop
public class ReverseStringUDF extends org.apache.hadoop.hive.ql.exec.UDF { public String evaluate(String input) { if (input == null) return null; return new StringBuilder(input).reverse().toString(); } } -- Hive query: SELECT ReverseStringUDF('hadoop');
Attempts:
2 left
💡 Hint
Think about what the StringBuilder.reverse() method does to the input string.
✗ Incorrect
The UDF reverses the input string. 'hadoop' reversed is 'poodah'.
❓ data_output
intermediate2:00remaining
Result of applying a UDF to a Hive table column
Given a Hive table
users with a column username, and a UDF ToUpperCaseUDF that converts strings to uppercase, what is the output of this query?Hadoop
SELECT username, ToUpperCaseUDF(username) AS username_upper FROM users WHERE username = 'alice';Attempts:
2 left
💡 Hint
The UDF changes the case but does not filter rows.
✗ Incorrect
The query selects the row where username is 'alice' and applies the UDF to convert it to uppercase, resulting in 'ALICE'.
🔧 Debug
advanced2:00remaining
Identify the error in this UDF code
This Java UDF code is intended to return the length of a string. What error will it cause when compiled or run?
Hadoop
public class StringLengthUDF extends org.apache.hadoop.hive.ql.exec.UDF { public int evaluate(String input) { return input.length(); } }
Attempts:
2 left
💡 Hint
What happens if the input string is null and you call length()?
✗ Incorrect
If the input is null, calling input.length() causes a NullPointerException at runtime.
🧠 Conceptual
advanced2:00remaining
Understanding UDF registration in Hive
Which statement correctly describes how to register a Java UDF in Hive before using it in queries?
Attempts:
2 left
💡 Hint
Think about how Hive loads external code and links it to a function name.
✗ Incorrect
In Hive, you first add the JAR containing the UDF with ADD JAR, then create the function with CREATE FUNCTION referencing the class.
🚀 Application
expert2:00remaining
Predict output of a complex UDF with multiple inputs
Given this UDF that concatenates two strings with a dash, what is the output of the Hive query?
Hadoop
public class ConcatDashUDF extends org.apache.hadoop.hive.ql.exec.UDF { public String evaluate(String s1, String s2) { if (s1 == null) s1 = ""; if (s2 == null) s2 = ""; return s1 + "-" + s2; } } -- Hive query: SELECT ConcatDashUDF('data', NULL);
Attempts:
2 left
💡 Hint
Check how the UDF handles null inputs before concatenation.
✗ Incorrect
The UDF replaces null inputs with empty strings, so the output is 'data-' when second input is null.