Database Reference
In-Depth Information
twitterkeyspace-user-jb-1-Data.db >
output.json
Here
twitterkeyspace-user-jb-1-Data.db
is a
.db
data file under the
data
directory (in this case it is under
/var/lib/Cassandra
). The preceding
command will create a JSON file having data as shown in
Figure 10-1
.
Figure 10-1
.
Data in the output.json file
We can also include and exclude specific rows using the
-k
and
-x
options, re-
spectively. With the
-k
option, keys have to be in hexadecimal format. Since with the
user
table, the primary key is of
timeuuid
type, so let's first get key values in hexa-
decimal format using the
timeuuidAsBlob
function as follows:
select timeuuidAsBlob(user_id),fname from user;
timeuuidAsBlob(user_id) | fname
-----------------------------------------+---------
0x849d582050e311e4abc13f484de45426 | Brian
0x74ac3a8050e311e4abc13f484de45426 | Melissa
0x7c34a26050e311e4abc13f484de45426 | Chris
0xf7d1f2c050e211e4abc13f484de45426 | vivek
(4 rows)
Here
timeuuidAsBlob(user_id)
is the
user_id
key in hexadecimal
format. Now we can fetch rows having
fname
as
brian
and
vivek
using the
-k
op-
tion:
$CASSANDRA_HOME/bin/sstable2json /var/lib/cassandra/data/
twitterkeyspace/user/twitterkeyspace-user-jb-1-Data.db -k
849d582050e311e4abc13f484de45426
f7d1f2c050e211e4abc13f484de45426
[
{"key": "849d582050e311e4abc13f484de45426","columns":