【问题标题】:hbase GREATER_OR_EQAUL operator does not work as expectedhbase GREATER_OR_EQAUL 运算符未按预期工作
【发布时间】:2021-04-30 00:58:55
【问题描述】:

我的 hbase 表中有这一行: {rowkey:1_1611646861574/cf:value/1611646776287/Put/vlen=8/seqid=0} 现在我想做一个简单的扫描并找到其列值大于“1611388300000”的行。但它不返回任何记录;但是,当我使用 LESS_OR_EQUAL 而不是 1611647500000 时,它会返回此记录。 奇怪的是我可以从 apache phoenix sql 查询中得到这条记录:select * from my_table where value>=1611388300000.

所以数字明显大于列值,apache phoenix 返回它;为什么 hbase compare Operator 没有?

这是我的代码:

Table table = con.getTable(TableName.valueOf("my_table"));
Scan scan = new Scan();
scan.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("value"));
FilterList flist = new FilterList(FilterList.Operator.MUST_PASS_ALL);
flist.addFilter(new PrefixFilter(Bytes.toBytes("1")));
flist.addFilter(new SingleColumnValueFilter(
                        Bytes.toBytes("cf"), Bytes.toBytes("value"), CompareOperator.GREATER_OR_EQUAL,
                        new BinaryComparator(Bytes.toBytes("1611388300000"))));
scan.setFilter(flist);
ResultScanner scanner = table.getScanner(scan);
for (Result result = scanner.next(); result != null; result = scanner.next())
     System.out.println("Found row : " + result);
scanner.close();

【问题讨论】:

    标签: java hadoop bigdata hbase phoenix


    【解决方案1】:

    我不知道为什么,但 LESS_OR_EQUAL 适用于字符串:

    new SingleColumnValueFilter(
                        Bytes.toBytes("cf"), Bytes.toBytes("value"), CompareOperator.LESS_OR_EQUAL,
                        new BinaryComparator(Bytes.toBytes("1611647500000")))
    

    但是当我使用引号时 GREATER_OR_EQUAL 不起作用,所以我必须使用数字(添加 L 以指定 Long)

    new SingleColumnValueFilter(
                            Bytes.toBytes("ui"), Bytes.toBytes("C"), CompareOperator.GREATER_OR_EQUAL,
                            new BinaryComparator(Bytes.toBytes(1611388300000L)))
    

    【讨论】:

      猜你喜欢
      • 2015-05-11
      • 2019-06-20
      • 2021-04-13
      • 1970-01-01
      • 2020-12-29
      • 2019-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多