标签:cassandra
| 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 standard UUID format |
| varchar | strings | UTF-8 encoded string |
| varint | integers | Arbitrary-precision integer Java type |
| CQL type | Java type |
|---|---|
| decimal | java.math.BigDecimal |
| float | java.lang.Float |
| double | java.lang.Double |
| varint | java.math.BigInteger |
desc cluster;
desc keyspaces;
desc keyspace portfoliodemo;
desc tables;
desc table stocks;创建keyspace: 默认制定SimpleStrategy的副本类型。Create a keyspace.
cqlsh> CREATE KEYSPACE demodb WITH REPLICATION = { ‘class‘ : ‘SimpleStrategy‘, ‘replication_factor‘ : 1 } AND durable_writes = true;
Use the keyspace.
cqlsh> USE demodb;创建数据表:CREATE TABLE users ( userid uuid PRIMARY KEY, first_name text, last_name text, emails set<text>, top_scores list<int>, todo map<timestamp, text>, create_time timestamp );
CREATE TABLE users ( userid uuid PRIMARY KEY, first_name text, last_name text, emails set<text>, top_scores list<int>, todo map<timestamp, text>, create_time timestamp PRIMARY KEY (userid, create_time) ) WITH CLUSTERING ORDER BY (create_time DESC);
ALTER TABLE users ALTER bio TYPE text;
INSERT INTO users (userid, first_name, last_name, emails)
VALUES(cfd66ccc-d857-4e90-b1e5-df98a3d40cd6 , ‘Frodo‘, ‘Baggins‘, {‘f@baggins.com‘, ‘baggins@gmail.com‘});增加emails数据:使用+
UPDATE users SET emails = emails + {‘fb@friendsofmordor.org‘} WHERE userid = cfd66ccc-d857-4e90-b1e5-df98a3d40cd6;
删除emails数据:使用-
UPDATE users SET emails = emails - {‘fb@friendsofmordor.org‘} WHERE userid = cfd66ccc-d857-4e90-b1e5-df98a3d40cd6;
清空emails数据:使用{}
UPDATE users SET emails = {} WHERE userid = cfd66ccc-d857-4e90-b1e5-df98a3d40cd6;查询数量 SELECT COUNT(*) FROM users; 查询前10条 SELECT * FROM users LIMIT 10 ALLOW FILTERING; 按照token查询 SELECT * FROM users WHERE TOKEN(userid) >= TOKEN(cfd66ccc-d857-4e90-b1e5-df98a3d40cd6); 查询token内容,token只能是primary key。 SELECT TOKEN(userid) FROM users WHERE TOKEN(userid) >= TOKEN(cfd66ccc-d857-4e90-b1e5-df98a3d40cd6);
标签:cassandra
原文地址:http://blog.csdn.net/freewebsys/article/details/41595353