Generation formatting date

In Pig, I have a statement that basically adds a date to my generated values.

Data = FOREACH Input GENERATE (CurrentTime()),FLATTEN(group), COUNT(guid)oas Cnt; 

The output gives me the date 2013-05-25T09:01:38.914-04:00 in ISO8601.

How can I do this as "YYYY-MM-DD" ?

+4
source share
2 answers

You have several options:

Convert it using Pig functions:
eg:

 A = load ... B = foreach A { currTime = CurrentTime(); year = (chararray)GetYear(currTime); month = (chararray)GetMonth(currTime); day = (chararray)GetDay(currTime); generate CONCAT(CONCAT(CONCAT(year, '-'), CONCAT(month, '-')),day) as myDate; } 

OR pass the date to the script as a parameter:

 pig -f script.pig -param CURR_DATE=`date +%Y-%m-%d` 

OR declare it in a script:

 %declare CURR_DATE `date +%Y-%m-%d`; 

Then refer to the variable as '$CURR_DATE' in the script.

You can also create a modified CurrentTime UDF in which you convert the DateTime object to the appropriate format using the Joda-Time library.

The easiest way would be to declare a date at the beginning of the script.

+13
source

If you use Pig 0.12 or later, you can use ToString (CurrentTime (), 'YYYY-MM-dd')

You can use any type of datetime instead of CurrentTime ()

See http://pig.apache.org/docs/r0.12.0/func.html#to-string for the date format.

+11
source

Source: https://habr.com/ru/post/1482714/


All Articles