我试图在猪中使用Days Between但我收到错误。
ERROR 1066: Unable to open iterator for alias test
rental = LOAD './rental.csv' USING PigStorage(',') AS (rental_id:int , rental_date:chararray, inventory_id:int , customer_id:int, return_date:chararray,staff_id:int);
test = foreach rental GENERATE rental_id, DaysBetween(ToDate(rental.return_date,'yyyy-MM-dd HH:mm:ss'),
ToDate(rental.rental_date,'yyyy-MM-dd HH:mm:ss'));
dump test;
如果我删除daysBetween函数转储测试将起作用。我找到了很多例子,但它不起作用。
日期格式示例2016-05-24 22:54:33
答案 0 :(得分:0)
投射ToDate的结果,即(日期时间)
test = foreach rental GENERATE rental_id, DaysBetween((datetime)ToDate(rental.return_date,'yyyy-MM-dd HH:mm:ss'),(datetime)ToDate(rental.rental_date,'yyyy-MM-dd HH:mm:ss'));
dump test;
修改强> 它有效,见下文
1,2016-05-24 22:54:33,2015-04-24 22:54:33
2,2016-04-24 22:54:33,2014-03-24 22:54:33
3,2016-03-24 22:54:33,2011-02-24 22:54:33