Dynamically add columns to cassandra

I have such a table in CQL3

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

This is a vertical table. Since I can insert new lines with (key, value).

Example data will be:

PRODUCT_INFO

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

But I need a horizontal table where I could dynamically add columns without changing the table.

PRODUCT_INFO

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

I need a structure similar to the above table, I need to continue to add columns on the fly.

CQL3 provides the ability to dynamically add columns, but before that we need to modify the table.

I need to know if there is another way that allows this.

I found that using trift api is possible, but since thrift is no longer supported, I cannot use it.

Is there any other API like hector or something else that supports this?

I went through similar entries, but I did not get a better solution.

+5
source share
2 answers
 CREATE TABLE product_info( product_name text, key text, value text, PRIMARY KEY (product_name, key) ); 

Now you can insert up to 2B k / v pairs, because the key is now a clustering column.

 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'); 

However, you did not specify request access patterns, so this data model may be completely wrong (or good) for your application.

+3
source

Have you considered using a map?

 create table products( id text primary key, something text, attributes map<text, text> ); 

See the end of http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_collections_c.html

0
source

Source: https://habr.com/ru/post/1209746/


All Articles