Database Reference
In-Depth Information
LOG.debug(new String(column.name, UTF8) + " : "
+ new String(column.value, UTF8));
//END GET
tr.close();
LOG.debug("All done.");
}
}
Here, we perform an insert so that we have something to get. We create a client object and then
call its get method, which takes the row key, a column path, and a consistency level as argu-
ments. The column path sets the name of the column that we're looking for. Remember that the
column names and values are binary (in a Java client they're byte arrays), so we have to convert
the string column name to a byte array for the query. Then when we get the column's value, it's
a byte array too, so we convert it to a string to work with the result.
In this example, we add values for both the name and the age columns, but because our column
path represents only the single column we're interested in querying, we just get the age. The out-
put is shown here:
DEBUG 14:36:42,265 Inserting row for key 1
DEBUG 14:36:42,273 Row insert done.
DEBUG 14:36:42,273 Get result:
DEBUG 14:36:42,282 name : George Clinton
DEBUG 14:36:42,282 All done.
Seeding Some Values
Here we'll just use the command-line interface to quickly create a couple of keys with some dif-
ferent columns to serve as data for the following queries:
[default@Keyspace1] set Standard1['k1']['a']='1'
Value inserted.
[default@Keyspace1] set Standard1['k1']['b']='2'
Value inserted.
[default@Keyspace1] set Standard1['k1']['c']='3'
Value inserted.
[default@Keyspace1] set Standard1['k2']['a']='2.1'
Value inserted.
[default@Keyspace1] set Standard1['k2']['b']='2.2'
So we have two rows; the first has three columns and the second has two columns.
Search WWH ::




Custom Search