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

查看:116
本文介绍了在工作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.

当我正在使用Cassandra CLI使用Netflix客户端(Astyanax客户端),然后我创建了这样的列系列 -

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,我需要用上面提到的一些不同的方式创建列族吗?

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?

我应该这样创建吗?

code> CREATE TABLE profile(
id varchar,
account varchar,
advertising varchar,
behavior varchar,
info varchar,
PRIMARY KEY (id)
);

CREATE TABLE profile ( id varchar, account varchar, advertising varchar, behavior varchar, info varchar, PRIMARY KEY (id) );

还是我应该这样创建?

CREATE COLUMN FAMILY个人资料(
id varchar,
account varchar,
advertising varchar,
behavior varchar,
info varchar,
PRIMARY KEY(id)
);

还有如何添加 -

crd as DateType
lmd as DateType


$ b

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

任何帮助将不胜感激。

推荐答案

无论您使用关键字 TABLE 还是 COLUMNFAMILY ,两者都是相同的(同义词)。我想用CQL3引入了关键字 TABLE

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,应该使用时间戳。

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天全站免登陆