如何让pig在hbase中将行存储为字符串而不是字节?

vc9ivgsu  于 2021-06-21  发布在  Pig
关注(0)|答案(2)|浏览(462)

如果我使用 hbase shell 并发布:

put 'test', 'rowkey1','cf:foo', 'bar'
scan 'test'

我将把结果看作字符串,而不是字节。
如果我使用 happybase 并发布:

import happybase
connection = happybase.Connection('<hostname>')
table = connection.table('test')
table.put('rowkey2', {'cf:foo': 'bar'})
for row in table.scan():
    print row

我将把结果看作字符串,而不是字节。
我在配置单元中有数据,我在其中运行聚合并通过以下方式存储在hdfs上:

INSERT OVERWRITE DIRECTORY 'aggregation_test'
SELECT device_id, device_name, sum(device_cost)
FROM devices
GROUP BY device_id, device_name
ORDER BY device_id, device_name

但是,如果我在pig中发布以下内容:

A = LOAD 'aggregation_test' USING PigStorage(',') as (device_id:chararray, device_name:chararray, device_sum:int);
STORE A INTO 'hbase://aggregation_test'
USING org.apache.pig.backend.hadoop.hbase.HBaseStorage(
    'cf:device_name, cf:device_sum');

扫描 hbase shell 而且在 happybase 结果是字节,而不是字符串。
我甚至不能搜索一个字符串的行键。
如何使用pig和hbastorage将hdfs中的数据作为字符串而不是字节存储到hbase中?

xsuvu9jc

xsuvu9jc1#

hbase shell和happybase中的扫描结果是字节,而不是字符串。
我怀疑问题出在源数据上,而不是清管器进程本身。
为什么不将源数据复制到本地磁盘并检查呢?比如:

hadoop fs -copyToLocal /<>/aggregation_test /tmp/aggregation_test
cat /tmp/aggregation_test/*

另一个检查:hbase中的行数是否与您期望的一致?

bmp9r5qi

bmp9r5qi2#

您尝试过使用hbasebinaryconverter选项吗?比如:

store CompleteCases_f into 'hbase://user_test' using
    org.apache.pig.backend.hadoop.hbase.HBaseStorage(
        'id:DEFAULT id:last_modified birth:year gender:female gender:male','-caster HBaseBinaryConverter'
);

相关问题