gpt4 book ai didi

hadoop - Hive 无法识别 hbase 中的数字类型值

转载 作者:可可西里 更新时间:2023-11-01 14:45:00 27 4
gpt4 key购买 nike

我有一个 hive/hbase 集成表,定义如下。

create table user_c(user_id int, c_name string, c_kind string, c_industry string,
c_jobtitle string, c_workyear int, c_title string, c_company string)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:c_name,cf1:c_kind,cf1:c_industry,cf1:c_jobtitle,cf1:c_workyear,cf1:c_title,cf1:c_company")
TBLPROPERTIES ("hbase.table.name" = "user_c");

在我的 java 代码中,我创建了一个 Put 并用从 db 读取的值填充它。代码如下所示:

final Put to = new Put(getByte(from, keyColumn));
for (final IColumn column : table.getColumns()) {
if (column.equals(keyColumn)) continue;
to.add(Bytes.toBytes(column.getColumnFamily()), Bytes.toBytes(column.getDestName()), getByte(from, column));
}
return to;

getByte 是一种将值转换为 byte[] 的方法。看起来像

byte[] getByte(final Map<String, Object> map, IColumn column) {
final Object val = map.get(column.getName());
if (val instanceof Integer) {
return Bytes.toBytes((Integer) val);
}
...
}

然后放入hbase。

我可以从 hbase shell 中扫描记录。

hbase(main):001:0> scan 'user_c'
ROW COLUMN+CELL
\x00\x0A\x07\x0D column=cf1:c_workyear, timestamp=1350298280554, value=\x00\x00\x07\xD8
\x00\x0A\x07\x0D column=cf1:c_industry, timestamp=1350298280554, value=120
...

Row key是Integer类型,在被getByte方法处理时应该会自动拆箱为原始int类型。不仅是行键,还有其他数字类型的列(cf1:c_workyear)显示为\x00\x0A\x07\x0D,一个字节数组。

同时,String 类型的列 (cf1:c_industry) 只显示它的值。

这样可以吗?

当我从 hive 查询记录时,它只给我一个 NULL 而不是数字类型列的值。

hive> select c_industry, c_workyear from user_c limit 1;
Total MapReduce CPU Time Spent: 10 seconds 370 msec
OK
120 NULL
Time taken: 46.063 seconds

c_workyear 值似乎无法被hive 识别。我想这是因为那个类型不正确。但是 int 字节数组不应该存储为 int 值,而不是字节数组吗?

有谁知道如何解决这个问题吗?

非常感谢。

最佳答案

在你的表定义中试试这个

"hbase.columns.mapping" = ":key,cf1:c_name,cf1:c_kind,cf1:c_industry#b,cf1:c_jobtitle,cf1:c_workyear#b,cf1:c_title,cf1:c_company"

注意在二进制字段之后使用 #b。我们已经成功地使用了一段时间

关于hadoop - Hive 无法识别 hbase 中的数字类型值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12909118/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com