首页 文章

Cassandra的Spring数据 - CassandraOperations获得最大列

提问于
浏览
2

我正在使用Spring Data for Cassandra v1.5.10开发Spring Boot应用程序以连接到Cassandra .

我找不到任何参考,显示如何使用CassandraOperations和QueryBuilder从Cassandra表中检索max(col) . 我试过下面但它返回 - 未定义的列名“max(id)”

public class CassandraTest{

  @Autowired
  private CassandraOperations cassandraTemplate;

  public void execute() {
    Select sel = QueryBuilder.select("max(id)").from("table").;
    Integer maxId= cassandraTemplate.queryForObject(sel, Integer.class);
    System.out.println("maxid ===> " + maxId);
  }
}

2 回答

  • 0

    经过reference doc之后,我发现了另一种方法 - 不使用QueryBuilder .

    String selectQuery = "select max(id) as maxId from table";      
        Integer maxId= csOps.selectOne(selectQuery, Integer.class);
        System.out.println("maxid ===> " + maxId);
    

    我仍然想知道QueryBuilder是否可行 . 有趣的是,datastax driver Select api支持最大功能 .

    public Select.SelectionOrAlias max(Object column)
    Description copied from class: Select.Selection
    Creates a max(x) built-in function call.
    Overrides:
    max in class Select.Selection
    Returns:
    the function call.
    
  • 0

    这应该工作(虽然没有测试):

    Select sel = QueryBuilder.select().max(column("id")).from("table").;
    

相关问题