Pig - How to manipulate and compare dates?

余生颓废 提交于 2019-12-08 08:14:28
SNeumann

No need to write a custom function:

In Pig 0.11 you can convert the date2 field from chararray to datetime data type using the ToDate() function, and then get the difference between the CurrentTime() and date2 using YearsBetween() and filter according to it. for example:

g = FILTER f BY YearsBetween(CurrentTime(),ToDate(date2 + ' 01', 'yyyy MM dd'))<3

in pig 11, is there a support for comparing datetime types? for example: date1:datetime

and filter has condition: date1 >= ToDate('1999-01-01')

does this comparison returns correct result?

If you are stuck on Pig older than .11, use datafu. They have a function UnixToIso

DEFINE UnixToISO   org.apache.pig.piggybank.evaluation.datetime.convert.UnixToISO();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!