2017-05-31 87 views
0

我建立了一个cassandra集群,并使用spring-cassandra框架1.53。 (http://docs.spring.io/spring-data/cassandra/docs/1.5.3.RELEASE/reference/html/cassandra-spring ingest命令不起作用

我想将数百万数据集写入我的cassandra集群。 executeAsync的解决方案效果很好,但spring框架中的“摄取”命令听起来也很有趣。

摄取方法利用静态的PreparedStatements,这些静态PreparedStatements仅为性能准备一次。数据集中的每条记录都绑定到相同的PreparedStatement,然后异步执行以获得高性能。

我的代码:

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)` 

我的编码完全一样的弹簧卡珊德拉数独..我不知道怎么的值映射我反对卡桑德拉期待的价值观?

回答

1

您的Session_Time_Table类可能是映射的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); 
+0

谢谢!完美的作品 –