Search in sources :

Example 46 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project beam by apache.

the class SpannerChangeStreamErrorTest method testInvalidRecordReceived.

@Test
public void testInvalidRecordReceived() {
    final Timestamp now = Timestamp.now();
    final Timestamp after3Seconds = Timestamp.ofTimeSecondsAndNanos(now.getSeconds() + 3, now.getNanos());
    mockTableExists();
    ResultSet getPartitionResultSet = mockGetParentPartition(now, after3Seconds);
    mockGetWatermark(now);
    mockGetPartitionsAfter(Timestamp.ofTimeSecondsAndNanos(now.getSeconds(), now.getNanos() + 1000), getPartitionResultSet);
    mockGetPartitionsAfter(Timestamp.ofTimeSecondsAndNanos(now.getSeconds(), now.getNanos() - 1000), getPartitionResultSet);
    mockInvalidChangeStreamRecordReceived(now, after3Seconds);
    try {
        pipeline.apply(SpannerIO.readChangeStream().withSpannerConfig(getSpannerConfig()).withChangeStreamName(TEST_CHANGE_STREAM).withMetadataDatabase(TEST_DATABASE).withMetadataTable(TEST_TABLE).withInclusiveStartAt(now).withInclusiveEndAt(after3Seconds));
        pipeline.run().waitUntilFinish();
    } finally {
        thrown.expect(PipelineExecutionException.class);
        thrown.expectMessage("Field not found");
    }
}
Also used : ResultSet(com.google.spanner.v1.ResultSet) Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Example 47 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project beam by apache.

the class SpannerChangeStreamErrorTest method mockGetWatermark.

private void mockGetWatermark(Timestamp now) {
    Statement watermarkStatement = Statement.newBuilder("SELECT Watermark FROM my-metadata-table WHERE State != @state ORDER BY Watermark ASC LIMIT 1").bind("state").to(State.FINISHED.name()).build();
    ResultSetMetadata watermarkResultSetMetadata = ResultSetMetadata.newBuilder().setRowType(StructType.newBuilder().addFields(Field.newBuilder().setName("Watermark").setType(Type.newBuilder().setCode(TypeCode.TIMESTAMP).build()).build()).build()).build();
    ResultSet watermarkResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue(now.toString()).build()).build()).setMetadata(watermarkResultSetMetadata).build();
    mockSpannerService.putStatementResult(StatementResult.query(watermarkStatement, watermarkResultSet));
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) ResultSet(com.google.spanner.v1.ResultSet)

Example 48 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class BinAuditLoggerTest method testSelectRoundTripQuery.

@Test
public void testSelectRoundTripQuery() throws Throwable {
    createTable("CREATE TABLE %s (id int primary key, v1 text, v2 text)");
    execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 1, "Apache", "Cassandra");
    execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 2, "trace", "test");
    String cql = "SELECT id, v1, v2 FROM " + KEYSPACE + '.' + currentTable() + " WHERE id = ?";
    Session session = sessionNet();
    PreparedStatement pstmt = session.prepare(cql);
    ResultSet rs = session.execute(pstmt.bind(1));
    assertEquals(1, rs.all().size());
    try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
        ExcerptTailer tailer = queue.createTailer();
        assertTrue(tailer.readDocument(wire -> {
            assertEquals(0L, wire.read("version").int16());
            assertEquals("audit", wire.read("type").text());
            assertThat(wire.read("message").text(), containsString(AuditLogEntryType.PREPARE_STATEMENT.toString()));
        }));
        assertTrue(tailer.readDocument(wire -> {
            assertEquals(0L, wire.read("version").int16());
            assertEquals("audit", wire.read("type").text());
            assertThat(wire.read("message").text(), containsString(AuditLogEntryType.SELECT.toString()));
        }));
        assertFalse(tailer.readDocument(wire -> {
        }));
    }
}
Also used : ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) BeforeClass(org.junit.BeforeClass) CQLTester(org.apache.cassandra.cql3.CQLTester) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) PreparedStatement(com.datastax.driver.core.PreparedStatement) Assert.assertThat(org.junit.Assert.assertThat) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ResultSet(com.datastax.driver.core.ResultSet) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) Assert.assertFalse(org.junit.Assert.assertFalse) Session(com.datastax.driver.core.Session) RollCycles(net.openhft.chronicle.queue.RollCycles) BinLogTest(org.apache.cassandra.utils.binlog.BinLogTest) Path(java.nio.file.Path) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Session(com.datastax.driver.core.Session) Test(org.junit.Test) BinLogTest(org.apache.cassandra.utils.binlog.BinLogTest)

