使用自定义聚合函数执行查询时,我有时会在Java驱动程序中获得com.datastax.driver.core.exceptions。 CodecNotFoundException 异常。
聚合函数的结果是一个映射。我希望Java API能有一个标准类型映射的编解码器。
cqlsh还报告错误"无法格式化值OrderedMapSerializedKey",但以JSON格式显示数据。
最终的功能是:
CREATE OR REPLACE FUNCTION average_by_source_final_1( state avg_type_1)
CALLED ON NULL INPUT
RETURNS map<text,double>
LANGUAGE java
...
汇总是:
CREATE OR REPLACE AGGREGATE avg_by_source( text, double)
SFUNC average_by_source_1
STYPE avg_type_1
FINALFUNC average_by_source_final_1
INITCOND ((null, 0, 0.0), null)
;
我假设最终函数的返回类型需要编解码器,而不是STYPE。
Java的例外:
execution of 'average_by_source_1[avg_type_1, text, double]' failed: com.datastax.driver.core.exceptions.CodecNotFoundException
... com.datastax.driver.core.exceptions.FunctionExecutionException: execution of 'roger_ts_08.average_by_source_1[avg_type_1, text, double]' failed: com.datasta
x.driver.core.exceptions.CodecNotFoundException
at com.datastax.driver.core.exceptions.FunctionExecutionException.copy(FunctionExecutionException.java:58)
at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37)
at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:245)
at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:64)
at com.brocade.tspoc.CassandraDb.aggregateWithAggrFunc(CassandraDb.java:309)
at com.brocade.tspoc.Main.aggregateWithAggrFuncTest(Main.java:223)
at com.brocade.tspoc.Main.main(Main.java:42)
Caused by: com.datastax.driver.core.exceptions.FunctionExecutionException: execution of 'average_by_source_1[avg_type_1, text, double]' failed: com.datastax.driver.core.exceptions.CodecNotFoundException
at com.datastax.driver.core.Responses$Error.asException(Responses.java:130)
at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:174)
at com.datastax.driver.core.RequestHandler.access$2600(RequestHandler.java:43)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:793)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:627)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1012)
在cqlsh中:
avg_by_source(source, value)
----------------------------------------------------------------------------------------------------
OrderedMapSerializedKey([(u'i1', 23.5), (u'i2', 1.2), (u's1', 50.0), (u's2', 15.0), (u's3', 8.0)])
(1 rows)
Failed to format value OrderedMapSerializedKey([(u'i1', 23.5), (u'i2', 1.2), (u's1', 50.0), (u's2', 15.0), (u's3', 8.0)]) : 'NoneType' object has no attribute 'sub_types'
答案 0 :(得分:0)
这只是部分答案。对于大型数据集,我经常在Java客户端和cqlsh中获得CodecNotFoundException。
我的部分问题是基于不正确的期望。我原以为结果将作为行返回,每个映射条目都是一行。但查询结果是包含地图的单行。
阅读结果的代码是:
Map<String,Double> map = queryResults.one().getMap( 0, String.class, Double.class);