apache pig - Human readable String date converted to date using Pig? -
apache pig - Human readable String date converted to date using Pig? -
i have next human readable date formats stored in text file:
wed oct 15 09:26:09 bst 2014 wed oct 15 19:26:09 bst 2014 wed oct 18 08:26:09 bst 2014 wed oct 23 10:26:09 bst 2014 sun oct 05 09:26:09 bst 2014 wed nov 20 19:26:09 bst 2014
how can convert dates using compatible pig's todate() function can utilize gethour(), getyear(), getday() , getmonth() apply date range constraints , logic queries?
1.pig back upwards few formats of date, need convert date , time according 1 of below format. http://docs.oracle.com/javase/6/docs/api/java/text/simpledateformat.html
2.your input has bst timezone in pig bst not supported, need take different timezone equivalent bst. timezones available here http://joda-time.sourceforge.net/timezones.html
examples:
i chosen time format "eee, d mmm yyyy hh:mm:ss z" wed, 4 jul 2001 12:08:56", bcoz matching input data. bst time zone not available, chosen 'gmt' time zone, can alter according need.input.txt
wed oct 15 09:26:09 bst 2014 wed oct 15 19:26:09 bst 2014 wed oct 18 08:26:09 bst 2014 wed oct 23 10:26:09 bst 2014 sun oct 05 09:26:09 bst 2014 wed nov 20 19:26:09 bst 2014
pigscript:
a = load 'input.txt' using pigstorage(' ') as(day:chararray,month:chararray,date:chararray,time:chararray,tzone:chararray,year:chararray); b = foreach generate concat(concat(concat(concat(day,', ',date),' ',month),' ',year),' ',time) mytime; c = foreach b generate todate(mytime,'eee, d mmm yyyy hh:mm:ss','gmt') newtime; d = foreach c generate getmonth(newtime),getday(newtime),getyear(newtime),gethour(newtime),getminute(newtime); dump d;
output:
(10,15,2014,9,26) (10,15,2014,19,26) (10,15,2014,8,26) (10,22,2014,10,26) (10,5,2014,9,26) (11,19,2014,19,26)
apache-pig
Comments
Post a Comment