gpt4 book ai didi

java - 在cassandra中动态添加列

转载 作者:搜寻专家 更新时间:2023-10-31 20:11:08 25 4
gpt4 key购买 nike

我在 CQL3 中有一个这样的表

create table product_info
(
key text,
value text,
Primary key (key)
);

这是一个垂直表。因为我可以使用 (key , value ) 对插入新行。

示例数据将是:

产品信息

  key                |     value       
-------------------------------------------
product_name | sample_product
quantity | 2
manufacture | sample_manufacturer
.... ....

但我需要的是一个水平表格,我可以在其中动态添加列而无需更改表格。

产品信息

    product_name     |   quantity   |  manufacture           |  ....
------------------------------------------------------------------------------
sample_product | 2 | sample_manufacturer | ....

我需要像上表这样的结构,需要不断地动态添加列。

CQL3 提供了动态添加列的选项,但在此之前我们需要更改表。

我需要知道是否有任何其他方法可以做到这一点。

我发现通过使用 thrift api 是可能的,但是由于 thrift 不受更多支持,所以不能使用它。

是否有任何其他 API,如 hector 或其他支持此功能的 API?

我确实看过类似的堆栈溢出帖子,但我没有得到更好的解决方案。

最佳答案

CREATE TABLE product_info(
product_name text,
key text,
value text,
PRIMARY KEY (product_name, key)
);

现在您最多可以插入 2B 个 k/v 对,因为键现在是聚类列。

INSERT INTO product_info (product_name, key, value) 
VALUES ('iPhone 6', 'quantity', '2');

INSERT INTO product_info (product_name, key, value)
VALUES ('iPhone 6', 'manufacturer', 'Apple');

INSERT INTO product_info (product_name, key, value)
VALUES ('iPhone 6', 'quantity', '2');

INSERT INTO product_info (product_name, key, value)
VALUES ('iPhone 6', 'another column name', 'another column value');

但是,您没有指定查询访问模式,因此该数据模型对于您的应用程序可能是完全错误的(或正确的)。

关于java - 在cassandra中动态添加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27613035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com