简体   繁体   中英

DataStax Cassandra Exception: InvalidRequestException(why:there were 2 markers(?) in CQL but 3 bound variables

I followed the example here: https://github.com/apache/cassandra/blob/trunk/examples/hadoop_cql3_word_count/src/WordCount.java to write my own MR job which reads data from table A and writes the same data into table B. Both table A and B are stored in Cassandra, DataStax version.

My MR job has no problem to read all of the data and I could also write then to HDFS, but when I tried to write back to table B, it throws me the error:

attempt_201311051600_0300_r_000000_2: java.io.IOException: InvalidRequestException(why:there were 2 markers(?) in CQL but 3 bound variables)
attempt_201311051600_0300_r_000000_2:   at org.apache.cassandra.hadoop.cql3.CqlRecordWriter$RangeClient.run(CqlRecordWriter.java:248)
attempt_201311051600_0300_r_000000_2: Caused by: InvalidRequestException(why:there were 2 markers(?) in CQL but 3 bound variables)
attempt_201311051600_0300_r_000000_2:   at org.apache.cassandra.thrift.Cassandra$execute_prepared_cql3_query_result.read(Cassandra.java:41868)
attempt_201311051600_0300_r_000000_2:   at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
attempt_201311051600_0300_r_000000_2:   at org.apache.cassandra.thrift.Cassandra$Client.recv_execute_prepared_cql3_query(Cassandra.java:1689)
attempt_201311051600_0300_r_000000_2:   at org.apache.cassandra.thrift.Cassandra$Client.execute_prepared_cql3_query(Cassandra.java:1674)
attempt_201311051600_0300_r_000000_2:   at org.apache.cassandra.hadoop.cql3.CqlRecordWriter$RangeClient.run(CqlRecordWriter.java:232)

My prepare statement is:

String query = "UPDATE " + KEYSPACE + "." + OUT_COLUMN_FAMILY + " SET amt=?, good_desc='?' ";
CqlConfigHelper.setOutputCql(job.getConfiguration(), query);

I tried to print out the List in my reducer right before context.write(keys, variables); (variables is the List), and it really contained only 2 values, for example:

INFO  - 2013-11-07 15:43:36.683; poc.cassandra.mr.access.CassandraReducer; --> tx_id: 2577620422:10001372:debit
INFO  - 2013-11-07 15:43:36.684; poc.cassandra.mr.access.CassandraReducer; 0: 12919
INFO  - 2013-11-07 15:43:36.684; poc.cassandra.mr.access.CassandraReducer; 1: Express

It means you were trying to pass 3 parameters to your prepared statement while you only had two '?' placeholders. So you are passing more parameters than you got placeholders ready. That does also happen with named parameters unfortunately (they could simply ignore the non matching parameters which would be very handy sometimes).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM