我是HBase的新手我已经将TextFormat中的表格数据导出为以下格式的文本文件。解析文本文件并导入到HBase中的表格
72 6F 77个31键值= {ROW1/CF:A/1444817478342/PUT/VLEN = 6/TS = 0}
相同的数据我要导入到该表中,我已通过给此文件试图输入到Hbase导入,但它期望SequenceFile格式并尝试通过将输入格式类更改为TextInputFormat来调整导入,但仍然无法工作。任何指导行都可以实现我的要求。
我是HBase的新手我已经将TextFormat中的表格数据导出为以下格式的文本文件。解析文本文件并导入到HBase中的表格
72 6F 77个31键值= {ROW1/CF:A/1444817478342/PUT/VLEN = 6/TS = 0}
相同的数据我要导入到该表中,我已通过给此文件试图输入到Hbase导入,但它期望SequenceFile格式并尝试通过将输入格式类更改为TextInputFormat来调整导入,但仍然无法工作。任何指导行都可以实现我的要求。
不用导出,你可以使用java程序来上传数据。
示例代码:
public class HBaseDataInsert { Configuration conf; 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();
}
导出和导入,默认情况下工作与序列文件转储。如果您的要求只是从一个表格加载到另一个表格,假设两者都具有相似的格式,则可以使用下面的命令。输入和输出目录是HDFS目录。
$斌/ HBase的org.apache.hadoop.hbase.mapreduce.Export
$斌/ HBase的org.apache.hadoop.hbase.mapreduce.Import
感谢您的答复阿曼!但我出口格式不是csv,如上所示,我给出了一行(72 6f 77 31 keyvalues = {row1/cf:a/1444817478342/Put/vlen = 6/ts = 0}),这是我输出的表格的扫描输出,I想要以导入的通用方式导入相同的文件。 – Naidu