Search in sources :

Example 46 with ResultSet

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());
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 47 with ResultSet

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());
}
Also used : ArrayList(java.util.ArrayList) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint)

Example 48 with ResultSet

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));
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 49 with ResultSet

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());
        }
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Test(org.junit.Test)

Example 50 with ResultSet

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));
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Test(org.junit.Test)

Aggregations

ResultSet (com.datastax.driver.core.ResultSet)95 Row (com.datastax.driver.core.Row)61 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)17 BoundStatement (com.datastax.driver.core.BoundStatement)13 Session (com.datastax.driver.core.Session)12 Cluster (com.datastax.driver.core.Cluster)10 Statement (com.datastax.driver.core.Statement)8 List (java.util.List)8 PreparedStatement (com.datastax.driver.core.PreparedStatement)7 ByteBuffer (java.nio.ByteBuffer)5 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)5 BatchStatement (com.datastax.driver.core.BatchStatement)4 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 Select (com.datastax.driver.core.querybuilder.Select)4 Tuple (io.vavr.Tuple)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)4 Entry (org.janusgraph.diskstorage.Entry)4