我有一个js自定义项,看起来是这样的:
is_match.outputSchema = 'matched:chararray, match_against:chararray, match_candidate:chararray';
function is_match (match_against, match_candidate) {
var mre = new RegExp(match_against);
return { word:mre.test(match_candidate), word:match_against, word:match_candidate };
}
叫它的Pig长得像这样:
register '<full path omitted>my_match.js' using javascript as js_match;
regexes = load <stuff> using PigStorage() as ( regex:chararray );
tests = load <stuff> using PigStorage() as ( agent:chararray );
regexes = distinct regexes;
tests = distinct tests;
tests = cross regexes, tests;
matched = foreach tests generate js_match.is_match( regex, agent );
我得到的是一大堆空元组:
((,,))
((,,))
((,,))
((,,))
如果我将js中的函数切换为这样:
is_match.outputSchema = 'foo:int';
function is_match (foo, bar) {
return 1;
}
我实际上得到:
(1.0)
(1.0)
(1.0)
这正是我所期望的。但是,当我将js的return更改为返回我的任何实际数据时,它不会返回。如果我做了回报声明 'return 1;'
,我得到1分。
我不知道为什么我不能从更大的js函数返回值,我能够返回“通过”的不太复杂的数据,它应该每次都返回“某物”。为了我们的目的, tests
看起来像:
(.oo,foobar)
(.oo,bazfoobar)
(.oo,foobarbaz)
([Ff]oo,Bar)
([Ff]oo,bar)
其中第一列是表达式,第二列是字符串。我只是想用一大堆表达式来浏览一大堆字符串。
暂无答案!
目前还没有任何答案,快来回答吧!