use of com.datastax.driver.core.ResultSet in project flink by apache.
the class CassandraConnectorITCase method testCassandraPojoAtLeastOnceSink.
@Test
public void testCassandraPojoAtLeastOnceSink() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
DataStreamSource<Pojo> source = env.addSource(new SourceFunction<Pojo>() {
private boolean running = true;
private volatile int cnt = 0;
@Override
public void run(SourceContext<Pojo> ctx) throws Exception {
while (running) {
ctx.collect(new Pojo(UUID.randomUUID().toString(), cnt, 0));
cnt++;
if (cnt == 20) {
cancel();
}
}
}
@Override
public void cancel() {
running = false;
}
});
source.addSink(new CassandraPojoSink<>(Pojo.class, 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 verifyResultsWhenReScaling.
@Override
protected void verifyResultsWhenReScaling(CassandraTupleWriteAheadSink<Tuple3<String, Integer, Integer>> sink, int startElementCounter, int endElementCounter) {
// IMPORTANT NOTE:
//
// for cassandra we always have to start from 1 because
// all operators will share the same final db
ArrayList<Integer> expected = new ArrayList<>();
for (int i = 1; i <= endElementCounter; i++) {
expected.add(i);
}
ArrayList<Integer> actual = new ArrayList<>();
ResultSet result = session.execute(SELECT_DATA_QUERY);
for (Row s : result) {
actual.add(s.getInt("counter"));
}
Collections.sort(actual);
Assert.assertArrayEquals(expected.toArray(), actual.toArray());
}
use of com.datastax.driver.core.ResultSet in project cassandra by apache.
the class ViewTest method conflictingTimestampTest.
@Test
public void conflictingTimestampTest() throws Throwable {
createTable("CREATE TABLE %s (" + "a int," + "b int," + "c int," + "PRIMARY KEY (a, b))");
executeNet(protocolVersion, "USE " + keyspace());
createView("mv", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE c IS NOT NULL AND a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (c, a, b)");
for (int i = 0; i < 50; i++) {
updateView("INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP 1", 1, 1, i);
}
ResultSet mvRows = executeNet(protocolVersion, "SELECT c FROM mv");
List<Row> rows = executeNet(protocolVersion, "SELECT c FROM %s").all();
Assert.assertEquals("There should be exactly one row in base", 1, rows.size());
int expected = rows.get(0).getInt("c");
assertRowsNet(protocolVersion, mvRows, row(expected));
}
use of com.datastax.driver.core.ResultSet in project cassandra by apache.
the class PagingQueryTest method pagingOnRegularColumn.
@Test
public void pagingOnRegularColumn() throws Throwable {
createTable("CREATE TABLE %s (" + " k1 int," + " c1 int," + " c2 int," + " v1 text," + " v2 text," + " v3 text," + " v4 text," + "PRIMARY KEY (k1, c1, c2))");
for (int c1 = 0; c1 < 100; c1++) {
for (int c2 = 0; c2 < 100; c2++) {
execute("INSERT INTO %s (k1, c1, c2, v1, v2, v3, v4) VALUES (?, ?, ?, ?, ?, ?, ?)", 1, c1, c2, Integer.toString(c1), Integer.toString(c2), someText(), someText());
}
if (c1 % 30 == 0)
flush();
}
flush();
try (Session session = sessionNet()) {
SimpleStatement stmt = new SimpleStatement("SELECT c1, c2, v1, v2 FROM " + KEYSPACE + '.' + currentTable() + " WHERE k1 = 1");
stmt.setFetchSize(3);
ResultSet rs = session.execute(stmt);
Iterator<Row> iter = rs.iterator();
for (int c1 = 0; c1 < 100; c1++) {
for (int c2 = 0; c2 < 100; c2++) {
assertTrue(iter.hasNext());
Row row = iter.next();
String msg = "On " + c1 + ',' + c2;
assertEquals(msg, c1, row.getInt(0));
assertEquals(msg, c2, row.getInt(1));
assertEquals(msg, Integer.toString(c1), row.getString(2));
assertEquals(msg, Integer.toString(c2), row.getString(3));
}
}
assertFalse(iter.hasNext());
for (int c1 = 0; c1 < 100; c1++) {
stmt = new SimpleStatement("SELECT c1, c2, v1, v2 FROM " + KEYSPACE + '.' + currentTable() + " WHERE k1 = 1 AND c1 = ?", c1);
stmt.setFetchSize(3);
rs = session.execute(stmt);
iter = rs.iterator();
for (int c2 = 0; c2 < 100; c2++) {
assertTrue(iter.hasNext());
Row row = iter.next();
String msg = "Within " + c1 + " on " + c2;
assertEquals(msg, c1, row.getInt(0));
assertEquals(msg, c2, row.getInt(1));
assertEquals(msg, Integer.toString(c1), row.getString(2));
assertEquals(msg, Integer.toString(c2), row.getString(3));
}
assertFalse(iter.hasNext());
}
}
}
use of com.datastax.driver.core.ResultSet in project cassandra by apache.
the class ViewTest method testClusteringOrder.
@Test
public void testClusteringOrder() throws Throwable {
createTable("CREATE TABLE %s (" + "a int," + "b int," + "c int," + "d int," + "PRIMARY KEY (a, b, c))" + "WITH CLUSTERING ORDER BY (b ASC, c DESC)");
executeNet(protocolVersion, "USE " + keyspace());
createView("mv1", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE b IS NOT NULL AND c IS NOT NULL PRIMARY KEY (a, b, c) WITH CLUSTERING ORDER BY (b DESC)");
createView("mv2", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE b IS NOT NULL AND c IS NOT NULL PRIMARY KEY (a, c, b) WITH CLUSTERING ORDER BY (c ASC)");
createView("mv3", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE b IS NOT NULL AND c IS NOT NULL PRIMARY KEY (a, b, c)");
createView("mv4", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE b IS NOT NULL AND c IS NOT NULL PRIMARY KEY (a, c, b) WITH CLUSTERING ORDER BY (c DESC)");
updateView("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 1, 1, 1);
updateView("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 1, 2, 2, 2);
ResultSet mvRows = executeNet(protocolVersion, "SELECT b FROM mv1");
assertRowsNet(protocolVersion, mvRows, row(2), row(1));
mvRows = executeNet(protocolVersion, "SELECT c FROM mv2");
assertRowsNet(protocolVersion, mvRows, row(1), row(2));
mvRows = executeNet(protocolVersion, "SELECT b FROM mv3");
assertRowsNet(protocolVersion, mvRows, row(1), row(2));
mvRows = executeNet(protocolVersion, "SELECT c FROM mv4");
assertRowsNet(protocolVersion, mvRows, row(2), row(1));
}
Aggregations