cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Cassandra Wiki] Update of "CassandraCli" by jeremyhanna
Date Thu, 24 Feb 2011 00:31:34 GMT
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=diff&rev1=27&rev2=28

--------------------------------------------------

  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 = UTF8Type;
  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. Use `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 family `Standard2` with the default options. Then we exited from our cli shell.
+ In the above example we started the cli with no options. You can specify things like `-host`,
`-port`, `-keyspace`, `-username`, `-password`, etc. Use `bin/cassandra-cli -?` for a full
set of options.
+ 
+ We went on to connect to our local Cassandra node. We created keyspace `Twissandra` and
column family `User` with the default options. Note that with the column family, we used a
UTF8Type comparator.  That means that the columns will be sorted based on UTF8Type sorting.
 It also means that when the column names are displayed on the command-line, they will be
displayed as UTF8Type (readable) text. For more information and options for creating column
families type `help create column family;` on the command line. Finally, 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'] = 'John';
+ [default@Twissandra] set User['jsmith']['first'] = 'John';
  Value inserted.
- [default@Keyspace1] set Standard2['jsmith']['last'] = 'Smith';
+ [default@Twissandra] set User['jsmith']['last'] = 'Smith';
  Value inserted.
- [default@Keyspace1] set Standard2['jsmith']['age'] = '42';
+ [default@Twissandra] set User['jsmith']['age'] = '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 [[API|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`. Each of these commands is the equivalent to an `insert()`
using the [[API|Thrift API]].
  
  Now let's read back the `jsmith` row to see what it contains:
  
  {{{
- [default@Keyspace1] get Standard2['jsmith'];
- => (column=616765, value=3432, timestamp=1298168118014000)
+ [default@Twissandra] get User['jsmith'];
+ => (column=age, value=3339, timestamp=1298504259386000)
- => (column=6669727374, value=4a6f686e, timestamp=1298166059047000)
+ => (column=first, value=4a6f686e, timestamp=1298504239938000)
- => (column=6c617374, value=536d697468, timestamp=1298168112533000)
+ => (column=last, value=536d697468, timestamp=1298504248570000)
  Returned 3 results.
  }}}
  Note: Using the `get` command in this form is the equivalent to a `get_slice()` 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 metadata of the column family to not
only make them output in a readable format, 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 = 
+ ...	[
+ ...	{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'] = 'Zaphod';
+ Value inserted.
+ [default@Twissandra] set User['zaphod']['last'] = 'Beeblebrox';
+ Value inserted.
+ [default@Twissandra] set User['zaphod']['age'] = '42';
+ Value inserted.
+ [default@Twissandra] get User where age = '42';
+ -------------------
+ RowKey: zaphod
+ => (column=age, value=42, timestamp=1298504874382000)
+ => (column=first, value=Zaphod, timestamp=1298504803709000)
+ => (column=last, value=Beeblebrox, timestamp=1298504848982000)
+ 
+ 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 display value unencoded in the cli
output. We also add an index on age. We add 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 more information
on how things work, type `help;` on the cli by itself or with any of the commands you're interested
in.
+ 

Mime
View raw message