按当前日期过滤结果 - Hadoop PIG 中的 2 天
Filter results by Current Date - 2 Days in Hadoop PIG
我在查找结果和正确转换日期和时间时遇到了一些问题。我有一个日期列的文件,我已经将 unix 时间转换为 yyyy mm dd 并且我只想 return 结果大于今天的日期 - 2 天(两天前或更长时间)。在 SQL 中,它只是 current_date - 2 但在 PIG 中,我在复制它时遇到了问题。这是我拥有的:
unixtime 到可读时间的转换:
b = FOREACH a GENERATE ID as id, epochToFormat(TIME_COLUMN, 'yyyy-MM-dd', 'America/Chicago') as time;
b = FILTER b BY id == 123;
b = FILTER b by ToDate(time, 'yyyy-MM-dd') == CurrentTime(-2);
转储 b;
您必须使用 SubtractDuration to get 2 days before the CurrentTime().You will have to specify the duration in ISO-8601 格式。
C = FILTER B BY ToDate(ToString(time,'yyyy-MM-dd'), 'yyyy-MM-dd') > ToDate(ToString(SubtractDuration(CurrentTime(),'P2D'),'yyyy-MM-dd'),yyyy-MM-dd');
我在查找结果和正确转换日期和时间时遇到了一些问题。我有一个日期列的文件,我已经将 unix 时间转换为 yyyy mm dd 并且我只想 return 结果大于今天的日期 - 2 天(两天前或更长时间)。在 SQL 中,它只是 current_date - 2 但在 PIG 中,我在复制它时遇到了问题。这是我拥有的:
unixtime 到可读时间的转换:
b = FOREACH a GENERATE ID as id, epochToFormat(TIME_COLUMN, 'yyyy-MM-dd', 'America/Chicago') as time;
b = FILTER b BY id == 123;
b = FILTER b by ToDate(time, 'yyyy-MM-dd') == CurrentTime(-2);
转储 b;
您必须使用 SubtractDuration to get 2 days before the CurrentTime().You will have to specify the duration in ISO-8601 格式。
C = FILTER B BY ToDate(ToString(time,'yyyy-MM-dd'), 'yyyy-MM-dd') > ToDate(ToString(SubtractDuration(CurrentTime(),'P2D'),'yyyy-MM-dd'),yyyy-MM-dd');