我在使用 Cassandra Java Driver
获取包含 map 的列表时遇到问题。
对于以下版本:
List<Map<Integer, Integer>> myList = state.getList(5, TypeTokens.mapOf(Integer.class, Integer.class));
错误如下:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Java source compilation failed: Line 3: TypeTokens cannot be resolved"
对于如下版本:
List<Map<Integer, Integer>> myList = state.getList(5 , Map.class);
错误如下:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Java source compilation failed: Line 3: Type mismatch: cannot convert from List<Map> to List<Map<Integer,Integer>>
对于最后一个版本,如下所示:
List<Map> myList = state.getList(5, Map.class);
编译器不会提示,但是当我执行聚合时,错误如下:
FunctionFailure: Error from server: code=1400 [User Defined Function failure] message="execution of 'my_keyspace.count_min_udf[count_min_udt, int, int, text]' failed: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [frozen<map<int, int>> <-> java.util.Map]"
state
是一个 UDT,定义为:
CREATE TYPE count_min_udt(
n int,
m int,
p bigint,
hash_a list <bigint>,
hash_b list <bigint>,
values list<frozen <map<int, int>>>
);
我用错了吗?我希望得到一些帮助
最佳答案
答案可以在这里找到: https://community.datastax.com/questions/3939/how-can-i-access-nested-collections-with-the-java.html
关于java - 如何使用 Cassandra Java 驱动程序访问带有嵌套映射的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61657750/