出口如何讀取序列文件我用下面的代碼輸出導出HBase的表並保存到HDFS:從HBase的
hbase org.apache.hadoop.hbase.mapreduce.Export \
MyHbaseTable1 hdfs://nameservice1/user/ken/data/exportTable1
輸出文件是二進制文件。如果我使用pyspark讀取文件夾:
test1 = sc.textFile('hdfs://nameservice1/user/ken/data/exportTable1')
test1.show(5)
它顯示:
u'SEQ\x061org.apache.hadoop.hbase.io.ImmutableBytesWritable%org.apache.hadoop.hbase.client.Result\x00\x00\x00\x00\x00\x00\ufffd-\x10A\ufffd~lUE\u025bt\ufffd\ufffd\ufffd&\x00\x00\x04\ufffd\x00\x00\x00'
u'\x00\x00\x00\x067-2010\ufffd\t'
u'|'
u'\x067-2010\x12\x01r\x1a\x08clo-0101 \ufffd\ufffd\ufffd*(\x042\\6.67|10|10|10|7.33|6.67|6.67|6.67|6.67|6.67|6.67|5.83|3.17|0|0|0.67|0.67|0.67|0.67|0|0|0|0|0'
u'u'
我可以告訴大家,在2號線
- '7-2010'是Rowkey, 在4號線
- 'R'是列家族,
- 'CLO-0101'在第四行是列名,
- 「6.67 | 10 | 10 | 10 | 7.33 | 6.67 | 6.67 | 6.67 | 6.67 | 6.67 | 6.67 | 5.83 | 3.17 | 0 | 0 | 0.67 | 0.67 | 0.67 | 0.67 | 0 | 0 | 0 | 0 | 0'是值。
我不知道在哪裏3和第5行是從哪裏來的。看起來Hbase-export遵循自己的規則來生成文件,如果我用我自己的方式來解碼它,數據可能會被損壞。
問:
我如何才能將此文件轉換回可讀格式?例如:
7-2010, r, clo-0101, 6.67|10|10|10|7.33|6.67|6.67|6.67|6.67|6.67|6.67|5.83|3.17|0|0|0.67|0.67|0.67|0.67|0|0|0|0|0
我曾嘗試:
test1 = sc.sequenceFile('/user/youyang/data/hbaseSnapshot1/', keyClass=None, valueClass=None, keyConverter=None, valueConverter=None, minSplits=None, batchSize=0)
test1.show(5)
和
test1 = sc.sequenceFile('hdfs://nameservice1/user/ken/data/exportTable1'
, keyClass='org.apache.hadoop.hbase.mapreduce.TableInputFormat'
, valueClass='org.apache.hadoop.hbase.io.ImmutableBytesWritable'
, keyConverter='org.apache.spark.examples.pythonconverters.ImmutableBytesWritableToStringConverter'
, valueConverter='org.apache.spark.examples.pythonconverters.HBaseResultToStringCon verter'
, minSplits=None
, batchSize=100)
沒有運氣,代碼沒有工作,ERROR:
Caused by: java.io.IOException: Could not find a deserializer for the Value class: 'org.apache.hadoop.hbase.client.Result'. Please ensure that the configuration 'io.serializations' is properly configured, if you're using custom serialization.
有什麼建議?謝謝!