Example 49 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class NativeProtocolTest method withClientRequests.

@Test
public void withClientRequests() throws Throwable {
    try (ICluster ignored = init(builder().withNodes(3).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).start())) {
        try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
            Session session = cluster.connect()) {
            session.execute("CREATE TABLE " + KEYSPACE + ".tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));");
            session.execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) values (1,1,1);");
            Statement select = new SimpleStatement("select * from " + KEYSPACE + ".tbl;").setConsistencyLevel(ConsistencyLevel.ALL);
            final ResultSet resultSet = session.execute(select);
            assertRows(RowUtil.toObjects(resultSet), row(1, 1, 1));
            Assert.assertEquals(3, cluster.getMetadata().getAllHosts().size());
        }
    }
}
Also used : SimpleStatement(com.datastax.driver.core.SimpleStatement) CQLStatement(org.apache.cassandra.cql3.CQLStatement) Statement(com.datastax.driver.core.Statement) SimpleStatement(com.datastax.driver.core.SimpleStatement) ICluster(org.apache.cassandra.distributed.api.ICluster) ResultSet(com.datastax.driver.core.ResultSet) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 50 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class AggregationTest method testAggregateWithWriteTimeOrTTL.

@Test
public void testAggregateWithWriteTimeOrTTL() throws Throwable {
    createTable("CREATE TABLE %s (a int primary key, b int, c int)");
    // Test with empty table
    assertColumnNames(execute("SELECT count(writetime(b)), min(ttl(b)) as min, writetime(b), ttl(c) as first FROM %s"), "system.count(writetime(b))", "min", "writetime(b)", "first");
    assertRows(execute("SELECT count(writetime(b)), min(ttl(b)) as min, writetime(b), ttl(c) as first FROM %s"), row(0L, null, null, null));
    long today = System.currentTimeMillis() * 1000;
    long yesterday = today - (DateUtils.MILLIS_PER_DAY * 1000);
    final int secondsPerMinute = 60;
    execute("INSERT INTO %s (a, b, c) VALUES (1, 2, null) USING TTL " + (20 * secondsPerMinute));
    execute("INSERT INTO %s (a, b, c) VALUES (2, 4, 6) USING TTL " + (10 * secondsPerMinute));
    execute("INSERT INTO %s (a, b, c) VALUES (4, 8, 12) USING TIMESTAMP " + yesterday);
    assertRows(execute("SELECT count(writetime(b)), count(ttl(b)) FROM %s"), row(3L, 2L));
    UntypedResultSet resultSet = execute("SELECT min(ttl(b)), ttl(b) FROM %s");
    assertEquals(1, resultSet.size());
    Row row = resultSet.one();
    assertTrue(row.getInt("ttl(b)") > (10 * secondsPerMinute));
    assertTrue(row.getInt("system.min(ttl(b))") <= (10 * secondsPerMinute));
    resultSet = execute("SELECT min(writetime(b)), writetime(b) FROM %s");
    assertEquals(1, resultSet.size());
    row = resultSet.one();
    assertTrue(row.getLong("writetime(b)") >= today);
    assertTrue(row.getLong("system.min(writetime(b))") == yesterday);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Row(org.apache.cassandra.cql3.UntypedResultSet.Row) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)32 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)12 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)9 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)8 Function (com.google.common.base.Function)8 DateTime (org.joda.time.DateTime)6 ResultSet (com.google.spanner.v1.ResultSet)5 ResultSet (com.datastax.driver.core.ResultSet)4 Session (com.datastax.driver.core.Session)4 ResultSet (com.google.api.ads.admanager.axis.v202105.ResultSet)4 Row (com.google.api.ads.admanager.axis.v202108.Row)4 Row (com.google.api.ads.admanager.axis.v202111.Row)4 Row (com.google.api.ads.admanager.axis.v202202.Row)4