
Answer-first summary for fast verification
Answer: SELECT key, value:name, value:email, value:country, value:age FROM customers
The correct answer is D because Spark SQL allows direct interaction with JSON data stored as strings using the ':' syntax to navigate nested structures. Options A, B, and E incorrectly attempt to use operators ('*' and '.') that are not applicable to String type columns. Option C is incorrect as the EXPLODE function is only for array or map type columns, not Strings.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
A table named 'customers' was created from a Kafka payload containing binary-encoded JSON values. After converting the 'key' and 'value' columns to String type, the 'value' column contains JSON data but remains as a String type. Which SQL statement correctly accesses the JSON data fields 'name', 'email', 'country', and 'age'?
A
SELECT key, value.* FROM customers
B
SELECT key, value.name, value.email, value.country, value.age FROM customers
C
SELECT key, EXPLODE(value) FROM customers
D
SELECT key, value:name, value:email, value:country, value:age FROM customers
E
SELECT key, value:* FROM customers