Java 不使用自定义编解码器的Cassandra地图地图。可能的

Java 不使用自定义编解码器的Cassandra地图地图。可能的,java,cassandra,cassandra-3.0,Java,Cassandra,Cassandra 3.0,我正在将包含地图的地图存储在Cassandra表中: CREATE TABLE reportsdb.report ( report_id TEXT, entity_type TEXT, entity_id TEXT, parameters MAP<TEXT, FROZEN<MAP<TEXT, INT>>>, PRIMARY KEY ((report_id), entity_type, entity_id) ); CRE

我正在将包含地图的地图存储在Cassandra表中:

CREATE TABLE reportsdb.report (
    report_id TEXT,
    entity_type TEXT,
    entity_id TEXT,
    parameters MAP<TEXT, FROZEN<MAP<TEXT, INT>>>,
    PRIMARY KEY ((report_id), entity_type, entity_id)
);
CREATE TABLE reportsdb.report(
报告id文本,
实体类型文本,
实体id文本,
参数映射,
主键((报表id)、实体类型、实体id)
);
存储数据工作正常,没有任何问题。 在检索数据时(使用Java和datastax驱动程序),我希望执行以下操作:

resultSet.forEach(row -> {
        Map<String, Map> parametersMap = row.getMap("parameters", String.class, Map.class);
// Do something with the parametersMap here...
}
resultSet.forEach(行->{
Map参数Map=row.getMap(“参数”,String.class,Map.class);
//用这里的参数映射做点什么。。。
}
因为我无法获得泛型类型的类,所以需要定义

Map<String, Map>
Map<String, Map<String, Integer>>
Map
当我真的想定义的时候,我就把它投出去

Map<String, Map>
Map<String, Map<String, Integer>>
Map
但是,在运行上述代码时,我得到以下异常:

Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [map<varchar, int> <-> java.util.Map]
wildfly       |     at com.datastax.driver.core.CodecRegistry.notFound(CodecRegistry.java:741)
wildfly       |     at com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:594)
wildfly       |     at com.datastax.driver.core.CodecRegistry.findCodec(CodecRegistry.java:558)
wildfly       |     at com.datastax.driver.core.CodecRegistry.maybeCreateCodec(CodecRegistry.java:643)
wildfly       |     at com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:586)
wildfly       |     at com.datastax.driver.core.CodecRegistry.access$500(CodecRegistry.java:137)
wildfly       |     at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:246)
wildfly       |     at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:232)
wildfly       |     at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3542)
wildfly       |     at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2323)
wildfly       |     at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2286)
wildfly       |     at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
wildfly       |     at com.google.common.cache.LocalCache.get(LocalCache.java:3953)
wildfly       |     at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3957)
wildfly       |     at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4875)
wildfly       |     at com.datastax.driver.core.CodecRegistry.lookupCodec(CodecRegistry.java:522)
wildfly       |     at com.datastax.driver.core.CodecRegistry.codecFor(CodecRegistry.java:485)
wildfly       |     at com.datastax.driver.core.AbstractGettableByIndexData.codecFor(AbstractGettableByIndexData.java:73)
wildfly       |     at com.datastax.driver.core.AbstractGettableByIndexData.getMap(AbstractGettableByIndexData.java:338)
wildfly       |     at com.datastax.driver.core.AbstractGettableData.getMap(AbstractGettableData.java:26)
wildfly       |     at com.datastax.driver.core.AbstractGettableByIndexData.getMap(AbstractGettableByIndexData.java:327)
wildfly       |     at com.datastax.driver.core.AbstractGettableData.getMap(AbstractGettableData.java:26)
wildfly       |     at com.datastax.driver.core.AbstractGettableData.getMap(AbstractGettableData.java:231)
wildfly       |     at com.ericsson.sm.reports.slaReport.SlaReportDao.lambda$getReportsFromResultSet$2(SlaReportDao.java:111)
wildfly       |     at java.lang.Iterable.forEach(Iterable.java:75)
wildfly       |     at com.ericsson.sm.reports.slaReport.SlaReportDao.getReportsFromResultSet(SlaReportDao.java:105)
wildfly       |     at com.ericsson.sm.reports.common.AbstractDao.getReports(AbstractDao.java:38)
wildfly       |     at com.ericsson.sm.reports.common.AbstractService.getReports(AbstractService.java:65)
wildfly       |     at com.ericsson.sm.reports.slaReport.SlaReportRestService.getDeviceSlaReports(SlaReportRestService.java:49)
wildfly       |     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
wildfly       |     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
wildfly       |     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
wildfly       |     at java.lang.reflect.Method.invoke(Method.java:498)
wildfly       |     at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
wildfly       |     at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
wildfly       |     at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
wildfly       |     at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
wildfly       |     at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:406)
wildfly       |     ... 56 more
原因:com.datastax.driver.core.exceptions.codecontfoundexception:未找到请求操作的编解码器:[map java.util.map]
wildfly |位于com.datastax.driver.core.CodecRegistry.notFound(CodecRegistry.java:741)
wildfly |位于com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:594)
wildfly |位于com.datastax.driver.core.CodecRegistry.findCodec(CodecRegistry.java:558)
wildfly |位于com.datastax.driver.core.CodecRegistry.maybeCreateCodec(CodecRegistry.java:643)
wildfly |位于com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:586)
wildfly |位于com.datastax.driver.core.CodecRegistry.access$500(CodecRegistry.java:137)
wildfly |位于com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:246)
wildfly |位于com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:232)
wildfly |位于com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3542)
wildfly |位于com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2323)
wildfly |位于com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2286)
wildfly |位于com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
wildfly |位于com.google.common.cache.LocalCache.get(LocalCache.java:3953)
wildfly |位于com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3957)
wildfly |位于com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4875)
wildfly |位于com.datastax.driver.core.CodecRegistry.lookupCodec(CodecRegistry.java:522)
wildfly |位于com.datastax.driver.core.CodecRegistry.codecFor(CodecRegistry.java:485)
wildfly |位于com.datastax.driver.core.AbstractGettableByIndexData.codefor(AbstractGettableByIndexData.java:73)
wildfly |位于com.datastax.driver.core.AbstractGettableByIndexData.getMap(AbstractGettableByIndexData.java:338)
wildfly |位于com.datastax.driver.core.AbstractGettableData.getMap(AbstractGettableData.java:26)
wildfly |位于com.datastax.driver.core.AbstractGettableByIndexData.getMap(AbstractGettableByIndexData.java:327)
wildfly |位于com.datastax.driver.core.AbstractGettableData.getMap(AbstractGettableData.java:26)
wildfly |位于com.datastax.driver.core.AbstractGettableData.getMap(AbstractGettableData.java:231)
wildfly |位于com.ericsson.sm.reports.slaReport.SlaReportDao.lambda$getReportsFromResultSet$2(SlaReportDao.java:111)
wildfly | at java.lang.Iterable.forEach(Iterable.java:75)
wildfly |位于com.ericsson.sm.reports.slaReport.SlaReportDao.getReportsFromResultSet(SlaReportDao.java:105)
wildfly |位于com.ericsson.sm.reports.common.AbstractDao.getReports(AbstractDao.java:38)
wildfly |位于com.ericsson.sm.reports.common.AbstractService.getReports(AbstractService.java:65)
wildfly |位于com.ericsson.sm.reports.slaReport.slarreportrestservice.getDevicesLarreports(SlaReportRestService.java:49)
wildfly | at sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
wildfly | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
wildfly | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
wildfly | at java.lang.reflect.Method.invoke(Method.java:498)
wildfly |位于org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
wildfly |位于org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
wildfly |位于org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
wildfly |位于org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
wildfly |位于org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:406)
wildfly |…56更多
由于上述原因,必须实现自定义编解码器似乎有点奇怪

我是否遗漏了一些明显的东西?最干净的解决方案是什么


谢谢

通过改用类型标记修复了此问题:

Map<String, Map<String, Integer>> parametersMap = row
                .getMap("parameters", TypeToken.of(String.class), TypeTokens.mapOf(String.class, Integer.class));
Map参数Map=row
.getMap(“参数”,TypeToken.of(String.class),TypeTokens.mapOf(String.class,Integer.class));

考虑了
blob
和协议缓冲区还是什么?