天天看點

Cassandra 2.1 資料查詢文法。

資料查詢語言文檔:

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/update_r.html">http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/update_r.html</a>

cql 支援的資料類型:

相對于 mysql,有幾個類型比較有意思,uuid類型,map,list,set類型,這個優化關聯查詢,直接将list存入一條記錄。

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

distributed counter value (64-bit long)

decimal

integers, floats

variable-precision decimal

java type

double

64-bit ieee-754 floating point

float

32-bit ieee-754 floating point

inet

ip address string in ipv4 or ipv6 format, used by the python-cql driver and cql native protocols

int

32-bit signed integer

list

n/a

a collection of one or more ordered elements

map

a json-style array of literals: { literal : literal, literal : literal ... }

set

a collection of one or more elements

text

utf-8 encoded string

timestamp

integers, strings

date plus time, encoded as 8 bytes since epoch

timeuuid

uuids

type 1 uuid only

tuple

cassandra 2.1 and later. a group of 2-3 fields.

uuid

varchar

varint

arbitrary-precision integer

java支援的資料類型:

<a target="_blank" href="http://docs.oracle.com/javase/7/docs/api/java/math/bigdecimal.html">java.math.bigdecimal</a>

<a target="_blank" href="http://docs.oracle.com/javase/7/docs/api/java/lang/float.html">java.lang.float</a>

<a target="_blank" href="http://docs.oracle.com/javase/7/docs/api/java/lang/double.html">java.lang.double</a>

<a target="_blank" href="http://docs.oracle.com/javase/7/docs/api/java/math/biginteger.html">java.math.biginteger</a>

in this topic:

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/blob_r.html">blob type</a>

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/collection_type_r.html">collection type</a>

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/counter_type.html">counter type</a>

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/uuid_type_r.html">uuid and timeuuid types</a>

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/timeuuid_functions_r.html">uuid and timeuuid functions</a>

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/timestamp_type_r.html">timestamp type</a>

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/tupletype.html">tuple type</a>

<a target="_blank" href="http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/cqlrefudtype.html">user-defined type</a>

檢視指令和mysql類似。

建立keyspace: 預設制定simplestrategy的副本類型。

建立資料表:

cassandra 有一個特性就是底層做好分布式了,是以再查詢排序的時候限制就比較多。

要按照使用者才建立時間倒叙查詢,必須再建立表的時候就寫好。

預設定義的時正序,倒叙需要再定義下,并且把這個字段放入到primary key 裡面。

更新表結構和mysql類似:

和mysq 類似:其中emails是set類型。

更新資料,比較特殊的時list,map,set類型:

還支援distinct,in等查詢,但不支援關聯查詢,畢竟不是關系型資料庫。