grunt> DEFINE trim InvokeForString('org.apache.commons.lang.StringUtils.trim', 'String');
grunt> B = FOREACH A GENERATE trim(fruit);
grunt> DUMP B;
(pomegranate)
(banana)
(apple)
(lychee)
這裡用到
InvokeForString
呼叫器是因為這個函數的回傳值是
String
型態。(另外
還有
InvokeForInt
、
InvokeForLong
、
InvokeForDouble
跟
InvokeForFloat
呼叫
器。)呼叫器建構者(
invoker constructor
)的第一個參數是欲呼叫的完整函數。第二
個參數是由空白隔開的參數列表,這些參數是給第一個參數指定的函數用的。
11.5.3
載入用自訂函數
接下來我們將示範一個客製化的載入函數,它可以用欄位字數範圍載入純文字,就像
Unix
的
cut
指令。其使用方式如下:
grunt>
records = LOAD 'input/ncdc/micro/sample.txt'
>>
USING com.hadoopbook.pig.CutLoadFunc('16-19,88-92,93-93')
>>
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.