You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by Apache Wiki <wi...@apache.org> on 2009/08/20 20:16:22 UTC

[Cassandra Wiki] Update of "ThriftInterface" by JonathanEllis

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for change notification.

The following page has been changed by JonathanEllis:
http://wiki.apache.org/cassandra/ThriftInterface

The comment on the change is:
remove horribly outdated material

------------------------------------------------------------------------------
  Usage: ./Cassandra-remote [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]
  }}}
  
- The following examples will use the following schema, specified in your `conf/storage-conf.xml`:
+ TODO: add examples. Volunteers welcome :)
  
- {{{ 
- <Tables>
-     <Table Name = "users">
-    	  <ColumnFamily Index="Name" Name="base_attributes"/>
-    	  <ColumnFamily Index="Name" Name="extended_attributes"/>
-    	  <ColumnFamily ColumnType="Super" Index="Name" Name="edges"/>
-     </Table>
- </Tables>
- }}} 
- 
- == insert ==
- 
- To get started, we'll insert some data into the `users` table:
- 
- {{{ 
- > ./Cassandra-remote -h <hostname>:<ThriftPort> insert 'users' '1' "ColumnPath('base_attributes', None, 'email')" 'ted@example.com' 0 False
- None
- > ./Cassandra-remote -h <hostname>:<ThriftPort> insert 'users' '1' "ColumnPath('base_attributes', None, 'age')" '25' 0 False
- None
- > ./Cassandra-remote -h <hostname>:<ThriftPort> insert 'users' '1' "ColumnPath('edges', 'friends', '2')" '1' 0 False
- None
- > ./Cassandra-remote -h <hostname>:<ThriftPort> insert 'users' '1' "ColumnPath('edges', 'friends', '4')" '1' 0 False
- None
- > ./Cassandra-remote -h <hostname>:<ThriftPort> insert 'users' '1' "ColumnPath('edges', 'groups', '1')" '1' 0 False
- None
- > ./Cassandra-remote -h <hostname>:<ThriftPort> insert 'users' '2' "ColumnPath('base_attributes', None, 'email')" 'bill@example.com' 0 False
- None
- }}}
- 
- Note that the first two calls add data to the `email` and `age` columns in the `base_attributes` column family, while the third call adds data to the `2` column of the `friends` super column of the `edges` column family.  Also note that I'm using a timestamp of 0 in all three cases.  There are now two rows in this table, with key values of `1` and `2`.
- 
- 
- == get_slice ==
- 
- If you set `start` to a value less than 0, you get all of the columns, no matter what value you give `count`.  If you set `start` to a value of zero or greater, setting `count` to `i` will return the first `i` columns.  Returns a list of dicts, with the dicts containing `{columnName, value, timestamp}`.
- 
- Some examples on our table:
- 
- {{{ 
- > ./Cassandra-remote -h <hostname>:<ThriftPort> get_slice 'users' '1' "ColumnParent('base_attributes')" -1 0
- [ {'columnName': 'email', 'value': 'ted@example.com', 'timestamp': 0},
-   {'columnName': 'age', 'value': '25', 'timestamp': 0}]
- > ./Cassandra-remote -h <hostname>:<ThriftPort> get_slice 'users' '1' "ColumnParent('base_attributes')" 0 1
- [{'columnName': 'email', 'value': 'ted@example.com', 'timestamp': 0}]
- > ./Cassandra-remote -h <hostname>:<ThriftPort> get_slice 'users' '1' "ColumnParent('base_attributes')" 0 2
- [ {'columnName': 'email', 'value': 'ted@example.com', 'timestamp': 0},
-   {'columnName': 'age', 'value': '25', 'timestamp': 0}] 
- }}}
- 
- == get_column ==
- 
- Get a dict containing `{columnName, value, timestamp}` for a specific row.
- 
- The easiest way to think of this coming from a SQL world is:
- 
- SELECT age FROM users WHERE id = 1
- 
- Some examples on our table:
- 
- {{{ 
- > ./Cassandra-remote -h <hostname>:<ThriftPort> get_column 'users' '1' "ColumnPath('base_attributes', None, 'age')" 
- {'columnName': 'age', 'value': '25', 'timestamp': 0}
- > ./Cassandra-remote -h <hostname>:<ThriftPort> get_column 'users' '1' "ColumnPath('edges', 'friends', '2')" 
- {'columnName': '2', 'value': '1', 'timestamp': 0}
- }}} 
- 
- == get_column_count ==
- 
- Will tell you the number of columns for a particular row and column family.
- 
- An example on our table:
- 
- {{{
- > ./Cassandra-remote -h <hostname>:<ThriftPort> get_column_count 'users' '1' "ColumnParent('base_attributes')
- }}} 
- 
- == batch_insert ==
- {{{
- > ./Cassandra-remote -h <hostname>:<ThriftPort> batch_insert "batch_mutation_t({'table':'users', 'key':'3', 'cfmap': {'base_attributes': [column_t({'columnName': 'email', 'value': 'napoleon@example.com', 'timestamp': 0}), column_t({'columnName': 'age', 'value': '45', 'timestamp': 0}) ] } })"
- None
- }}} 
- 
- == batch_insert_blocking ==
- 
- == remove ==
- 
- {{{ 
- > ./Cassandra-remote -h <hostname>:<ThriftPort> remove 'users' '1' "ColumnPath('base_attributes', None, 'email')"
- None
- > ./Cassandra-remote -h <hostname>:<ThriftPort> get_column 'users' '1' "ColumnPath('base_attributes', None, 'age')" 
- {'columnName': 'email', 'value': '', 'timestamp': 0}
- }}} 
- 
- == get_slice_super ==
- 
- {{{ 
- > ./Cassandra-remote -h <hostname>:<ThriftPort> get_slice_super 'users' '1' 'edges' -1 0
- [ {'name': 'friends', 'columns': [{'columnName': '2', 'value': '1', 'timestamp': 0}, {'columnName': '4', 'value': '1', 'timestamp': 0}]},
-   {'name': 'groups', 'columns': [{'columnName': '1', 'value': '1', 'timestamp': 0}]}]
- }}} 
- 
- == storage configuration impact on the Thrift API ==
- 
- Note that some API calls may silently return empty sets if the underlying storage configuration doesn't support them.  In particular, get_columns_since will only return rows if the column family is ordered by time.
- 
- == usage of timestamp in Thrift calls ==
- 
- In the examples shown here timestamps are all 0.  This is to make them non-clock dependent.  In real world scenarios this is used to provide eventual consistency... mutations are ordered by the timestamp supplied by the client.  In most cases you should set the timestamp to the time at which the data was updated, or the current time if that is unavailable.
-