use of com.datastax.driver.core.ResultSet in project cassandra by apache.
the class ViewTest method testPrimaryKeyOnlyTable.
@Test
public void testPrimaryKeyOnlyTable() throws Throwable {
createTable("CREATE TABLE %s (" + "a int," + "b int," + "PRIMARY KEY (a, b))");
executeNet(protocolVersion, "USE " + keyspace());
// Cannot use SELECT *, as those are always handled by the includeAll shortcut in View.updateAffectsView
createView("mv1", "CREATE MATERIALIZED VIEW %s AS SELECT a, b FROM %%s WHERE b IS NOT NULL PRIMARY KEY (b, a)");
updateView("INSERT INTO %s (a, b) VALUES (?, ?)", 1, 1);
ResultSet mvRows = executeNet(protocolVersion, "SELECT a, b FROM mv1");
assertRowsNet(protocolVersion, mvRows, row(1, 1));
}
use of com.datastax.driver.core.ResultSet in project cassandra by apache.
the class ViewTest method testDeleteSingleColumnInViewClustering.
@Test
public void testDeleteSingleColumnInViewClustering() throws Throwable {
createTable("CREATE TABLE %s (" + "a int," + "b int," + "c int," + "d int," + "PRIMARY KEY (a, b))");
executeNet(protocolVersion, "USE " + keyspace());
createView("mv1", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE a IS NOT NULL AND b IS NOT NULL AND d IS NOT NULL PRIMARY KEY (a, d, b)");
updateView("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0);
ResultSet mvRows = executeNet(protocolVersion, "SELECT a, d, b, c FROM mv1");
assertRowsNet(protocolVersion, mvRows, row(0, 0, 0, 0));
updateView("DELETE c FROM %s WHERE a = ? AND b = ?", 0, 0);
mvRows = executeNet(protocolVersion, "SELECT a, d, b, c FROM mv1");
assertRowsNet(protocolVersion, mvRows, row(0, 0, 0, null));
updateView("DELETE d FROM %s WHERE a = ? AND b = ?", 0, 0);
mvRows = executeNet(protocolVersion, "SELECT a, d, b FROM mv1");
assertTrue(mvRows.isExhausted());
}
use of com.datastax.driver.core.ResultSet in project flink by apache.
the class CassandraConnectorITCase method testCassandraTupleAtLeastOnceSink.
// ------------------------------------------------------------------------
// At-least-once Tests
// ------------------------------------------------------------------------
@Test
public void testCassandraTupleAtLeastOnceSink() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
DataStream<Tuple3<String, Integer, Integer>> source = env.fromCollection(collection);
source.addSink(new CassandraTupleSink<Tuple3<String, Integer, Integer>>(INSERT_DATA_QUERY, builder));
env.execute();
ResultSet rs = session.execute(SELECT_DATA_QUERY);
Assert.assertEquals(20, rs.all().size());
}
use of com.datastax.driver.core.ResultSet in project flink by apache.
the class CassandraConnectorITCase method verifyResultsDataPersistenceUponMissedNotify.
@Override
protected void verifyResultsDataPersistenceUponMissedNotify(CassandraTupleWriteAheadSink<Tuple3<String, Integer, Integer>> sink) {
ResultSet result = session.execute(SELECT_DATA_QUERY);
ArrayList<Integer> list = new ArrayList<>();
for (int x = 1; x <= 60; x++) {
list.add(x);
}
for (Row s : result) {
list.remove(new Integer(s.getInt("counter")));
}
Assert.assertTrue("The following ID's were not found in the ResultSet: " + list.toString(), list.isEmpty());
}
use of com.datastax.driver.core.ResultSet in project flink by apache.
the class CassandraTupleWriteAheadSink method sendValues.
@Override
protected boolean sendValues(Iterable<IN> values, long timestamp) throws Exception {
final AtomicInteger updatesCount = new AtomicInteger(0);
final AtomicInteger updatesConfirmed = new AtomicInteger(0);
final AtomicReference<Throwable> exception = new AtomicReference<>();
FutureCallback<ResultSet> callback = new FutureCallback<ResultSet>() {
@Override
public void onSuccess(ResultSet resultSet) {
updatesConfirmed.incrementAndGet();
if (updatesCount.get() > 0) {
// only set if all updates have been sent
if (updatesCount.get() == updatesConfirmed.get()) {
synchronized (updatesConfirmed) {
updatesConfirmed.notifyAll();
}
}
}
}
@Override
public void onFailure(Throwable throwable) {
if (exception.compareAndSet(null, throwable)) {
LOG.error("Error while sending value.", throwable);
synchronized (updatesConfirmed) {
updatesConfirmed.notifyAll();
}
}
}
};
//set values for prepared statement
int updatesSent = 0;
for (IN value : values) {
for (int x = 0; x < value.getArity(); x++) {
fields[x] = value.getField(x);
}
//insert values and send to cassandra
BoundStatement s = preparedStatement.bind(fields);
s.setDefaultTimestamp(timestamp);
ResultSetFuture result = session.executeAsync(s);
updatesSent++;
if (result != null) {
//add callback to detect errors
Futures.addCallback(result, callback);
}
}
updatesCount.set(updatesSent);
synchronized (updatesConfirmed) {
while (exception.get() == null && updatesSent != updatesConfirmed.get()) {
updatesConfirmed.wait();
}
}
if (exception.get() != null) {
LOG.warn("Sending a value failed.", exception.get());
return false;
} else {
return true;
}
}
Aggregations