Cassandra 动态列族 [英] Cassandra dynamic column family

查看:58
本文介绍了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');

并选择所有列:

select * from xxxx where id = 1;

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

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