Return-Path: Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: (qmail 25805 invoked from network); 24 Feb 2011 00:32:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Feb 2011 00:32:11 -0000 Received: (qmail 32381 invoked by uid 500); 24 Feb 2011 00:32:11 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 32342 invoked by uid 500); 24 Feb 2011 00:32:10 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 32334 invoked by uid 500); 24 Feb 2011 00:32:10 -0000 Delivered-To: apmail-incubator-cassandra-commits@incubator.apache.org Received: (qmail 32331 invoked by uid 99); 24 Feb 2011 00:32:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Feb 2011 00:32:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.131] (HELO eos.apache.org) (140.211.11.131) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Feb 2011 00:32:08 +0000 Received: from eosnew.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id EFCA91E4; Thu, 24 Feb 2011 00:31:34 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Apache Wiki To: Apache Wiki Date: Thu, 24 Feb 2011 00:31:34 -0000 Message-ID: <20110224003134.20949.54907@eosnew.apache.org> Subject: =?utf-8?q?=5BCassandra_Wiki=5D_Update_of_=22CassandraCli=22_by_jeremyhann?= =?utf-8?q?a?= X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for= change notification. The "CassandraCli" page has been changed by jeremyhanna. The comment on this change is: Added some more example information.. http://wiki.apache.org/cassandra/CassandraCli?action=3Ddiff&rev1=3D27&rev2= =3D28 -------------------------------------------------- Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit. [default@unknown] connect localhost/9160; Connected to: "Test Cluster" on localhost/9160 - [default@unknown] create keyspace Keyspace1; + [default@unknown] create keyspace Twissandra; d105c4f1-3c93-11e0-9fb5-e700f669bcfc - [default@unknown] use Keyspace1; + [default@unknown] use Twissandra; - Authenticated to keyspace: Keyspace1 + Authenticated to keyspace: Twissandra - [default@Keyspace1] create column family Standard2; + [default@Twissandra] create column family User with comparator =3D UTF8Ty= pe; 00389812-3c94-11e0-9fb5-e700f669bcfc - [default@Keyspace1] quit; + [default@Twissandra] quit; evans@achilles:~/cassandra$ }}} - In the above example we started the cli with no options. You can specify = things like `-host`, `-port`, `-keyspace`, `-username`, `-password`, etc. U= se `bin/cassandra-cli -?` for a full set of options. We went on to connect= to our local Cassandra node. We created keyspace `Keyspace1` and column fa= mily `Standard2` with the default options. Then we exited from our cli shel= l. + In the above example we started the cli with no options. You can specify = things like `-host`, `-port`, `-keyspace`, `-username`, `-password`, etc. U= se `bin/cassandra-cli -?` for a full set of options. + = + We went on to connect to our local Cassandra node. We created keyspace `T= wissandra` and column family `User` with the default options. Note that wit= h the column family, we used a UTF8Type comparator. That means that the co= lumns will be sorted based on UTF8Type sorting. It also means that when th= e column names are displayed on the command-line, they will be displayed as= UTF8Type (readable) text. For more information and options for creating co= lumn families type `help create column family;` on the command line. Finall= y, we exited from our cli shell. = Let's get back into the shell with some options specified and create some= data. = @@ -30, +32 @@ Welcome to cassandra CLI. = Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit. - [default@unknown] use Keyspace1; + [default@unknown] use Twissandra; - Authenticated to keyspace: Keyspace1 + Authenticated to keyspace: Twissandra - [default@Keyspace1] set Standard2['jsmith']['first'] =3D 'John'; + [default@Twissandra] set User['jsmith']['first'] =3D 'John'; Value inserted. - [default@Keyspace1] set Standard2['jsmith']['last'] =3D 'Smith'; + [default@Twissandra] set User['jsmith']['last'] =3D 'Smith'; Value inserted. - [default@Keyspace1] set Standard2['jsmith']['age'] =3D '42'; + [default@Twissandra] set User['jsmith']['age'] =3D '39'; Value inserted. }}} - Note that before we can start adding data, we have to `use Keyspace1` to = set our context. We created a record in the `Standard2` column family using= the key `jsmith`. This record has three columns, `first`, `last`, and `age= `. Each of these commands is the equivalent to an `insert()` using the [[AP= I|Thrift API]]. + Note that before we can start adding data, we have to `use Twissandra` to= set our context. We created a record in the `User` column family using the= key `jsmith`. This record has three columns, `first`, `last`, and `age`. E= ach of these commands is the equivalent to an `insert()` using the [[API|Th= rift API]]. = Now let's read back the `jsmith` row to see what it contains: = {{{ - [default@Keyspace1] get Standard2['jsmith']; - =3D> (column=3D616765, value=3D3432, timestamp=3D1298168118014000) + [default@Twissandra] get User['jsmith']; + =3D> (column=3Dage, value=3D3339, timestamp=3D1298504259386000) - =3D> (column=3D6669727374, value=3D4a6f686e, timestamp=3D1298166059047000) + =3D> (column=3Dfirst, value=3D4a6f686e, timestamp=3D1298504239938000) - =3D> (column=3D6c617374, value=3D536d697468, timestamp=3D1298168112533000) + =3D> (column=3Dlast, value=3D536d697468, timestamp=3D1298504248570000) Returned 3 results. }}} Note: Using the `get` command in this form is the equivalent to a `get_sl= ice()` using the [[API|Thrift API]]. + Why are the values all hex? It's because the default validation class is = BytesType, which displays in hex in the output. Let's update the column met= adata of the column family to not only make them output in a readable forma= t, but also add a secondary index on age. We'll also add another record so = that we can see the secondary index work. = + {{{ + [default@Twissandra] update column family User with = = + ... column_metadata =3D = + ... [ + ... {column_name: first, validation_class: UTF8Type}, + ... {column_name: last, validation_class: UTF8Type}, + ... {column_name: age, validation_class: UTF8Type, index_type: KEYS} + ... ]; + fd98427f-3fa6-11e0-8f42-e700f669bcfc + [default@Twissandra] set User['zaphod']['first'] =3D 'Zaphod'; + Value inserted. + [default@Twissandra] set User['zaphod']['last'] =3D 'Beeblebrox'; + Value inserted. + [default@Twissandra] set User['zaphod']['age'] =3D '42'; + Value inserted. + [default@Twissandra] get User where age =3D '42'; + ------------------- + RowKey: zaphod + =3D> (column=3Dage, value=3D42, timestamp=3D1298504874382000) + =3D> (column=3Dfirst, value=3DZaphod, timestamp=3D1298504803709000) + =3D> (column=3Dlast, value=3DBeeblebrox, timestamp=3D1298504848982000) + = + 1 Row Returned. + }}} + In the above example, you can see that we can span commands over multiple= lines. We add column metadata that validates the column data as well as di= splay value unencoded in the cli output. We also add an index on age. We ad= d one more row with an age of '42' and finally query the column family for = rows that with an age of 42. + = + This has just been a brief introduction with a couple of examples. For mo= re information on how things work, type `help;` on the cli by itself or wit= h any of the commands you're interested in. +=20