2015년 8월 26일 수요일

[PIG] Calling Static Java Functions

1. Syntax
DEFINE alias GenericInvoker(String fullName)
DEFINE alias GenericInvoker(String fullName, String paramSpecsStr)
DEFINE alias GenericInvoker(String fullName, String paramSpecsStr, String isStatic)
2. Terms
alias: UDF 함수 이름 지정
GenericInvoker: return type에 따라 InvokeForInt, InvokeForLong, InvokeForFloat, InvokeForDouble, InvokeForString 중 택 1
fullName: Java Method 지정
paramSpecsStr: 매개변수 type 지정
isStatic: Static 여부 지정, Default = 'true'

3. Example 1
decimal to hexadecimal
DEFINE IntToHex InvokeForString('java.lang.Integer.toHexString', 'int');
pvd = load 'PageViewData' as (exchange, symbol, date, open, high, low, close, volume, str_hex);
inhex = foreach pvd {
generate symbol, IntToHex((int)volume);
}

4. Example 2
hexadecimal to decimal ( Long )
DEFINE Hex2Long InvokeForLong('java.lang.Long.parseLong', 'String int');
pvd = load 'PageViewData' as (exchange, symbol, date, open, high, low, close, volume, str_hex);
hexLong = foreach pvd {
generate symbol, Hex2Long(str_hex, 16);
}

5. 참고 link
https://www.safaribooksonline.com/library/view/programming-pig/9781449317881/ch05s04.html
http://pig.apache.org/docs/r0.10.0/api/org/apache/pig/builtin/GenericInvoker.html
http://www.tutorialspoint.com/java/lang/long_parselong_radix.htm

댓글 없음:

댓글 쓰기

추천 게시물

python: SVD(Singular Value Decomposition)로 간단한 추천시스템 만들기( feat. surprise )

svd_example In [15]: # !pip install surprise In [21]: from...