cassandra-spring 摄取命令不起作用

cassandra-spring ingest command doesn't work

我已经设置了一个 cassandra 集群并使用 spring-cassandra 框架 1.53。 (http://docs.spring.io/spring-data/cassandra/docs/1.5.3.RELEASE/reference/html/)

我想将数百万个数据集写入我的 cassandra 集群。使用 executeAsync 的解决方案效果很好,但来自 spring 框架的 "ingest" 命令听起来也很有趣。

The ingest method takes advantage of static PreparedStatements that are only prepared once for performance. Each record in your data set is bound to the same PreparedStatement, then executed asynchronously for high performance.

我的代码:

List<List<?>> session_time_ingest = new ArrayList<List<?>>();
for (Long tokenid: listTokenID) {
List<Session_Time_Table> tempListSessionTimeTable = repo_session_time.listFetchAggregationResultMinMaxTime(tokenid);
session_time_ingest.add(tempListSessionTimeTable);
}

cassandraTemplate.ingest("INSERT into session_time (sessionid, username, eserviceid, contextroot," +
                " application_type, min_processingtime, max_processingtime, min_requesttime, max_requesttime)" +
                " VALUES(?,?,?,?,?,?,?,?,?)", session_time_ingest);

抛出异常:

`Exception in thread "main" com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [varchar <-> ...tracking.Tables.Session_Time_Table]
at com.datastax.driver.core.CodecRegistry.notFound(CodecRegistry.java:679)
at com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:540)
at com.datastax.driver.core.CodecRegistry.findCodec(CodecRegistry.java:520)
at com.datastax.driver.core.CodecRegistry.codecFor(CodecRegistry.java:470)
at com.datastax.driver.core.AbstractGettableByIndexData.codecFor(AbstractGettableByIndexData.java:77)
at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:201)
at com.datastax.driver.core.DefaultPreparedStatement.bind(DefaultPreparedStatement.java:126)
at org.springframework.cassandra.core.CqlTemplate.ingest(CqlTemplate.java:1057)
at org.springframework.cassandra.core.CqlTemplate.ingest(CqlTemplate.java:1077)
at org.springframework.cassandra.core.CqlTemplate.ingest(CqlTemplate.java:1068)
at ...tracking.SessionAggregationApplication.main(SessionAggregationApplication.java:68)`

我的编码与 spring-cassandra doku 完全一样。我不知道如何将我的对象的值映射到 cassandra 期望的值?!

您的 Session_Time_Table class 可能是映射的 POJO,但摄取方法不使用 POJO 映射。

相反,您需要提供一个矩阵,其中每行包含的参数与要在准备好的语句中绑定的变量一样多,类似于:

List<List<?>> rows = new ArrayList<List<?>>();

for (Long tokenid: listTokenID) {
    Session_Time_Table obj = ... // obtain a Session_Time_Table instance
    List<Object> row = new ArrayList<Object>();
    row.add(obj.sessionid);
    row.add(obj.username);
    row.add(obj.eserviceid);
    // etc. for all bound variables
    rows.add(row);
}

cassandraTemplate.ingest(
    "INSERT into session_time (sessionid, username, eserviceid, " +
    "contextroot, application_type, min_processingtime, " +
    "max_processingtime, min_requesttime, max_requesttime) " +
    "VALUES(?,?,?,?,?,?,?,?,?)", rows);