Pig BigDecimal to Hive decimal(Pig BigDecimal to Hive decimal)

编程入门 行业动态 更新时间:2024-10-26 15:24:33
Pig BigDecimal to Hive decimal(Pig BigDecimal to Hive decimal)

我试图将Pig BigDecimal转换为Hive Decimal类型,但值被gettined 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。 使用DECIMAL(16,0)的此列定义创建测试表。 我正在使用Hive 1.1.0。 请建议如何解决此问题。

I am trying to convert Pig BigDecimal to Hive Decimal type but values are gettined null. Here is the sample code:

Pig Scripts:

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

In the above code, the sum value of record counts is coming properly in the HDFS file stored as 'user/test'. But with HcatStorer, the same field is populated with NULL for all the records. The test table is created with this column definition of DECIMAL(16,0). I am using Hive 1.1.0. Please suggest how to fix this issue.

最满意答案

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

I have finally figured it out the reason for null. Hcatalog does a range check when converting bigdecimal in pig to Decimal in hive. As there is no scale in the Hive definition (i.e., DECIMAL (16,0)), it is getting defaulted to null during range check while storing. When I changed the Hive definition to DECIMAL(16,2) it is getting stored properly. So this requires a change in layout for sure to update the scale.

更多推荐

Hive,using,test',电脑培训,计算机培训,IT培训"/> <meta name="descrip

本文发布于:2023-04-29 09:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:BigDecimal   Pig   decimal   Hive

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!