0

任何人都可以帮助如何使用 cassandra 的 hector api 更新具有特定列值的行。

即相当于

UPDATE table_name SET value="" where column_name=column_value;

4

2 回答 2

1

Cassandra 中的更新只能通过主键完成。

(更一般地说,我建议在半过时的 Hector上使用https://github.com/datastax/java-driver上的本机 CQL 驱动程序。)

于 2013-10-09T21:21:12.213 回答
0
    StringSerializer ss = StringSerializer.get();
    String keyspaceName = "Test_Keyspace";
    Cluster cluster = HFactory.getOrCreateCluster("TestCluster", new CassandraHostConfigurator("localhost:9160"));
    Keyspace ksp = HFactory.createKeyspace(keyspaceName, cluster);

// 更新===============================

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();
    }
于 2019-08-13T07:55:06.733 回答