如何简化相同的方法调用

时间:2017-01-24 01:50:37

标签: apache-pig

您好我有以下猪码:

leafNodes = FOREACH records GENERATE
  'buckets' AS bucket_url,
  MultiConcat(localziedName, ' in ', localizedLocation) AS title,
  ToJSONString(
      'url', url,
      'title', MultiConcat(localziedName, ' in ', localizedLocation)
  ) AS link_json;

同一次MultiConcat(localziedName, ' in ', localizedLocation)来电两次。那么,有没有办法使用变量或类似的东西来减少一次调用?

1 个答案:

答案 0 :(得分:1)

我找到了办法。基本上,只需在GENERATE语句之前创建一个变量。这是代码:

leafNodes = FOREACH records {
  title = MultiConcat(localziedName, ' in ', localizedLocation);
  GENERATE
  'buckets' AS bucket_url,
  title,
  ToJSONString(
      'url', url,
      'title', title
  ) AS link_json;
}