1

我正在尝试选择一个整数值,但我不能这是我的代码:

cassandra_socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
cassandra_transport = boost::shared_ptr<TFramedTransport>(new TFramedTransport(cassandra_socket));
protocol = boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(cassandra_transport));
cassandra_client = new CassandraClient(protocol);
try {
    cassandra_transport->open();
    cassandra_client->set_keyspace("MPS");
    ColumnOrSuperColumn csc;
    ColumnPath cpath;
    cpath.column_family.assign("SubmitResposes_count");
    /* This is required - thrift 'feature' */
    cpath.__isset.column = true;
    cpath.column = "Counter";
    cassandra_client->get(csc, "1", cpath,org::apache::cassandra::ConsistencyLevel::ONE);
    cout << "Value read is '" << csc.column.value << "'..." << endl;
}
catch (NotFoundException &nf) {
    FORCE_TRACE(0, "NOT FOUND EXCEPTION ERROR: %s", nf.what());
} catch (InvalidRequestException &re) {
    FORCE_TRACE(0, "INVALID REQUEST ERROR: %s", re.why);
} catch (TException &tx) {
    FORCE_TRACE(0, "TEEXCEPTION ERROR: %s", tx.what());
}

它给了我这个例外: InvalidRequest ERROR: Expected 4 or 0 byte int (1)

&这是我创建的表:

create table SubmitResposes_count(
    ID int primary key,
    Counter bigint);
4

1 回答 1

0

您的密钥是一个 int:

ID int primary key,

但是您正在使用字符串键进行查询:

cassandra_client->get(csc, "1", cpath,org::apache::cassandra::ConsistencyLevel::ONE);
                           ^^^

Cassandra 正在尝试将您的字符串验证为 int,这导致了此异常。

于 2012-11-26T14:52:37.917 回答