从HBase中获取二进制数据

时间:2016-06-23 10:46:02

标签: hbase cloudera binary-data

我正在体验HBase(Cloudera 5.7 Distribution)并且有一个问题。 我在HBase中存储了二进制数据(PDF,Word,JPEG,...),并激活了新的MOB功能(MOB DocumentationDescription of MOB-Concept

存储数据不是问题。但是,如何从HBase中获取文件(最好是另存为对话框)?

提前谢谢!

1 个答案:

答案 0 :(得分:0)

如关于MOB支持的Cloudera文档中所述

  

该功能对客户端是透明的。

https://www.cloudera.com/documentation/enterprise/5-5-x/topics/admin_hbase_mob.html

这意味着您可以使用与任何其他列相同的方式获取存储的MOB的内容。 在Java中:

        String namespace = "nmsp";
        String tblName = "MOB_TEST";
        byte[] rowKey = "MOB_1".getBytes();
        byte[] columnFamily = "D".getBytes();
        byte[] qualifier = "MOB".getBytes();

        Get g = new Get(rowKey);
        g.addColumn(columnFamily, qualifier);

        Configuration cfg = HBaseConfiguration.create();
        Connection con = ConnectionFactory.createConnection(cfg);
        Table t = con.getTable(TableName.valueOf(namespace, tblName));

        Result r = t.get(g);
        byte[] mobContent = r.getValue(columnFamily, qualifier);

        Path outPath = FileSystems.getDefault()
                .getPath("C:/testBigFile_fromHBase.xml");
        Files.write(outPath, mobContent);