hadoop - 解析文本文件并导入 HBase 中的表

标签 hadoop mapreduce hbase

我是 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/

相关文章:

java - Hadoop MapReduce : MapOutputValueClass : Map<String, 字符串>?

java - 从 MapReduce 映射器中的输入文件获取唯一行号

hadoop - mapred.job.queue.name 的用例

java - 在 hbase shell 上执行 ValueFilter 和 Count 值

java - 搜索 arrayLists 的映射树

hadoop - 配置单元插入查询失败,错误返回码-101

java - CSV 类未找到异常

java - 摆脱 Hbase 配置弃用警告

hadoop - 在osx中​​构建hadoop 3.1.1以获取 native 库

sql - HiveQL:从字符串列中删除前导空格