在使用 Datastax API(使用新的二进制协议)时在 Cassandra 中创建列族或表 [英] Creating column family or table in Cassandra while working Datastax API(which uses new Binary protocol)

查看:20
本文介绍了在使用 Datastax API(使用新的二进制协议)时在 Cassandra 中创建列族或表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用 Cassandra 数据库.我打算使用 Datastax API 来更新/读入/从 cassandra 数据库读取.我对这个 Datastax API(它使用新的二进制协议)完全陌生,我也找不到很多包含一些适当示例的文档.

I have started working with Cassandra database. I am planning to use Datastax API to upsert/read into/from cassandra database. I am totally new to this Datastax API (which uses new Binary protocol) and I am not able to find lot of documentations as well which have some proper examples.

当我使用 Netflix 客户端(Astyanax 客户端)使用 Cassandra CLI 时,我创建了这样的列族-

When I was working with Cassandra CLI using the Netflix client(Astyanax client), then I created the column family like this-

create column family profile
with key_validation_class = 'UTF8Type'
and comparator = 'UTF8Type'
and default_validation_class = 'UTF8Type'
and column_metadata = [
  {column_name : crd, validation_class : 'DateType'}
  {column_name : lmd, validation_class : 'DateType'}
  {column_name : account, validation_class : 'UTF8Type'}
  {column_name : advertising, validation_class : 'UTF8Type'}
  {column_name : behavior, validation_class : 'UTF8Type'}
  {column_name : info, validation_class : 'UTF8Type'}
  ];

现在我尝试使用 Datastax API 做同样的事情.因此,要开始使用 Datastax API,我是否需要以上述不同的方式创建列族?或者,每当我尝试使用 Datastax API 将数据插入到 Cassandra 数据库中时,上面的列族都可以正常工作.

Now I was trying to do the same thing using Datastax API. So to start working with Datastax API, do I need to create the column family in some different way as mentioned above? Or the above column familiy will work fine whenever I will try to insert data into Cassandra database using Datastax API.

如果上面的列族不起作用那么-

If the above column family will not work then-

首先,我创建了如下所示的 KEYSPACE-

First of all I have created the KEYSPACE like below-

CREATE KEYSPACE USERS WITH strategy_class = 'SimpleStrategy' AND strategy_options:replication_factor = '1';

现在我很困惑如何创建表?我不确定哪种方法是正确的?

Now I am confuse how to create the table? I am not sure which is the right way to do that?

我应该这样创作吗?

创建表配置文件(id varchar,帐户变量,广告varchar,行为变量,信息变量,主键 (id));

还是我应该像这样创建?

or should I create like this?

创建列族配置文件(id varchar,帐户变量,广告varchar,行为变量,信息变量,主键 (id));

以及如何添加-

crd as DateType
lmd as DateType

在使用 Datastax API 时在上表或列族中?

in above table or column family while working with Datastax API?

任何帮助将不胜感激.

推荐答案

无论您使用关键字TABLE 还是COLUMNFAMILY,两者都是相同的(同义词).我猜关键字 TABLE 是在 CQL3 中引入的.所以你可以在你的语句中使用任何一个.

Whether you use the keyword TABLE or COLUMNFAMILY, both are the same (synonyms). I guess the keyword TABLE was introduced with CQL3. So you can use either one in your statements.

第二个问题,添加DateType,应该使用timestamp.

Second question, adding DateType, you should use timestamp.

CREATE COLUMNFAMILY sample (rowkey text, ts timestamp, PRIMARY KEY(rowkey));

INSERT INTO sample (rowkey, ts ) VALUES ( '1','1366354711797');
// ts value is basically the System.currentTimeMillis(), I mean a long value

这篇关于在使用 Datastax API(使用新的二进制协议)时在 Cassandra 中创建列族或表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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