我是 HBase 的新手,我已将 TextFormat 中的表数据导出到以下格式的文本文件中。
72 6f 77 31 键值={row1/cf:a/1444817478342/Put/vlen=6/ts=0}
我想导入表的相同数据,我尝试通过将此文件输入提供给 Hbase 导入,但它需要 SequenceFile 格式,并尝试通过将输入格式类更改为 TextInputFormat 来调整导入,但仍然无法正常工作。任何指导行达到我的要求。
最佳答案
您可以使用 java 程序上传数据,而不是导出。
示例代码:
公共(public)类 HBaseDataInsert {
配置文件;
HTable hTable;
HBaseScan hbaseScan;
public HBaseDataInsert() throws IOException {
conf = HBaseConfiguration.create();
hTable = new HTable(conf, "emp_java");
}
public void upload_transactionFile() throws IOException {
String currentLine = null;
BufferedReader br = new BufferedReader(
new FileReader("transactionsFile.csv"));
while ((currentLine = br.readLine()) != null) {
System.out.println(currentLine);
String[] line = currentLine.split(",");
Put p = new Put(Bytes.toBytes(line[0] + "_" + line[1]));
p.add(Bytes.toBytes("details"), Bytes.toBytes("Name"), Bytes.toBytes(line[0]));
p.add(Bytes.toBytes("details"), Bytes.toBytes("id"), Bytes.toBytes(line[1]));
p.add(Bytes.toBytes("details"), Bytes.toBytes("DATE"), Bytes.toBytes(line[2]));
p.add(Bytes.toBytes("transaction details"), Bytes.toBytes("TRANSACTION_TYPE"), Bytes.toBytes(line[3]));
hTable.put(p);
}
br.close();
hTable.close();
}
关于hadoop - 解析文本文件并导入 HBase 中的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33147397/