Database Reference
In-Depth Information
Figure 9.8 Reformatted date/times
Now that you have the dates in ISO format, you can easily strip out the day
and hour from the date. Use the following code to create the day and hour
fields. The output should match Figure 9.9 :
REGISTER
'C:\hdp\hadoop\pig-0.11.0.1.3.0.0-0380\piggybank.jar';
REGISTER
'C:\hdp\hadoop\pig-0.11.0.1.3.0.0-0380\joda-time-2.2.jar';
DEFINE Convert
org.apache.pig.piggybank.evaluation.datetime.convert.CustomFormatToISO;
DEFINE SubString
org.apache.pig.piggybank.evaluation.string.SUBSTRING;
SpeedData = LOAD '/user/test/trafic.txt' using
PigStorage()
AS (dtstamp:chararray, sensorid:int, speed:double);
SpeedDataFormat = FOREACH SpeedData Generate dtstamp,
Convert(dtstamp,'MM/dd/YYYY hh:mm:ss a') as dtISO,
speed;
SpeedDataHour = FOREACH SpeedDataFormat
Generate dtstamp, SubString(dtISO,5,7) as day,
SubString(dtISO,11,13) as hr, speed;
Dump SpeedDataHour;
 
 
Search WWH ::




Custom Search