에 Databag 전달 나는 장소에 대한 몇 가지 데이터를로드하는 스크립트가 있습니다. 돼지 UDF 생성자
그래서 나는 그런이 UDF 정의하려고 :DEFINE GenerateVenues org.gla.anton.udf.main.GenerateVenues(venues);
을 그리고 여기에 실제 UDF입니다 :
public class GenerateVenues extends EvalFunc<Tuple> {
TupleFactory mTupleFactory = TupleFactory.getInstance();
BagFactory mBagFactory = BagFactory.getInstance();
private static final String ALLCHARS = "(.*)";
private ArrayList<String> venues;
private String regex;
public GenerateVenues(DataBag venuesBag) {
Iterator<Tuple> it = venuesBag.iterator();
venues = new ArrayList<String>((int) (venuesBag.size() + 1)); // possible fails!!!
String current = "";
regex = "";
while (it.hasNext()){
Tuple t = it.next();
try {
current = "(" + ALLCHARS + t.get(0) + ALLCHARS + ")";
venues.add((String) t.get(0));
} catch (ExecException e) {
throw new IllegalArgumentException("VenuesRegex: requires tuple with at least one value");
}
regex += current + (it.hasNext() ? "|" : "");
}
}
@Override
public Tuple exec(Tuple tuple) throws IOException {
// expect one string
if (tuple == null || tuple.size() != 2) {
throw new IllegalArgumentException(
"BagTupleExampleUDF: requires two input parameters.");
}
try {
String tweet = (String) tuple.get(0);
for (String venue: venues)
{
if (tweet.matches(ALLCHARS + venue + ALLCHARS))
{
Tuple output = mTupleFactory.newTuple(Collections.singletonList(venue));
return output;
}
}
return null;
} catch (Exception e) {
throw new IOException(
"BagTupleExampleUDF: caught exception processing input.", e);
}
}
}
스크립트가 단지 (venues);
전에 DEFINE
부분에 오류가 발사되어 실행되는 경우
2013-12-19 04:28:06,072 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <file script.pig, line 6, column 60> mismatched input 'venues' expecting RIGHT_PAREN
명백하게 나는 잘못된 것을하고있다. ca n 당신이 무엇이 잘못되었는지 알아내는 것을 도와줍니다. 장소 관계를 매개 변수로 허용 할 수없는 UDF입니까? 또는이 관계가 DataBag
(이 public GenerateVenues(DataBag venuesBag)
과 같은)으로 표시되지 않습니까? 감사합니다.
추신 : 나는 돼지 버전 0.11.1.1.3.0.0-107을 사용하고 있습니다.