Deletion and programmatic definition

Certify and Increase Opportunity.
Be
Govt. Certified Apache Cassandra Professional

Deletion and programmatic definition

Data written to Cassandra gets persisted to SSTables. Since SSTables are immutable, the data can’t actually be removed when you perform a delete, instead, a marker (also called a “tombstone”) is written to indicate the value’s new status. Never fear though, on the first compaction that occurs between the data and the tombstone, the data will be expunged completely and the corresponding disk space recovered.

DELETE Usage

DELETE [<column_name> [, …]] FROM <column_family>
[USING CONSISTENCY <consistency_level> [AND TIMESTAMP <integer>]] WHERE <row_specification>;

<row_specification> is:

KEY | <key_alias> = <key_value>
KEY | <key_alias> IN (<key_value> [,…])

Description
A DELETE statement removes one or more columns from one or more rows in the named column family.

Specifying Columns
After the DELETE keyword, optionally list column names, separated by commas.

DELETE col1, col2, col3 FROM Planeteers USING CONSISTENCY ONE WHERE KEY = ‘Captain’;

When no column names are specified, the entire row(s) specified in the WHERE clause are deleted.

DELETE FROM MastersOfTheUniverse WHERE KEY IN (‘Man-At-Arms’, ‘Teela’);

Specifying the Column Family
The column family name follows the list of column names and the keyword FROM.

Specifying Options

You can specify these options:

Consistency level
Timestamp (current time)

When a column is deleted, it is not removed from disk immediately. The deleted column is marked with a tombstone and then removed after the configured grace period has expired. The optional timestamp defines the new tombstone record. See About Deletes for more information about how Cassandra handles deleted columns and rows.

Specifying Rows

The WHERE clause specifies which row or rows to delete from the column family. This form allows the specification of a single keyname using the KEY keyword (or key alias) and the = operator.

DELETE col1 FROM SomeColumnFamily WHERE KEY = ‘some_key_value’;

This form provides a list of key names using the IN notation and a parenthetical list of comma-delimited keyname terms.

DELETE col1 FROM SomeColumnFamily WHERE keyalias IN (key1, key2);

Example

DELETE email, phone
FROM users
USING CONSISTENCY QUORUM AND TIMESTAMP 1318452291034
WHERE user_name = ‘jsmith’;
DELETE phone FROM users WHERE KEY IN (‘jdoe’, ‘jsmith’);

Programmatic Column Addition

cluster.addColumnFamily(ColumnFamilyDefinition cfdef); // where the
‘cluster’ is derived from new ThriftCluster(“Cluster1”,
cassandraHostConfigurator);

Another example for programmatic addition is –

The unit test for Cluster has some examples for creating keyspaces and
column families dynamically:
https://github.com/rantav/hector/blob/master/core/src/test/java/me/prettyprint/cassandra/service/CassandraClusterTest.java#L88-179
Share this post
[social_warfare]
Single, range and multiget slice
History of Cassandra

Get industry recognized certification – Contact us

keyboard_arrow_up