首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HBase中的组合键

HBase中的组合键
EN

Stack Overflow用户
提问于 2013-09-06 18:11:07
回答 2查看 5.9K关注 0票数 2

我是HBase的新手,必须使用组合键作为主键。请告诉我

代码语言:javascript
复制
How to make composite-key in hbase?
And How to search a record using that composite-key?
EN

回答 2

Stack Overflow用户

发布于 2013-09-06 18:44:59

只需连接密钥的各个部分并使用它即可。没有什么特别事情。假设您有一个customer表,并且希望有一个由CustID和时间戳组成的行键。然后,您希望获取特定用户的所有结果,而不考虑时间戳。你会这样做:

代码语言:javascript
复制
public static void main(String[] args) throws IOException {

    Configuration conf = HBaseConfiguration.create();
    HTable table = new HTable(conf, "demo");
    String CustID = "tar024";
    byte[] rowKey = Bytes.add(Bytes.toBytes(CustID), Bytes.toBytes(System.currentTimeMillis()));

    //Put the data
    Put p = new Put(rowKey);
    System.out.println(Bytes.toString(rowKey));
    p.add(Bytes.toBytes("cf"), Bytes.toBytes("c1"), Bytes.toBytes("VALUE"));
    table.put(p);

    //Get the data
    Scan s = new Scan();
    Filter filter = new PrefixFilter(Bytes.toBytes("tar024"));
    s.setFilter(filter);
    ResultScanner rs = table.getScanner(s);
    for(Result r : rs){
        System.out.println("VALUE : " + Bytes.toString(r.getValue(Bytes.toBytes("cf"), Bytes.toBytes("c1"))));
    }
    rs.close();
    table.close();
}

HTH

票数 6
EN

Stack Overflow用户

发布于 2014-02-12 23:20:56

对我来说,最好的方法就是有序地使用。它是一个库,可以帮助您创建组合键并对它们进行排序。Link to Orderly。您也可以在设置开始和停止行键的扫描操作中使用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18655256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档