【发布时间】:2015-07-28 11:57:38
【问题描述】:
我有一个用例,我需要输入一个月的日期来返回上个月的最后日期。
Ex: input:20150331 output:20150228
我将使用上个月的最后一个日期来过滤每日分区(在猪脚本中)。
B = filter A by daily_partition == GetPrevMonth(20150331);
我创建了一个 UDF(GetPrevMonth),它获取日期并返回上个月的最后一个日期。但无法在过滤器上使用它。
ERROR:Could not infer the matching function for GetPrevMonth as multiple or none of them fit. Please use an explicit cast.
我的 udf 将元组作为输入。 谷歌搜索它说UDF不能应用于过滤器。 有什么解决方法吗?还是我在某个地方出错了?
UDF:public class GetPrevMonth extends EvalFunc<Integer> {
public Integer exec(Tuple input) throws IOException {
String getdate = (String) input.get(0);
if (getdate != null){
try{
//LOGIC to return prev month date
}
需要帮助。提前致谢。
【问题讨论】:
-
你应该接受 Balduz 的回答,除非你觉得它不令人满意(在我看来是对的)
标签: apache-pig udf