Reputation: 39
Can anyone help on how to update row with particular column values using the hector api for cassandra.
i.e equivalent of
UPDATE table_name SET value=" " where column_name=column_value;
Upvotes: 0
Views: 360
Reputation: 1
StringSerializer ss = StringSerializer.get();
String keyspaceName = "Test_Keyspace";
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", new CassandraHostConfigurator("localhost:9160"));
Keyspace ksp = HFactory.createKeyspace(keyspaceName, cluster);
// UPDATE==============================
ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(ksp,"Standard1",ss,ss);
ColumnFamilyUpdater<String, String> updater = template.createUpdater("jsmith");
updater.setString("first", "Devid");
ColumnFamilyUpdater<String, String> updater2 = template.createUpdater("ksmith");
updater2.setString("first", "Kohli");
updater2.setString("middle", "Virat");
try {
template.update(updater);
template.update(updater2);
RangeSlicesQuery<String, String, String> rangeSlicesQuery3 = HFactory.createRangeSlicesQuery(ksp,ss,ss,ss);
rangeSlicesQuery3.setColumnFamily("Standard1");
rangeSlicesQuery3.setKeys("jsmith", "ksmith");
rangeSlicesQuery3.setRange("jsmith", null, false, 4);
QueryResult<OrderedRows<String, String, String>> result6 = rangeSlicesQuery3.execute();
// System.out.println(result6.get());
} catch (HectorException e) {
// do something ...
e.printStackTrace();
}
Upvotes: 0
Reputation: 19377
Updates in Cassandra may only be done by primary key.
(More generally, I'd recommend using the native CQL driver at https://github.com/datastax/java-driver over the semi-obsolete Hector.)
Upvotes: 1