Here is a code snippet that lets you dump the data into set statements that you can then load via the CLI.
public void dumpColumnFamily() {
String columnFamily = "YOUR_COLUMN_FAMILY";
Cluster cluster = HFactory.getOrCreateCluster("dev", "localhost:9160");
Keyspace keyspace = HFactory.createKeyspace("YOUR_KEYSPACE", cluster);
RangeSlicesQuery<String, String, String> rangeSlicesQuery = HFactory
.createRangeSlicesQuery(keyspace, StringSerializer.get(),
StringSerializer.get(), StringSerializer.get());
rangeSlicesQuery.setColumnFamily(columnFamily);
rangeSlicesQuery.setKeys("", "");
rangeSlicesQuery.setRange("", "", false, 2000); // MAX_COLUMNS
rangeSlicesQuery.setRowCount(2000); // MAX_ROWS
QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery .execute();
OrderedRows<String, String, String> orderedRows = result.get();
for (Row<String, String, String> r : orderedRows) {
ColumnSlice<String, String> slice = r.getColumnSlice();
for (HColumn<String, String> column : slice.getColumns()) {
System.out.println("set " + columnFamily + "['" + r.getKey()
+ "']" + "['" + column.getName() + "'] = '"
+ column.getValue() + "';");
}
}
}
No comments:
Post a Comment