Cassandra 2.1 data query syntax.

Source: Internet
Author: User
Tags cassandra datastax

1, Official document, basic typedata Query Language documentation:http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/update_r.html

data types supported by CQL:Compared to MySQL, there are several types of interesting,uuid type, map,list,set type, this optimization association query, directly to the list into a record.
CQL Type Constants Description
Ascii Strings Us-ascii character string
bigint Integers 64-bit signed Long
Blob BLOBs Arbitrary bytes (no validation), expressed as hexadecimal
Boolean Booleans True or False
Counter Integers Distributed counter Value (64-bit long)
Decimal integers, floats Variable-precision Decimal

Java type

Double Integers 64-bit IEEE-754 floating point

Java type

Float integers, floats 32-bit IEEE-754 floating point

Java type

inet Strings IP address string in IPV4 or IPV6 format, used by the PYTHON-CQL driver and CQL native protocols
Int Integers 32-bit signed integer
List N/A A collection of one or more ordered elements
Map N/A A Json-style Array of literals: {literal:literal, literal:literal ...}
Set N/A A collection of one or more elements
Text Strings UTF-8 encoded string
Timestamp Integers, strings Date plus time, encoded as 8 bytes since epoch
Timeuuid UUIDs Type 1 UUID only
Tuple N/A Cassandra 2.1 and later. A Group of 2-3 fields.
Uuid UUIDs A uuid in the standard UUID format
varchar Strings UTF-8 encoded string
Varint Integers Arbitrary-precision integer

Java type


data types supported by Java:
CQL type java type
decimal
float
double
varint
In this topic:
    • Blob type
    • Collection type
    • Counter type
    • UUID and Timeuuid types
    • UUID and TIMEUUID functions
    • Timestamp type
    • Tuple type
    • user-defined type
2, view, create keyspace, data sheetThe View command is similar to MySQL.
Desc cluster;desc keyspaces;desc keyspace portfoliodemo;desc tables;desc table stocks;
Create Keyspace: Default to make Simplestrategy copy type.
Create a keyspace.cqlsh> Create Keyspace demodb with REPLICATION = {' class ': ' Simplestrategy ', ' replication_factor ': 1} and durable_writes = true; Use the keyspace.cqlsh> use Demodb;
To create a data table:
CREATE TABLE users (userid uuid PRIMARY KEY, first_name text, last_name text, emails set<text>, Top_scores lis T<int>, Todo Map<timestamp, text>, create_time timestamp);

Cassandra has a feature is the bottom of the distributed, so the query sort of time limit is more.to create a time flashback query according to the user, you must write the table again when you create it.
CREATE TABLE users (  userid uuid PRIMARY KEY,  first_name text,  last_name text,  emails set<text>,< C7/>top_scores list<int>,  todo Map<timestamp, text>,  create_time timestamp  PRIMARY KEY ( UserID, Create_time)) with Clustering ORDER by (Create_time DESC);

The default definition of the time sequence, flashbacks need to be redefined, and put this field into the primary key.Reference: Http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/refClstrOrdr.html
The Update table structure is similar to MySQL:
Alter TABLE users alter bio TYPE text;
3, inserting data, updatingsimilar to MYSQ: where emails is a set type.
INSERT into Users (userid, first_name, last_name, emails)  VALUES (cfd66ccc-d857-4e90-b1e5-df98a3d40cd6, ' Frodo ', ' Baggins ', {' [email protected] ', ' [email protected] '};

Update data to compare special time List,map,set types:other similar, refer to http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/update_r.html
Add emails data: Use + UPDATE users SET emails = emails + {' [email protected] '} WHERE userid = cfd66ccc-d857-4e90-b1e5-df98a3d40cd 6. Delete emails data: Use-UPDATE users SET emails = emails-{' [email protected] '} WHERE userid = Cfd66ccc-d857-4e90-b1e5-df98a3d40 cd6; empty emails data: use {} UPDATE users SET emails = {} WHERE userid = Cfd66ccc-d857-4e90-b1e5-df98a3d40cd6;
4. Querying data
Number of Queries Select COUNT (*) from users; query Top 10 SELECT * from users LIMIT, allow FILTERING; query by token select * from users WHERE token (userid) >= token (CFD66CCC-D857-4E90-B1E5-DF98A3D40CD6); Check token content, token can only be primary key. SELECT TOKEN (userid) from the Users WHERE token (userid) >= token (CFD66CCC-D857-4E90-B1E5-DF98A3D40CD6);

It also supports queries such as distinct,in, but does not support associated queries, after all, it is not a relational database.



Cassandra 2.1 data query syntax.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.