Java客户端调用Cassandra数据库无法使IN和order by的SQL语句同时使用报错问题

Cassandra数据库无法同时使用IN和order by

当使用 IN 和 ORDER BY 时,Cassandra 不支持分页。datastax 文档 -使用 IN 关键字进行检索中也说明了这一点。
在这里插入图片描述

一、问题场景:

报错如下:
Cannot page queries with both ORDER BY and a IN restriction on the partition key; you must either remove the ORDER BY or the IN and sort client side, or disable paging for this query
具体SQL如下:

select * from AXWS where v IN ('LX2H, 'L5') and ct>=17375 order by ct desc

二、解决方法

①取消分页限制(代码层面):

import com.datastax.driver.core.Statement;
		 ResultSet rows = null;
  		 Statement statement = new SimpleStatement(cql);
         statement.setFetchSize(Integer.MAX_VALUE);//设置最大值
         rows = this.session.execute(statement);

②取消分页限制(命令):

  • 关闭分页:

cqlsh> PAGING OFF

③取消IN或者order by,使用批量查询,归到Java中进行排序

	 ResultSet rows1 =  this.session.execute(sql1);
 	 ResultSet rows2 =  this.session.execute(sql2);
 	 ResultSet rows3 =  this.session.execute(sql3);
 
	...合并处理时间排序操作
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值