在cassandra中动态添加列

Suj*_* PS 5 java thrift cassandra hector cassandra-cli

我在CQL3中有一个这样的表

create table product_info
(
 key text,
 value text,
 Primary key (key)
);
Run Code Online (Sandbox Code Playgroud)

这是一张垂直的桌子.因为我可以插入带有(键,值)对的新行.

样本数据将是:

产品的详细信息

  key                |     value       
  -------------------------------------------
  product_name       |   sample_product   
  quantity           |   2
  manufacture        |   sample_manufacturer   
  ....                   ....
Run Code Online (Sandbox Code Playgroud)

但我需要的是一个水平表,我可以在不改变表的情况下动态添加列.

产品的详细信息

    product_name     |   quantity   |  manufacture           |  ....
   ------------------------------------------------------------------------------    
    sample_product   |    2         |  sample_manufacturer   |  ....
Run Code Online (Sandbox Code Playgroud)

我需要像上表那样的结构,需要不断添加列.

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

我需要知道是否有任何其他方法允许这样做.

我发现通过使用thrift api是可能的,但由于不再支持thrift,所以不能使用它.

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

我确实经历了类似的堆栈溢出帖子,但我没有得到更好的解决方案.

Akb*_*med 5

CREATE TABLE product_info(
    product_name text,
    key text,
    value text,
    PRIMARY KEY (product_name, key)
);
Run Code Online (Sandbox Code Playgroud)

现在您最多可以插入 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');
Run Code Online (Sandbox Code Playgroud)

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