如何在查询时将cassandra列值转换为相应的枚举

如何在查询时将cassandra列值转换为相应的枚举,cassandra,cql,Cassandra,Cql,我们有一个int类型的cassandra列,int的这个值对应于一个enum的值,有没有办法在查询时将这个int列转换为enum字符串。在CQL本身中不可能进行转换,但是Java驱动程序通过使用EnumOrdinalCodec类(文档中的示例)来支持: enum状态{INIT,RUNNING,STOPPING,STOPPED} cluster.getConfiguration().getCodecRegistry() .register(新的EnumOrdinalCodec(State.clas

我们有一个int类型的cassandra列,int的这个值对应于一个enum的值,有没有办法在查询时将这个int列转换为enum字符串。

在CQL本身中不可能进行转换,但是Java驱动程序通过使用
EnumOrdinalCodec
类(文档中的示例)来支持:

enum状态{INIT,RUNNING,STOPPING,STOPPED}
cluster.getConfiguration().getCodecRegistry()
.register(新的EnumOrdinalCodec(State.class));
//模式:创建表序号示例(id int主键,state int)
session.execute(“插入序数_示例(id,state)值(1),”,state.INIT);
enum State {INIT, RUNNING, STOPPING, STOPPED}

cluster.getConfiguration().getCodecRegistry()
        .register(new EnumOrdinalCodec<State>(State.class));

// schema: create table ordinal_example(id int PRIMARY KEY, state int)
session.execute("insert into ordinal_example (id, state) values (1, ?)", State.INIT);