Creating column family or table in Cassandra while working Datastax API(which uses new Binary protocol)

北城以北 提交于 2019-11-30 21:08:37
abhi

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.

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

In cassandra keyspace or database are same,like wise columnfamily and table are just same.

Cassandra is more like Mysql In its syntax and supports hql(similar to sql)

A table in cassandra can be created like:

CREATE TABLE users (
user_name varchar,
password varchar,
gender varchar,
session_token varchar,
state varchar,
birth_year bigint,
PRIMARY KEY (user_name));

More information here : Cassandra Tutorials

@neel4soft - With Cassandra things simply evolve. Therefore in order to be a kind of easier for people, steadily a renaming process is ongoing to make the transition from SQL to CQL easier for newbies. However CQL should not be thought of like being a relative to SQL, rather like a 3rd cousin from the side of it's mother, in other words not a close relative. Therefor comparing it to MySQL is an improper image of it's capabilities.

There are few differences while creating table/ colomn family using cassandra-cli and cqlsh.

One of them is, using cassandra-cli if we create table, it will create with compact storage format which is unable to alter further.

In cqlsh, it will not be created in this format unless we mention specifically while created the table/colomn family.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!