- Use "cqlsh" command.
[surachart@centos apache-cassandra-1.2.0]$ ./bin/cqlsh- Use "cassandra-cli" command.
Connected to Test Cluster at centos:9160.
[cqlsh 2.3.0 | Cassandra 1.2.0 | CQL spec 3.0.0 | Thrift protocol 19.35.0]
Use HELP for help.
cqlsh> CREATE SCHEMA demo WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> use demo;
cqlsh:demo> show tables;
Improper show command.
cqlsh:demo> CREATE TABLE users (
... user_id varchar PRIMARY KEY,
... first varchar,
... last varchar,
... age int
... );
cqlsh:demo> INSERT INTO users (user_id, first, last, age) VALUES ('opun', 'Surachart', 'Opun', 20);
cqlsh:demo>
cqlsh:demo> SELECT * FROM users;
user_id | age | first | last
---------+-----+-----------+------
opun | 20 | Surachart | Opun
cqlsh:demo> alter table users add email varchar;
cqlsh:demo> SELECT * FROM users;
user_id | age | email | first | last
---------+-----+-------+-----------+------
opun | 20 | null | Surachart | Opun
cqlsh:demo> update demo.users SET email='surachart at gmail dot com' WHERE user_id='opun';
cqlsh:demo> SELECT * FROM users;
user_id | age | email | first | last
---------+-----+----------------------------+-----------+------
opun | 20 | surachart at gmail dot com | Surachart | Opun
[default@MyKeyspace] use demoAfter I used "assume" to change to be as 'utf8', I could read it. Then I tried to use "set" command but error. However, I wasn't interested in it.
... ;
Authenticated to keyspace: demo
[default@demo] get users['opun'];
=> (column=, value=, timestamp=1357289978977000)
=> (column=age, value=00000014, timestamp=1357289771856000)
=> (column=email, value=73757261636861727420617420676d61696c20646f7420636f6d, timestamp=1357289978977000)
=> (column=first, value=537572616368617274, timestamp=1357289771856000)
=> (column=last, value=4f70756e, timestamp=1357289771856000)
Returned 5 results.
Elapsed time: 22 msec(s).
[default@demo] describe;
Keyspace: demo:
Replication Strategy: org.apache.cassandra.locator.SimpleStrategy
Durable Writes: true
Options: [replication_factor:1]
Column Families:
[default@demo] assume users keys as utf8;
Assumption for column family 'users' added successfully.
[default@demo] get users['opun'];
=> (column=, value=, timestamp=1357289978977000)
=> (column=age, value=00000014, timestamp=1357289771856000)
=> (column=email, value=73757261636861727420617420676d61696c20646f7420636f6d, timestamp=1357289978977000)
=> (column=first, value=537572616368617274, timestamp=1357289771856000)
=> (column=last, value=4f70756e, timestamp=1357289771856000)
Returned 5 results.
Elapsed time: 5.48 msec(s).
[default@demo] assume users comparator as utf8;
Assumption for column family 'users' added successfully.
[default@demo] get users['opun'];
=> (column=, value=, timestamp=1357289978977000)
=> (column=age, value=00000014, timestamp=1357289771856000)
=> (column=email, value=73757261636861727420617420676d61696c20646f7420636f6d, timestamp=1357289978977000)
=> (column=first, value=537572616368617274, timestamp=1357289771856000)
=> (column=last, value=4f70756e, timestamp=1357289771856000)
Returned 5 results.
Elapsed time: 8.08 msec(s).
[default@demo] assume users validator as utf8;
Assumption for column family 'users' added successfully.
[default@demo] get users['opun'];
=> (column=, value=, timestamp=1357289978977000)
=> (column=age, value=, timestamp=1357289771856000)
=> (column=email, value=surachart at gmail dot com, timestamp=1357289978977000)
=> (column=first, value=Surachart, timestamp=1357289771856000)
=> (column=last, value=Opun, timestamp=1357289771856000)
Returned 5 results.
Elapsed time: 5.27 msec(s).
[default@demo]
[default@demo] set users['opun']['add1ress']='N/A';
Not enough bytes to read value of component 0
InvalidRequestException(why:Not enough bytes to read value of component 0)
at org.apache.cassandra.thrift.Cassandra$insert_result.read(Cassandra.java:16552)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_insert(Cassandra.java:839)
at org.apache.cassandra.thrift.Cassandra$Client.insert(Cassandra.java:823)
at org.apache.cassandra.cli.CliClient.executeSet(CliClient.java:975)
at org.apache.cassandra.cli.CliClient.executeCLIStatement(CliClient.java:218)
at org.apache.cassandra.cli.CliMain.processStatementInteractive(CliMain.java:210)
at org.apache.cassandra.cli.CliMain.main(CliMain.java:337)
[default@demo] get users['chart'];
Returned 0 results.
Elapsed time: 3.17 msec(s).
It'd better, if tested to insert again.
- Use "cqlsh" command again.
cqlsh:demo> SELECT * FROM users;
user_id | age | email | first | last
---------+-----+----------------------------+-----------+------
opun | 20 | surachart at gmail dot com | Surachart | Opun
cqlsh:demo> INSERT INTO users (user_id, first, last, age, email) VALUES ('chart', 'John', 'Test', 60,'test@test.com');
cqlsh:demo> SELECT * FROM users;- Use "cassandra-cli" command again.
user_id | age | email | first | last
---------+-----+----------------------------+-----------+------
opun | 20 | surachart at gmail dot com | Surachart | Opun
chart | 60 | test@test.com | John | Test
[default@demo] get users['chart'];I believe cqlsh tool is useful. You can read more.
=> (column=, value=, timestamp=1357291020421000)
=> (column=age, value=<, timestamp=1357291020421000)
=> (column=email, value=test@test.com, timestamp=1357291020421000)
=> (column=first, value=John, timestamp=1357291020421000)
=> (column=last, value=Test, timestamp=1357291020421000)
Returned 5 results.
Elapsed time: 8.73 msec(s).
[default@demo]
Cassandra Query Language (CQL) v2.0
Cassandra Query Language (CQL) v3.0.0
No comments:
Post a Comment