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();

在上面的代码中,记录计数的和值正确地出现在存储为"用户/测试"的HDFS文件中。但是对于HcatStorer,所有记录都会在同一个字段中填充NULL。测试表是使用DECIMAL(16,0)的列定义创建的。我使用的是配置单元1.1.0。请建议如何解决此问题。

我终于找到了null的原因。当将pig中的bigdecimal转换为hive中的Decimal时,Hcatalog会进行范围检查。由于Hive定义中没有小数位数(即DECIMAL(16,0)),因此在存储时进行范围检查时,它将默认为null。当我将配置单元定义更改为DECIMAL(16,2)时,它得到了正确的存储。因此,这需要改变布局以确保更新比例。

最新更新