将别名和字段传递到猪宏

时间:2014-11-24 18:29:57

标签: macros apache-pig

我正在尝试将别名和字段传递给猪宏:

define mymac (a1, f, a2) returns void {
  foreach (join $a1 on $f, $a2 on field) generate
    $a1::$f as $f, $a2::field as field;
};

我收到错误

Unexpected character '$'
当我将宏调用为

时,

$中的第二个$a1::$f

mymac(x,foo,y);

我也试过

define mymac (a1, f, af, a2) returns void {
  foreach (join $a1 on $f, $a2 on field) generate
    $af as $f, $a2::field as field;
};
mymac(x,foo,x::foo,y);

并且出现了更加神秘的错误

org.apache.pig.PigServer - exception during parsing: Error during parsing. Pig script failed to parse: at expanding macro

那么,我该怎么办?如何将别名与宏中的字段组合?

1 个答案:

答案 0 :(得分:2)

调用宏时,您需要在''中输入字段名称,例如mymac(x,'foo','x::foo',y);。我已经测试了你提到的第二种方法并且它有效。