0
我正在使用Cassandra,並且我正在使用Hector客戶端來讀取和插入Cassandra數據庫中的數據。我試圖使用hector客戶端從Cassandra數據庫中檢索數據,如果我只想檢索一列,我就可以做到這一點。使用Hector客戶端從Cassandra檢索多列值
現在我試圖檢索rowKey as 1011
的數據,但將columnNames作爲字符串的集合。下面是我的API,將檢索使用赫克託卡桑德拉數據庫中的數據客戶端 -
public Map<String, String> getAttributes(String rowKey, Collection<String> attributeNames, String columnFamily) {
final Cluster cluster = CassandraHectorConnection.getInstance().getCluster();
final Keyspace keyspace = CassandraHectorConnection.getInstance().getKeyspace();
try {
ColumnQuery<String, String, String> columnQuery = HFactory
.createStringColumnQuery(keyspace)
.setColumnFamily(columnFamily).setKey(rowKey)
.setName("c1");
QueryResult<HColumn<String, String>> result = columnQuery.execute();
System.out.println("Column Name from cassandra: " + result.get().getName() + "Column value from cassandra: " + result.get().getValue());
} catch (HectorException e) {
LOG.error("Exception in CassandraHectorClient::getAttributes " +e+ ", RowKey = " +rowKey+ ", Attribute Names = " +attributeNames);
} finally {
cluster.getConnectionManager().shutdown();
}
return null;
}
如果你看到我上面的方法,我正在嘗試從卡桑德拉數據庫中的數據進行特定的rowKey
和column c1
。現在我正在嘗試從Cassandra數據庫中檢索數據以收集特定rowKey的列。
含義像這個 -
我想檢索多列,但對同一rowKey數據。我如何使用Hector客戶端來做到這一點?我不想檢索所有列的數據,然後重複查找我正在查找的各個列數據。