更新时间:2024-11-26 GMT+08:00
分享

统计查询

功能介绍

返回满足查询条件的实体总量,不返回数据的具体信息,代码中设置setCountOnly()。

可以参考以下样例代码。

样例代码

public void testCountOnlyQuery() { 
  LOG.info("Entering testCountOnlyQuery."); 

  try (Table table = conn.getTable(tableName)) { 
    // Using Table instance to create LemonTable. 
    LemonTable lemonTable = new LemonTable(table); 
    // Build LemonQuery. 
    LemonQuery query = LemonQuery.builder() 
      // Set ad-hoc query condition. 
      .setQuery("education:bachelor OR education:master") 
      // just return how many entities meet the query condition, without any rowkey/column 
      .setCountOnly() 
      .build(); 
    ResultSet resultSet = lemonTable.query(query); 
    // Read result rows. 
    int count = resultSet.getCount(); 
    LOG.info("the entity count of query is " + count); 
  } catch (IOException e) { 
    LOG.error("testCountOnlyQuery failed ", e); 
  } 

  LOG.info("Exiting testCountOnlyQuery."); 
}

相关文档