我有一个复杂的JSON,我想在Cassandra中推送,我会有问题和选项的映射。我应该在Cassandra设计我的表吗?我的表架构应该是什么?
insert into questions_options JSON'{
"qid": "12736467",
"chapter_id": "12",
"subject_id": 19482065,
"topic_id": 216.28,
"type": "picked",
"content": "on time",
"difficulty": 1,
"marks": 12,
"hint": "do something",
"explanations": "do something dude",
"created_by": 1232,
"create_on": "2013-06-10",
"options": [
{
"option_id": 1,
"option_text": "ACBD",
"sort_order": 1,
"correct_option": true
},
{
"option_id": 2,
"option_text": "bcdd",
"sort_order": 2,
"correct_option": true
}
]
}'
我写了下面的创建表查询。是吗?
create table questions_options (
qid bigint,
chapter_id bigint,
subject_id int,
topic_id int,
class varchar,
type varchar,
content text,
difficulty tinyint,
marks int,
hint text,
explanations text,
created_by bigint,
create_on timestamp,
option_id bigint,
option_text text,
sort_order int,
correct_option boolean,
PRIMARY KEY((qid), option_id)
);
答案 0 :(得分:1)
在Cassandra中,您必须按照要查询的方式设计表格,而不是要插入的表格。
顺便说一句,你问的是支持你的json的表格是什么。
以下是转换方式:
对于你的json,这将是架构:
CREATE TYPE option (
option_id bigint,
option_text text,
sort_order int,
correct_option boolean
);
CREATE TABLE questions_options (
qid bigint PRIMARY KEY,
chapter_id bigint,
class text,
content text,
create_on date,
created_by bigint,
difficulty int,
explanations text,
hint text,
marks int,
options list<frozen<option>>,
subject_id int,
topic_id double,
type text
);