Support Questions

Find answers, ask questions, and share your expertise

How to substractduration of 1min from a ISO time in Pig ?

avatar
Rising Star
 
1 ACCEPTED SOLUTION

avatar
Expert Contributor
all the comments mentioned here are correct,this is small example


emp = load 'data' using PigStorage(',') as (empno,ename ,job,mgr,hiredate ,sal,comm,deptno);
each_date = foreach emp generate ToDate(hiredate,'dd-MMM-yyyy') as mydate;
subt = foreach each_date generate mydate,SubtractDuration(mydate,'PT1M');
dump subt;

View solution in original post

4 REPLIES 4

avatar
Master Mentor

avatar
Master Mentor
@Pradeep Allu

you need to refer to the standard for ISO 8601 to specify duration or period linked Here. For example PT1M is a one-minute duration. Here's the implementation of the function if you need clear understanding. Get to know jodatime java library and Period object to get a handle on this function. Excellent question!

avatar
Expert Contributor
all the comments mentioned here are correct,this is small example


emp = load 'data' using PigStorage(',') as (empno,ename ,job,mgr,hiredate ,sal,comm,deptno);
each_date = foreach emp generate ToDate(hiredate,'dd-MMM-yyyy') as mydate;
subt = foreach each_date generate mydate,SubtractDuration(mydate,'PT1M');
dump subt;

avatar
Expert Contributor

use ISO time pattern instead of dd-MMM-yyyy from my code