sca*_*cer 3 integration client hadoop hbase hive
我有一个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");
Run Code Online (Sandbox Code Playgroud)
在我的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;
Run Code Online (Sandbox Code Playgroud)
这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);
}
...
}
Run Code Online (Sandbox Code Playgroud)
然后把它放入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
...
Run Code Online (Sandbox Code Playgroud)
行键是一种Integer类型,int在由getByte方法处理时应该自动取消对原始类型的取消.不仅行键,而且其他数字类型列(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
Run Code Online (Sandbox Code Playgroud)
似乎hive无法识别c_workyear值.我猜是因为那种类型不正确.但是不应该将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"
Run Code Online (Sandbox Code Playgroud)
注意在#b二进制字段之后使用.我们已经成功地使用它已经有一段时间了
| 归档时间: |
|
| 查看次数: |
2539 次 |
| 最近记录: |