标签:pig
pig支持的类型转换(cast)
Pig Latin supports casts as shown in this table.
from / to |
bag |
tuple |
map |
int |
long |
float |
double |
chararray |
bytearray |
boolean |
bag |
error |
error |
error |
error |
error |
error |
error |
error |
error |
|
tuple |
error |
error |
error |
error |
error |
error |
error |
error |
error |
|
map |
error |
error |
error |
error |
error |
error |
error |
error |
error |
|
int |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
error |
|
long |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
error |
|
float |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
error |
|
double |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
error |
|
chararray |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
yes |
|
bytearray |
yes |
yes |
yes |
yes |
yes |
yes |
yes |
yes |
yes |
|
boolean |
error |
error |
error |
error |
error |
error |
error |
yes |
error |
将字符类型转化做int是可以的。测试如下
pig 代码:
%default testFile /user/wizad/test/lmj/test_file.txt
test_data = LOAD ‘$testFile‘ USING PigStorage(‘,‘)
AS
(str1:chararray,
number:int
);
dump test_data;
my_result = foreach test_data generate (int)SUBSTRING(str1,0,3);
dump my_result;
describe my_result;
--myts = sample g_log 0.0001;
--myts = limit g_log 10;
--dump myts;
--STORE myts INTO ‘/user/wizad/tmp/my‘ USING PigStorage(‘,‘);
from / to |
bag |
tuple |
map |
int |
long |
float |
double |
chararray |
bytearray |
boolean |
bag |
error |
error |
error |
error |
error |
error |
error |
error |
error |
|
tuple |
error |
error |
error |
error |
error |
error |
error |
error |
error |
|
map |
error |
error |
error |
error |
error |
error |
error |
error |
error |
|
int |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
error |
|
long |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
error |
|
float |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
error |
|
double |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
error |
|
chararray |
error |
error |
error |
yes |
yes |
yes |
yes |
error |
yes |
|
bytearray |
yes |
yes |
yes |
yes |
yes |
yes |
yes |
yes |
yes |
|
boolean |
error |
error |
error |
error |
error |
error |
error |
yes |
error |
标签:pig
原文地址:http://blog.csdn.net/longshenlmj/article/details/41823277