【发布时间】:2018-10-16 17:22:25
【问题描述】:
我正在尝试 Cassandra,但我仍在尝试将我的大脑切换到这种基于列的逻辑。
我看过几个视频,并试图模仿他们谈论的内容...视频存储、天气信息等,但我不断收到错误。
来自服务器的错误:code=2200 [Invalid query] message="Unknown PRIMARY KEY 中引用的定义 postid"
来自服务器的错误:代码 = 2200 [无效查询] 消息 =“缺少列的 CLUSTERING ORDER postid”
我只尝试了用户、标签和帖子。我可以很容易地想象出我不明白的地方。
CREATE TABLE users(
userId uuid,
login map<int, text>,
email text,
phoneNumber text,
emailVerified boolean,
phoneNumberVerified boolean,
firstName text,
lastName text,
gender text,
country text,
region text,
city text,
cityId int,
zipcode text,
password text,
passwordSetDate timestamp,
createdAt timestamp,
PRIMARY KEY ((email, phoneNumber, userId), lastName, createdAt)
);
CREATE TABLE tags(
tag text,
itemId uuid,
itemType text,
createdAt timestamp,
PRIMARY KEY ((tag), itemId)
);
CREATE TABLE posts(
postId uuid,
authorId uuid,
authorName text,
content text,
tags set<text>,
createdAt timestamp,
PRIMARY KEY ((authorId, postId), createdAt)
) WITH CLUSTERING ORDER BY (createdAt DESC);
CREATE TABLE comments(
commentId uuid,
postId uuid,
authorName text,
authorId uuid,
content text,
createdAt timestamp,
PRIMARY KEY ((authorId), postId)
) WITH CLUSTERING ORDER BY (createdAt DESC);
CREATE TABLE messages(
channelId uuid,
messageId uuid,
authorId uuid,
authorName text,
content text,
tags set<text>,
time timeuuid,
createdAt Timestamp,
PRIMARY KEY ((channelId, authorId), messageId)
) WITH CLUSTERING ORDER BY (message_id DESC);
CREATE TABLE channels(
channelId uuid,
content text,
createdAt Timestamp,
PRIMARY KEY ((channelId, authorId), messageId)
) WITH CLUSTERING ORDER BY (message_id DESC);
CREATE TABLE media(
mediaId uuid,
userId uuid,
userEmail text,
type text,
description text,
size text,
mime text,
tags set<text>,
createdAt Timestamp,
PRIMARY KEY ((channel_id), message_id)
) WITH CLUSTERING ORDER BY (message_id DESC);
CREATE TABLE loginLog(
eventId timeuuid,
login text,
createdAt timestamp,
status text,
ip inet,
PRIMARY KEY ((eventId, ip), message_id)
);
CREATE TABLE weatherByCities(
cityId int,
date text,
city text,
createdAt timestamp,
PRIMARY KEY ((cityId, date), createdAt)
) WITH CLUSTERING ORDER BY (createdAt DESC);
谁能解释一下我不明白的地方?缺陷在哪里?
【问题讨论】:
标签: sql database-design cassandra