use of com.netflix.titus.ext.cassandra.executor.AsyncCassandraExecutor in project titus-control-plane by Netflix.
the class CassandraUtils method writeIntoTwoColumnTable.
public static long writeIntoTwoColumnTable(Session targetSession, String table, Observable<Pair<Object, Object>> sourceData) {
Pair<String, String> columnNames = resolveColumnNamesInTwoColumnTable(targetSession, table);
String primaryKey = columnNames.getLeft();
String valueColumn = columnNames.getRight();
PreparedStatement insertStatement = targetSession.prepare(String.format("INSERT INTO %s (%s, %s) VALUES (?, ?)", table, primaryKey, valueColumn));
AsyncCassandraExecutor executor = new AsyncCassandraExecutor(targetSession, PAGE_SIZE, SPLIT);
long recordCount = sourceData.flatMap(pair -> {
BoundStatement boundStatement = insertStatement.bind(pair.getLeft(), pair.getRight());
return executor.executeUpdate(boundStatement).cast(Long.class).concatWith(Observable.just(1L));
}, MAX_CONCURRENCY).reduce(0L, (acc, v) -> acc + v).toBlocking().firstOrDefault(null);
return recordCount;
}
use of com.netflix.titus.ext.cassandra.executor.AsyncCassandraExecutor in project titus-control-plane by Netflix.
the class CassandraUtils method readTwoColumnTable.
public static Observable<Pair<Object, Object>> readTwoColumnTable(Session sourceSession, String table) {
Pair<String, String> columnNames = resolveColumnNamesInTwoColumnTable(sourceSession, table);
String primaryKey = columnNames.getLeft();
String valueColumn = columnNames.getRight();
PreparedStatement queryAllStatement = sourceSession.prepare(String.format("SELECT * FROM %s WHERE token(%s) > :min AND token(%s) <= :max", table, primaryKey, primaryKey));
AsyncCassandraExecutor executor = new AsyncCassandraExecutor(sourceSession, PAGE_SIZE, SPLIT);
return executor.rawRangeQuery2(primaryKey, valueColumn, queryAllStatement);
}
Aggregations