This page (revision-21) was last changed on 23-Apr-2022 17:06 by Harry Metske

This page was created on 23-Apr-2022 17:05 by Harry Metske

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
21 23-Apr-2022 17:06 11 KB Harry Metske to previous

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 131 added 90 lines
!! Creating keyspace, tables, inserting, updating , querying
! Create keyspace
First create a keyspace. You can do that both with ''cassandra-cli'' and ''cqlsh'', but they have different syntaxes :-) .\\
Here's a cqlsh example:
{{{
[default@unknown] cssndra@ubuntu1:~$ cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 2.3.0 | Cassandra 1.2.4 | CQL spec 3.0.0 | Thrift protocol 19.35.0]
Use HELP for help.
cqlsh> CREATE KEYSPACE demo_keyspace WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 2, 'DC2' : 2};
cqlsh> select * from system.schema_keyspaces;
keyspace_name | durable_writes | strategy_class | strategy_options
---------------+----------------+------------------------------------------------------+----------------------------
system_auth | True | org.apache.cassandra.locator.SimpleStrategy | {"replication_factor":"1"}
demo_keyspace | True | org.apache.cassandra.locator.NetworkTopologyStrategy | {"DC2":"2","DC1":"2"}
system | True | org.apache.cassandra.locator.LocalStrategy | {}
system_traces | True | org.apache.cassandra.locator.SimpleStrategy | {"replication_factor":"1"}
cqlsh>
}}}
! Create a column family
Create a columnfamily with the ''cassandra-cli'' utility:
{{{
cssndra@ubuntu1:~$ cassandra-cli
Connected to: "Test Cluster" on 127.0.0.1/9160
Welcome to Cassandra CLI version 1.2.4
Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.
[default@unknown] use demo_keyspace;
Authenticated to keyspace: demo_keyspace
[default@demo_keyspace] create column family users with key_validation_class = 'UTF8Type' and comparator = 'UTF8Type' and default_validation_class = 'UTF8Type';
0b6b0010-fc89-35a1-ad05-77d53e5a4443
}}}
! Insert data
Again with the ''cassandra-cli'' utility insert some data in the {{users}} columnfamily:
{{{
[default@demo_keyspace] cssndra@ubuntu1:~$ cassandra-cli
Connected to: "Test Cluster" on 127.0.0.1/9160
Welcome to Cassandra CLI version 1.2.4
Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.
[default@unknown] use demo_keyspace;
Authenticated to keyspace: demo_keyspace
[default@demo_keyspace] set users[1234][name] = scott;
Value inserted.
Elapsed time: 52 msec(s).
[default@demo_keyspace] set users[1234][password] = scott-secret;
Value inserted.
Elapsed time: 14 msec(s).
[default@demo_keyspace] set users[1234][length] = 185;
Value inserted.
Elapsed time: 8.76 msec(s).
[default@demo_keyspace] set users[1235][name] = harry;
Value inserted.
Elapsed time: 6.71 msec(s).
[default@demo_keyspace] set users[1235][length] = 181;
Value inserted.
Elapsed time: 13 msec(s).
[default@demo_keyspace] set users[1235][whatevercolumn] = skfkjdkfjdklsjfsjflkjldk181;
Value inserted.
Elapsed time: 6.2 msec(s).
[default@demo_keyspace] list users;
Using default limit of 100
Using default column limit of 100
-------------------
RowKey: 1234
=> (column=length, value=185, timestamp=1368883341707000)
=> (column=name, value=scott, timestamp=1368883316118000)
=> (column=password, value=scott-secret, timestamp=1368883330142000)
-------------------
RowKey: 1235
=> (column=length, value=181, timestamp=1368883368497000)
=> (column=name, value=harry, timestamp=1368883358461000)
=> (column=whatevercolumn, value=skfkjdkfjdklsjfsjflkjldk181, timestamp=1368883385475000)
2 Rows Returned.
Elapsed time: 42 msec(s).
}}}