Search code examples
azurehadoopapache-pig

Converting Date to week Day name and part of the day


so how do i get this output from pig with the following inputs. which commands should i use

Input:

10/3/2013 1200
10/4/2013 0000

Expected Output:

Monday Morning 
Tuesday Evening

Solution

  • Split the field into 2 fields and then use ToDate for getting the name of the day.For evening and morning,you can check the value and assign.Assuming you have a relation with 1 field

    B = FOREACH A GENERATE STRSPLIT((chararray)A.$0,' ',2);
    C = FOREACH B GENERATE ToString(ToDate(B.$0,'MM/dd/yyyy'), 'E'),(CASE B.$1
                              WHEN '1200' THEN 'Morning' 
                              WHEN '0000' THEN 'Evening'
                              ELSE '' END
                              )