如何在Cassandra中存储自定义对象?

时间:2019-05-21 06:29:05

标签: spring-boot cassandra

我有以下需要存储在Cassandra中的对象。我需要使用UDT还是有其他方法存储对象?我最终需要使用存储库方法从spring-boot应用程序中存储它。

{
    "name": "Krishna",
    "age" : 24,
    "address" : [
        {
            "attributes" : [
                {
                    "name": "",
                    "value" : ""
                }
            ],
            "contactnumbers" : [ "123123234", "123456"]
        }
    ],
    "devices" : [
        "android_pixel",
        "ios_6s"
    ]
}

1 个答案:

答案 0 :(得分:1)

我认为,您需要在此处使用UDT。我可以提出这个。

CREATE TYPE attribute_info (
    name text,
    value text
);

CREATE TYPE address_info (
    attributes list<frozen<attribute_info>>,
    contactnumbers list<text> 
);

CREATE TYPE user_info (
    name text,
    age int,
    address list<frozen<address_info>>,
    devices list<text>
);

一旦user_info下有key space,在创建或更改表时将其用作列的类型。

相关问题