Java,适当的数据结构来表示列族

时间:2021-11-10 16:58:40

I am trying to find out the best data structure to represent a cassandra column family.

我试图找出代表cassandra列族的最佳数据结构。

My table schema is like this:

我的表架构是这样的:

create table IF NOT EXISTS test.test (
cname1 varchar,
cname2 varchar,
cname3 bigint,
cname4 bigint,
cname5 bigint,
cname6 boolean,
cname7 bigint,
......(70 more)
cnamex boolean,
PRIMARY KEY (cname1, cname2,cname3)
);

each column name has its own type like varchar bigint or boolean. In java, how to develop a neat data structure to represent such a table, and then I can easily access to a column name and also know its 'type', so that I can do other things against them like insert operation.

每个列名都有自己的类型,如varchar bigint或boolean。在java中,如何开发一个整洁的数据结构来表示这样一个表,然后我可以轻松访问一个列名并且也知道它的'type',这样我就可以对它们做其他的事情,比如插入操作。

Normally I will do something like this:

通常我会做这样的事情:

public class table{
    String cname1 = "cname1";
    String cname2 = "cname2";
    ......
}

But then I cannot know the type of each column.

但后来我不知道每列的类型。

1 个解决方案

#1


0  

Creating a simple POJO bean that you have shown above is good approach. If you want the type of the field at rune time then you can use reflection API.

创建一个上面显示的简单POJO bean是很好的方法。如果您希望符号时间的字段类型,则可以使用反射API。

#1


0  

Creating a simple POJO bean that you have shown above is good approach. If you want the type of the field at rune time then you can use reflection API.

创建一个上面显示的简单POJO bean是很好的方法。如果您希望符号时间的字段类型,则可以使用反射API。