V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
nthin0
V2EX  ›  Java

求助,用 Java api 怎样快速判断 hbase 里模糊匹配的 rowkey 是否存在

  •  
  •   nthin0 · Sep 7, 2020 · 2671 views
    This topic created in 2068 days ago, the information mentioned may be changed or developed.
    • rowkey 的数量在几十万到百万左右
    • 方案一:遍历生成所有的 rowkey,再用 table.existsAll(gets)可以判断 rowkey 是否存在,但是较慢
    • 方案二:用 scan 可以模糊匹配 rowkey,但是会把所有的数据都查出来,还是比较慢。。
    Scan scan = new Scan();
    scan.setStartRow(Bytes.toBytes(startRow));
    scan.setStopRow(Bytes.toBytes(stopRow));
    
    • 有没有把两种效果结合起来的方法,模糊匹配 rowkey 是否存在,比如 rowkey 的格式是 12345$yyyyMMddHHmmss,67890$yyyyMMddHHmmss

    • 能通过传入 12345 就快速判断 hbase 中是否有 rowkey 以 12345 开头的数据

    • 总之就是 快速 足够快 特别快

    • 谢谢各位大佬了!!!

    5 replies    2020-09-08 23:27:20 +08:00
    nthin0
        1
    nthin0  
    OP
       Sep 7, 2020
    没有大佬帮忙看一下吗~~
    yanshenxian
        2
    yanshenxian  
       Sep 7, 2020
    thinkmore
        3
    thinkmore  
       Sep 8, 2020
    @nthin0 可以使用 prefixFilter 试一试,比如

    ```
    scan 'yourTable',{LIMIT=>10,FILTER=>"PrefixFilter('123456')"}
    ```

    或者 RowFilter

    ```
    scan 'your_table',{FILTER=>"RowFilter(=,'substring:123456')"}
    ```
    thinkmore
        4
    thinkmore  
       Sep 8, 2020   ❤️ 1
    @nthin0 在我的 blog https://generalthink.github.io/2018/12/17/hbase-scan-command/ 中可以看到 scan 的更多命令
    nthin0
        5
    nthin0  
    OP
       Sep 8, 2020
    @thinkmore 感谢!我研究一下这些 filter
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1580 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 16:31 · PVG 00:31 · LAX 09:31 · JFK 12:31
    ♥ Do have faith in what you're doing.