我正在尝试Cassandra,我仍然试图将我的大脑转换为基于列的逻辑。
我看了几个视频并试图模仿他们谈论的内容......视频存储,天气信息等,但我一直都会遇到错误。
服务器出错:代码= 2200 [查询无效] message =“未知 PRIMARY KEY中引用的定义postid“
来自服务器的错误:code = 2200 [无效查询] message =“缺少列的CLUSTERING ORDER 帖子ID“
我只尝试过用户,标签和帖子。我很容易想象有些事情我不明白。
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);
有人可以解释我不理解的内容吗?缺陷在哪里?
答案 0 :(得分:0)
您的查询中存在多个严重错误,无效的列定义:以下是其中一些:
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);
此处 WITH CLUSTERING ORDER BY(createdAt DESC); createdAt
列不是群集密钥。它应该是 postId 。
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);
此处 message_id 不存在,应为 messageId 。
同样的事情也发生在媒体上:
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);
channel_id,message_id 不存在。
我猜你已经知道你做错了什么。现在仔细查找其他拼写错误并修复它们。