NEW QUESTION 25
Below table temp_data has one column called raw contains JSON data that records temperature for every four hours in the day for the city of Chicago, you are asked to calculate the maximum temperature that was ever recorded for 12:00 PM hour across all the days. Parse the JSON data and use the necessary array function to calculate the max temp.
Table: temp_date
Column: raw
Datatype: string
Expected output: 58
Explanation
Note: This is a difficult question, more likely you may see easier questions similar to this but the more you are prepared for the exam easier it is to pass the exam.
Use this below link to look for more examples, this will definitely help you,
https://docs.databricks.com/optimizations/semi-structured.html
Here is the solution, step by step
Text Description automatically generated
Use this below link to look for more examples, this will definitely help you,
https://docs.databricks.com/optimizations/semi-structured.html
If you want to try this solution use below DDL,
1.create or replace table temp_data
2. as select ‘ {
3. “chicago”:[
4.{“date”:”01-01-2021″,
5.”temp”:[25,28,45,56,39,25]
6.},
7.{“date”:”01-02-2021″,
8.”temp”:[25,28,49,54,38,25]
9.},
10.{“date”:”01-03-2021″,
11.”temp”:[25,28,49,58,38,25]
12. }]
13. }
14. ‘ as raw
15.
16.select array_max(from_json(raw:chicago[*].temp[3],’array<int>’)) from temp_data
17.