1

次のようなJS udfがあります。

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 ステートメントを作成すると、1 が返さ'return 1;'れます。

より大きな JS 関数から値を返すことができず、「通過する」より複雑でないデータを返すことができる理由がわかりません。毎回「何か」を返す必要があります。私たちの目的では、tests次のようになります。

(.oo,foobar)
(.oo,bazfoobar)
(.oo,foobarbaz)
([Ff]oo,Bar)
([Ff]oo,bar)

ここで、最初の列は式で、2 番目の列は文字列です。式の巨大なリストを使用して、文字列の巨大なリストを実行しようとしています。

4

0 に答える 0