Pig BigDecimal 到 Hive 十进制
Pig BigDecimal to Hive decimal
我正在尝试将 Pig BigDecimal 转换为 Hive Decimal 类型,但值变为 null。这是示例代码:
猪脚本:
a = LOAD 'test.txt' using TextLoader() as (col1:chararray,col2:int,col3:chararray,col4:int);
b = foreach a generate *,1 as rec_cnt;
c = group b by col1,col3;
d = foreach c generate flatten(group),(bigdecimal) SUM(rec_cnt) as grp_code;
STORE d into 'user/test' Using PigStorage(',');
STORE d into 'default.test' using org.apache.hive.hcatalog.pig.HCatStorer();
在上面的代码中,记录计数的总和值正确地存储在存储为'user/test'的HDFS文件中。但是对于 HcatStorer,同一字段的所有记录都填充为 NULL。测试 table 是使用 DECIMAL(16,0) 的列定义创建的。我正在使用 Hive 1.1.0。请建议如何解决此问题。
我终于弄清楚null的原因了。当将 pig 中的 bigdecimal 转换为 hive 中的 Decimal 时,Hcatalog 会进行范围检查。由于 Hive 定义中没有比例(即 DECIMAL (16,0)),因此在存储时的范围检查期间它会默认为 null。当我将 Hive 定义更改为 DECIMAL(16,2) 时,它已正确存储。所以这需要更改布局以确保更新比例。
我正在尝试将 Pig BigDecimal 转换为 Hive Decimal 类型,但值变为 null。这是示例代码:
猪脚本:
a = LOAD 'test.txt' using TextLoader() as (col1:chararray,col2:int,col3:chararray,col4:int);
b = foreach a generate *,1 as rec_cnt;
c = group b by col1,col3;
d = foreach c generate flatten(group),(bigdecimal) SUM(rec_cnt) as grp_code;
STORE d into 'user/test' Using PigStorage(',');
STORE d into 'default.test' using org.apache.hive.hcatalog.pig.HCatStorer();
在上面的代码中,记录计数的总和值正确地存储在存储为'user/test'的HDFS文件中。但是对于 HcatStorer,同一字段的所有记录都填充为 NULL。测试 table 是使用 DECIMAL(16,0) 的列定义创建的。我正在使用 Hive 1.1.0。请建议如何解决此问题。
我终于弄清楚null的原因了。当将 pig 中的 bigdecimal 转换为 hive 中的 Decimal 时,Hcatalog 会进行范围检查。由于 Hive 定义中没有比例(即 DECIMAL (16,0)),因此在存储时的范围检查期间它会默认为 null。当我将 Hive 定义更改为 DECIMAL(16,2) 时,它已正确存储。所以这需要更改布局以确保更新比例。