Cassandra动态柱系列 [英] Cassandra dynamic column family

查看:153
本文介绍了Cassandra动态柱系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是cassandra的新手,并且阅读了一些有关静态和动态列系列的文章. 提到,从Cassandra 3的表和列族是相同的.

I am new to cassandra and I read some articles about static and dynamic column family. It is mentioned ,From Cassandra 3 table and column family are same.

我创建了键空间,一些表并将数据插入到该表中.

I created key space, some tables and inserted data into that table.

CREATE TABLE subscribers(
 id uuid,
 email text,
 first_name text,
 last_name text,
 PRIMARY KEY(id,email)
);

INSERT INTO subscribers(id,email,first_name,last_name) 
    VALUES(now(),'Test@123.com','Test1','User1');
INSERT INTO subscribers(id,email,first_name,last_name) 
    VALUES(now(),'Test2@222.com','Test2','User2');
INSERT INTO subscribers(id,email,first_name,last_name) 
    VALUES(now(),'Test3@333.com','Test3','User3');

一切似乎都很好.

但是我需要创建一个仅包含数据类型而没有预定义列的动态列族.

But what I need is to create a dynamic column family with only data types and no predefined columns.

使用插入查询,我可以有不同的参数,并且应该插入表.

With insert query I can have different arguments and the table should be inserted.

在文章中提到,对于动态列族,无需创建架构(预定义列). 我不确定在cassandra中是否可行,或者我的理解是错误的.

In articles, it is mentioned ,for dynamic column family, there is no need to create a schema(predefined columns). I am not sure if this is possible in cassandra or my understanding is wrong.

让我知道这是否可行吗? 如果可能的话,请提供一些示例.

Let me know if this is possible or not? if possible Kindly provide with some examples.

谢谢.

推荐答案

我认为您所引用的文章是在Cassandra的前几年编写的,当时它是基于Thrift协议的. Cassandra查询语言是在多年前引入的,现在它成为了与Cassandra一起使用的方式-Thrift在Cassandra 3.x中已弃用,而在4.0(尚未发布)中已完全删除.

I think that articles that you're referring where written in the first years of Cassandra, when it was based on the Thrift protocols. Cassandra Query Language was introduced many years ago, and now it's the way to work with Cassandra - Thrift is deprecated in Cassandra 3.x, and fully removed in the 4.0 (not released yet).

如果您确实需要完全动态的内容,则可以尝试使用带有列的表作为从文本到特定类型的映射的表来进行模拟,例如:

If you really need to have fully dynamic stuff, then you can try to emulate this by using table with columns as maps from text to specific type, like this:

create table abc (
  id int primary key,
  imap map<text,int>,
  tmap map<text,text>,
  ... more types
);

但是您需要小心-使用集合时会有局限性和性能影响,特别是如果您要存储数百个以上的元素.

but you need to be careful - there are limitations and performance effects when using collections, especially if you want to store more then hundreds of elements.

另一种方法是将数据存储为单独的行:

another approach is to store data as individual rows:

create table xxxx (
  id int,
  col_name text,
  ival int,
  tval text,
  ... more types
  primary key(id, col_name));

然后您可以将各个值插入为单独的列:

then you can insert individual values as separate columns:

insert into xxxx(id, col_name, ival) values (1, 'col1', 1);
insert into xxxx(id, col_name, tval) values (1, 'col2', 'text');

,然后将所有列选择为:

and select all columns as:

select * from xxxx where id = 1;

这篇关于Cassandra动态柱系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