Cassandra Java驱动程序查询结果集未存储在变量中

发布于 2025-01-18 15:50:20 字数 815 浏览 5 评论 0原文

        //Read data from Cassandra
        String query = "SELECT * FROM LABA_2.DATA LIMIT 5;";
        //Creating Cluster object
        Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
        //Creating Session object
        Session session = cluster.connect();
        //Getting the ResultSet
        ResultSet result = session.execute(query);
        System.out.println(result.all().size());
        System.out.println("AJFGJKABGSDKGJS");
        System.out.println(result.all().size());
        System.out.println("AJFGJKABGSDKGJS");

输出:

22/04/02 23:11:56 INFO Cluster: New Cassandra host /127.0.0.1:9042 added
5
AJFGJKABGSDKGJS
0
AJFGJKABGSDKGJS

第一种情况大小 = 5,第二种情况 = 0。

cassandra-driver - 3.11.0

为什么结果不同?

        //Read data from Cassandra
        String query = "SELECT * FROM LABA_2.DATA LIMIT 5;";
        //Creating Cluster object
        Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
        //Creating Session object
        Session session = cluster.connect();
        //Getting the ResultSet
        ResultSet result = session.execute(query);
        System.out.println(result.all().size());
        System.out.println("AJFGJKABGSDKGJS");
        System.out.println(result.all().size());
        System.out.println("AJFGJKABGSDKGJS");

Output:

22/04/02 23:11:56 INFO Cluster: New Cassandra host /127.0.0.1:9042 added
5
AJFGJKABGSDKGJS
0
AJFGJKABGSDKGJS

In the first case size = 5, in the second = 0.

cassandra-driver - 3.11.0

Why results are different?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明天过后 2025-01-25 15:50:21

您的测试无效。调用resultset.all()迫使驱动程序一口气检索整个结果设置。重要的是,这里要注意的是,在调用all()之后,没有什么可检索的。

当您第二次调用all()时,它没有返回,因为您已经检索了所有内容 - 列表已经耗尽了,没有剩下的。干杯!

Your test is invalid. Calling ResultSet.all() forces the driver to retrieve the whole result set in one go. The important thing to note here is that after calling all(), there is nothing left to retrieve.

When you call all() a second time, it returns nothing because you have already retrieved everything -- the list is exhausted and there's nothing left. Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文