Apache pig 过滤器上的清管器udf
我有一个用例,在这个用例中,我需要输入一个月的日期来返回上个月的最后一个日期Apache pig 过滤器上的清管器udf,apache-pig,udf,Apache Pig,Udf,我有一个用例,在这个用例中,我需要输入一个月的日期来返回上个月的最后一个日期 Ex: input:20150331 output:20150228 我将使用上个月的最后一个日期来过滤每日分区(在pig脚本中) 我已经创建了一个UDF(GetPrevMonth),它接受日期并返回上个月的最后一个日期。但是无法在过滤器上使用它 ERROR:Could not infer the matching function for GetPrevMonth as multiple or none of th
Ex: input:20150331 output:20150228
我将使用上个月的最后一个日期来过滤每日分区(在pig脚本中)
我已经创建了一个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
}
UDF:public类GetPrevMonth扩展EvalFunc{
公共整数执行(元组输入)引发IOException{
字符串getdate=(字符串)input.get(0);
如果(getdate!=null){
试一试{
//返回上一个月日期的逻辑
}
需要帮助。请提前感谢。您可以在
过滤器中调用UDF
,但您正在向函数传递一个数字,而您希望它接收字符串(字符集
):
简单的解决方案是在调用UDF时将其强制转换为chararray
:
B = filter A by daily_partition == GetPrevMonth((chararray)20150331);
通常,当您看到一些错误,如无法推断X的匹配函数为多个或没有一个匹配时,
,99%的原因是您试图传递给UDF的值是错误的
最后一件事,即使没有必要,在将来您可能希望编写一个纯过滤器
UDF。在这种情况下,您需要从EvalFunc
继承,而不是从FilterFunc
继承,并返回一个布尔值:
public class IsPrevMonth extends FilterFunc {
@Override
public Boolean exec(Tuple input) throws IOException {
try {
String getdate = (String) input.get(0);
if (getdate != null){
//LOGIC to retrieve prevMonthDate
if (getdate.equals(prevMonthDate)) {
return true;
} else {
return false;
}
} else {
return false;
}
} catch (ExecException ee) {
throw ee;
}
}
}
你应该接受巴尔杜兹的回答,除非你觉得不满意(对我来说似乎是对的)
B = filter A by daily_partition == GetPrevMonth((chararray)20150331);
public class IsPrevMonth extends FilterFunc {
@Override
public Boolean exec(Tuple input) throws IOException {
try {
String getdate = (String) input.get(0);
if (getdate != null){
//LOGIC to retrieve prevMonthDate
if (getdate.equals(prevMonthDate)) {
return true;
} else {
return false;
}
} else {
return false;
}
} catch (ExecException ee) {
throw ee;
}
}
}