Cassandra CQL3 support in Astyanax

守給你的承諾、 提交于 2019-12-08 17:56:39

问题


Does Astyanax support "insert into" via prepared statement with CQL3? I use the latest Astyanax library 1.56.24 and Cassandra 1.2.1. When I try to execute a prepared statement with CQL3:

keyspace.prepareQuery(conn.CF_CONTACTS)
  .withCql("INSERT INTO contacts (a, b) VALUES (?, ?);")
  .asPreparedStatement()
  .withStringValue("123")
  .withStringValue("456")
  .execute();;

I get the following exception:

Caused by: InvalidRequestException(why:Cannot execute/prepare CQL2 statement since the CQL has been set to CQL3(This might mean your client hasn't been upgraded correctly to use the new CQL3 methods introduced in Cassandra 1.2+).)
at org.apache.cassandra.thrift.Cassandra$prepare_cql_query_result.read(Cassandra.java:38738)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_prepare_cql_query(Cassandra.java:1598)
at org.apache.cassandra.thrift.Cassandra$Client.prepare_cql_query(Cassandra.java:1584)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$6$3$1.internalExecute(ThriftColumnFamilyQueryImpl.java:747)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$6$3$1.internalExecute(ThriftColumnFamilyQueryImpl.java:742)
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:56)

回答1:


This is because a change in cassandra client to notifies high-level client apps that are using CQL3 implementation improperly. See https://issues.apache.org/jira/browse/CASSANDRA-5172

It seems that Astyanax either did not upgrade to this version of the cassandra client or they did not document the I'm currently looking myself for a solution at this moment.




回答2:


I got this working using Astyanax 1.56.31. You need to set the following in your AstyanaxConfigurationImpl instance:

.setTargetCassandraVersion("1.2")
.setCqlVersion("3.0.0")


来源:https://stackoverflow.com/questions/14579731/cassandra-cql3-support-in-astyanax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!