Cassandra Java驱动程序查询结果集未存储在变量中
//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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的测试无效。调用
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 callingall()
, 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!