LoginSignup
3
3

More than 3 years have passed since last update.

Cassandraのデータタイプ

Last updated at Posted at 2019-10-13

はじめに

CassandraはNoSQLの代表的なデータベースシステムです。
image.png

出典:https://db-engines.com/en/ranking

データタイプ

データタイプは下記の種類があります。メモします。
・native types
・collection types
・user-defined types
・tuple types
・custom types

native types

  • ASCII
  • BIGINT: 64bit
  • BLOB
  • BOOLEAN
  • COUNTER
  • DATE
  • DECIMAL
  • DOUBLE
  • DURATION
  • FLOAT
  • INET
  • INT: 32bit
  • SMALLINT: 16bit
  • TEXT: UTF8 encoded string
  • TIME
  • TIMESTAMP
  • TIMEUUID
  • TINYINT: 8bit
  • UUID
  • VARCHAR: Textと同じ。UTF8 encoded string
  • VARINT: 任意精度の整数

collection types

ネストしたい場合はコレクション型を定義しても便利です。

  • Map

サンプル

CREATE TABLE users (
    id text PRIMARY KEY,
    name text,
    read_books map<text, text> // isbn:本名
);
INSERT INTO users (id, name, read_books)
           VALUES ('tanaka', '田中 太郎', { '978-4873115290' : 'Cassandra', '978-4873112565' : 'Apacheセキュリティ' });
  • Set

定義例: tags set ⇒ 値例: {"20代", "男性"}
更新例1: tags = tags - { '20代', '男性' }
更新例2: tags = tags + { '30代', '女性' }

  • List

定義例: scores list ⇒ 値例: [10, 5, 15, 20]。
更新例1: scores = scores - [ 10, 15]
更新例2: scores = scores + [ 12, 18]
更新例3: scores[0] = 16

user-defined types

CREATE TYPE address (
    street text,
    city text,
    zip text,
    phones map<text, text>
)

CREATE TABLE user (
    name text PRIMARY KEY,
    addresses map<text, address>
)

tuple types

CREATE TABLE durations (
    event text,
    duration tuple<int, text>,
)

INSERT INTO durations (event, duration) VALUES ('event1', (3, 'hours'));

custom types

推奨されていません

dataypes: http://cassandra.apache.org/doc/latest/cql/types.html

以上

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3