카산드라
[cas@s1 ~]$ ./cassandra/bin/cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.13 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> use testdb
...
...
...
... ;
cqlsh:testdb>
cqlsh:testdb>
cqlsh:testdb>
cqlsh:testdb> CREATE TABLE products (
... productid int,
... productname varchar,
... price int,
... PRIMARY KEY (productid)
... );
package com.multi.cas.jdbc1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class InsertBulkData {
public static void main(String[] args) throws Exception {
Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
//Connection con = DriverManager.getConnection("jdbc:cassandra://localhost:9160/testdb");
Connection con = DriverManager.getConnection("jdbc:cassandra://192.168.56.101:9160/testdb");
String sql = "INSERT INTO products (productid, productname, price) VALUES (?, ?, ?)";
PreparedStatement pstmt = con.prepareStatement(sql);
for (int i=1; i <= 3000; i++) {
pstmt.setInt(1, i);
pstmt.setString(2, "아이패드" + i);
pstmt.setInt(3, 1000+(500*(i % 10)));
pstmt.executeUpdate();
}
pstmt.close();
con.close();
System.out.println("Row 생성 완료!!");
}
}
cqlsh:testdb>
cqlsh:testdb>
cqlsh:testdb> CREATE INDEX idx_price ON products(price);
cqlsh:testdb>
cqlsh:testdb>
cqlsh:testdb> SELECT * FROM products WHERE productid IN (1,2,3,4,5,6,7,8,9,10);
productid | price | productname
-----------+-------+-------------
1 | 1500 | 아이패드1
2 | 2000 | 아이패드2
3 | 2500 | 아이패드3
4 | 3000 | 아이패드4
5 | 3500 | 아이패드5
6 | 4000 | 아이패드6
7 | 4500 | 아이패드7
8 | 5000 | 아이패드8
9 | 5500 | 아이패드9
10 | 1000 | 아이패드10
(10 rows)
cqlsh:testdb> SELECT * FROM products WHERE productid=1;
productid | price | productname
-----------+-------+-------------
1 | 1500 | 아이패드1
(1 rows)
cqlsh:testdb> SELECT * FROM products WHERE productid IN (1,2,3,4,5,6,7,8,9,10) AND price = 3000;
Bad Request: Select on indexed columns and with IN clause for the PRIMARY KEY are not supported
cqlsh:testdb> SELECT * FROM products WHERE price = 3000 LIMIT 10;
productid | price | productname
-----------+-------+--------------
1584 | 3000 | 아이패드1584
114 | 3000 | 아이패드114
2744 | 3000 | 아이패드2744
2524 | 3000 | 아이패드2524
744 | 3000 | 아이패드744
2074 | 3000 | 아이패드2074
2354 | 3000 | 아이패드2354
214 | 3000 | 아이패드214
1224 | 3000 | 아이패드1224
144 | 3000 | 아이패드144
(10 rows)
cqlsh:testdb>
CREATE TABLE products2 ( productid int, type varchar,
productname varchar, price int,
PRIMARY KEY (type, productid)
);
UPDATE products2 SET productname='맥북에어2' WHERE type='C';
에러 발생 : primary key의 일부분인 productid에 대해 EQ 연산이 포함되지 않았음.
=> 멀티update 허용 X
=> 한 row에서 여러개 update안됨
카산드라 모델링은 힘들다
요구사항이 바뀌어야 하는 상황이면 미침.
'dev > NoSQL 모델링' 카테고리의 다른 글
초간단 nasdaq 데이터분석 (0) | 2017.04.27 |
---|---|
정리 (0) | 2017.01.26 |
NoSql 모델링 기법 (0) | 2017.01.25 |
Shard Cluster (1) | 2017.01.25 |
Replica set (0) | 2017.01.25 |