在 Cassandra 中更改组合键
Changin Composite Key in Cassandra
我想更换我的 cassandra table。我知道如果我需要添加额外的主键,我必须创建另一个 table。比如我想把这个table
create table sample1 (
p1 int,
p2 timestamp,
c1 text,
c2 text,
c3 text,
c4 text,
x1 int,
x2 int,
x3 int
PRIMARY KEY((p1,p2),c1,c2,c3,c4)
);
进入这个table
create table sample1 (
p1 int,
p2 timestamp,
c1 text,
c2 text,
c3 text,
c4 text,
c5 text,
c6 text,
x1 int,
x2 int,
x3 int
PRIMARY KEY((p1,p2),c1,c2,c3,c4,c5,c6)
);
这种情况会再次发生,我将不得不再次改变这个table。
我正在考虑像这样创建 table。你认为这是最好的方法吗?或者有别的办法吗?
create table sample1 (
p1 int,
p2 timestamp,
combined_six_field text,
c1 text,
c2 text,
c3 text,
c4 text,
c5 text,
c6 text,
x1 int,
x2 int,
x3 int
PRIMARY KEY((p1,p2), combined_six_field)
);
您可以使用冻结地图作为聚类列。
示例:
CREATE TABLE sample1 (
p1 int,
p2 timestamp,
c frozen<map<text, text>>,
x1 int,
x2 int,
x3 int
PRIMARY KEY((p1,p2), c)
);
插入示例:
INSERT INTO sample1(pk1, pk2, c, x1, x2, x3) VALUES (
1,
toTimestamp(now()),
{'c1' : 'v1', 'c2' : 'v2', 'c3' : 'v3'},
10,
100,
1000
);
INSERT INTO sample1(pk1, pk2, c, x1, x2, x3) VALUES (
2,
toTimestamp(now()),
{'c1' : 'v1', 'c2' : 'v2', 'c3' : 'v3', 'c4' : 'v4', 'c5' : 'v5', 'c6' : 'v6'},
20,
200,
2000
);
我想更换我的 cassandra table。我知道如果我需要添加额外的主键,我必须创建另一个 table。比如我想把这个table
create table sample1 (
p1 int,
p2 timestamp,
c1 text,
c2 text,
c3 text,
c4 text,
x1 int,
x2 int,
x3 int
PRIMARY KEY((p1,p2),c1,c2,c3,c4)
);
进入这个table
create table sample1 (
p1 int,
p2 timestamp,
c1 text,
c2 text,
c3 text,
c4 text,
c5 text,
c6 text,
x1 int,
x2 int,
x3 int
PRIMARY KEY((p1,p2),c1,c2,c3,c4,c5,c6)
);
这种情况会再次发生,我将不得不再次改变这个table。
我正在考虑像这样创建 table。你认为这是最好的方法吗?或者有别的办法吗?
create table sample1 (
p1 int,
p2 timestamp,
combined_six_field text,
c1 text,
c2 text,
c3 text,
c4 text,
c5 text,
c6 text,
x1 int,
x2 int,
x3 int
PRIMARY KEY((p1,p2), combined_six_field)
);
您可以使用冻结地图作为聚类列。
示例:
CREATE TABLE sample1 (
p1 int,
p2 timestamp,
c frozen<map<text, text>>,
x1 int,
x2 int,
x3 int
PRIMARY KEY((p1,p2), c)
);
插入示例:
INSERT INTO sample1(pk1, pk2, c, x1, x2, x3) VALUES (
1,
toTimestamp(now()),
{'c1' : 'v1', 'c2' : 'v2', 'c3' : 'v3'},
10,
100,
1000
);
INSERT INTO sample1(pk1, pk2, c, x1, x2, x3) VALUES (
2,
toTimestamp(now()),
{'c1' : 'v1', 'c2' : 'v2', 'c3' : 'v3', 'c4' : 'v4', 'c5' : 'v5', 'c6' : 'v6'},
20,
200,
2000
);