°C = (°F - 32) × 5/9. The precipitation type data is an array with zero or more values in lowercase. The data pipeline also utilizes a lambda function to convert the first character of each precipitation type to uppercase. The pipeline uses the metadata filename in the data load as an audit trail.
Retrieve the Weather Data from the Source
Retrieve year-to-date weather data for Chicago in JSON format from the Weather Query Builder. Here is a sample row of data. The data contains:queryCost— Cost of the querylatitude— Latitude of the locationlongitude— Longitude of the locationresolvedAddress— Address of the location with the countryaddress— City and state of the addresstimezone— Time zone of the locationtzoffset— Time zone offsetname— Name of the locationdays— Daily weather data in an array with these fields:datetime— Date of the weather datadatetimeEpoch— Date epoch of the weather datatempmax— Maximum temperature of the daytempmin— Minimum temperature of the daytemp— Temperature of the dayfeelslike— Feels like temperature of the dayhumidity— Humidity for the dayprecip— Precipitation amount for the dayprecipprob— Probability of precipitation for the daypreciptype— Type of precipitation for the day (array of strings for types such as rain, snow, and so on)windspeed— Wind speed for the day
JSON
chicago_weather_ytd table with these columns:
latitude— Latitude of the locationlongitude— Longitude of the locationlocation_name— Name of the locationlog_date— Date of the weather eventtemp— Temperature of the daypreciptype— An array of characters for multiple types of weather eventsfile_name— Name of the file that contains the weather data
SQL
Create a User-Defined Function for Temperature Conversion
Create a user-defined function that converts a degree value from Fahrenheit to Celsius, and round the returned value to one decimal place. Use code to specify the calculation and rounding.SQL
Create a Data Pipeline to Load the Weather Data
Build a pipeline by using a preview of the data to load with thePREVIEW PIPELINE SQL statement to see how a limited number of rows loads. Preview four rows. Specify the JSON format. Transform the latitude and longitude to the double type using the DOUBLE cast function. For the date of the weather of the event log_date, expand the input array of days into its elements using the EXPLODE_OUTER function and convert the date to a date type using the DATE cast function. For the temperature of the day, expand the input array of days into its elements using the EXPLODE_OUTER function and convert the temperature to the double type using the DOUBLE cast function. Execute the f_to_c user-defined function to convert the temperature from Fahrenheit to Celsius. For the type of precipitation, expand the input array of days into its elements using the EXPLODE_OUTER function. Then, transform each element of the input array using a lambda function that converts the first character of the precipitation type to uppercase. Use the METADATA function to capture the filename.
SQL
Text
PREVIEW with the CREATE keyword in the SQL statement.
SQL
Execute the Data Pipeline Load
Start the data pipeline by allowing 100 errors before the pipeline fails. The data pipeline runs to completion.SQL
SHOW PIPELINE_STATUS command to view the status of the data pipeline.
SQL
Text
SQL
Text

