Search in sources :

Example 6 with StreamedQueryResult

use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.

the class ClientMutationIntegrationTest method shouldStreamQueryWithProperties.

@Test
public void shouldStreamQueryWithProperties() throws Exception {
    // Given
    final Map<String, Object> properties = new HashMap<>();
    properties.put("auto.offset.reset", "latest");
    final String sql = "SELECT * FROM " + TEST_STREAM + " EMIT CHANGES LIMIT 1;";
    final KsqlObject insertRow = new KsqlObject().put("K", new KsqlObject().put("F1", new KsqlArray().add("my_key_shouldStreamQueryWithProperties"))).put("STR", "Value_shouldStreamQueryWithProperties").put("LONG", 2000L).put("DEC", new BigDecimal("12.34")).put("BYTES_", new byte[] { 0, 1, 2 }).put("ARRAY", new KsqlArray().add("v1_shouldStreamQueryWithProperties").add("v2_shouldStreamQueryWithProperties")).put("MAP", new KsqlObject().put("test_name", "shouldStreamQueryWithProperties")).put("STRUCT", new KsqlObject().put("F1", 4)).put("COMPLEX", COMPLEX_FIELD_VALUE).put("TIMESTAMP", "1970-01-01T00:00:00.001").put("DATE", "1970-01-01").put("TIME", "00:00:00");
    // When
    final StreamedQueryResult queryResult = client.streamQuery(sql, properties).get();
    // Then: a newly inserted row arrives
    final Row row = assertThatEventually(() -> {
        // Potentially try inserting multiple times, in case the query wasn't started by the first time
        try {
            client.insertInto(TEST_STREAM, insertRow).get();
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
        return queryResult.poll(Duration.ofMillis(10));
    }, is(notNullValue()));
    assertThat(row.getKsqlObject("K"), is(new KsqlObject().put("F1", new KsqlArray().add("my_key_shouldStreamQueryWithProperties"))));
    assertThat(row.getString("STR"), is("Value_shouldStreamQueryWithProperties"));
    assertThat(row.getLong("LONG"), is(2000L));
    assertThat(row.getDecimal("DEC"), is(new BigDecimal("12.34")));
    assertThat(row.getBytes("BYTES_"), is(new byte[] { 0, 1, 2 }));
    assertThat(row.getKsqlArray("ARRAY"), is(new KsqlArray().add("v1_shouldStreamQueryWithProperties").add("v2_shouldStreamQueryWithProperties")));
    assertThat(row.getKsqlObject("MAP"), is(new KsqlObject().put("test_name", "shouldStreamQueryWithProperties")));
    assertThat(row.getKsqlObject("STRUCT"), is(new KsqlObject().put("F1", 4)));
    assertThat(row.getKsqlObject("COMPLEX"), is(EXPECTED_COMPLEX_FIELD_VALUE));
    assertThat(row.getString("TIMESTAMP"), is("1970-01-01T00:00:00.001"));
    assertThat(row.getString("DATE"), is("1970-01-01"));
    assertThat(row.getString("TIME"), is("00:00"));
}
Also used : HashMap(java.util.HashMap) KsqlObject(io.confluent.ksql.api.client.KsqlObject) Matchers.containsString(org.hamcrest.Matchers.containsString) Row(io.confluent.ksql.api.client.Row) KsqlArray(io.confluent.ksql.api.client.KsqlArray) BigDecimal(java.math.BigDecimal) ZooKeeperClientException(kafka.zookeeper.ZooKeeperClientException) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) ExecutionException(java.util.concurrent.ExecutionException) KsqlObject(io.confluent.ksql.api.client.KsqlObject) StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 7 with StreamedQueryResult

use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.

the class ClientIntegrationTest method shouldStreamPullQueryOnTableSync.

@Test
public void shouldStreamPullQueryOnTableSync() throws Exception {
    // When
    final StreamedQueryResult streamedQueryResult = client.streamQuery(PULL_QUERY_ON_TABLE).get();
    // Then
    assertThat(streamedQueryResult.columnNames(), is(PULL_QUERY_COLUMN_NAMES));
    assertThat(streamedQueryResult.columnTypes(), is(PULL_QUERY_COLUMN_TYPES));
    assertThat(streamedQueryResult.queryID(), is(notNullValue()));
    final Row row = streamedQueryResult.poll();
    verifyPullQueryRow(row);
    assertThat(streamedQueryResult.poll(), is(nullValue()));
    assertThatEventually(streamedQueryResult::isComplete, is(true));
}
Also used : Row(io.confluent.ksql.api.client.Row) GenericRow(io.confluent.ksql.GenericRow) StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Example 8 with StreamedQueryResult

use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.

the class ConsistencyOffsetVectorFunctionalTest method shouldNotRoundTripCVWhenPullQueryOnTableAsync.

@Test
public void shouldNotRoundTripCVWhenPullQueryOnTableAsync() throws Exception {
    // When
    final StreamedQueryResult streamedQueryResult = eventualClient.streamQuery(PULL_QUERY_ON_TABLE).get();
    // Then
    shouldReceiveRows(streamedQueryResult, 1, // do nothing
    (v) -> {
    }, true);
    assertThatEventually(streamedQueryResult::isComplete, is(true));
    assertThat(((ClientImpl) eventualClient).getSerializedConsistencyVector(), is(isEmptyString()));
}
Also used : StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) Test(org.junit.Test)

Example 9 with StreamedQueryResult

use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.

the class ConsistencyOffsetVectorFunctionalTest method shouldNotRoundTripCVWhenPullQueryOnTableSync.

@Test
public void shouldNotRoundTripCVWhenPullQueryOnTableSync() throws Exception {
    // When
    final StreamedQueryResult streamedQueryResult = eventualClient.streamQuery(PULL_QUERY_ON_TABLE).get();
    streamedQueryResult.poll();
    // Then
    assertThatEventually(streamedQueryResult::isComplete, is(true));
    assertThatEventually(() -> ((ClientImpl) eventualClient).getSerializedConsistencyVector(), is(isEmptyString()));
}
Also used : StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) Test(org.junit.Test)

Example 10 with StreamedQueryResult

use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.

the class ConsistencyOffsetVectorFunctionalTest method shouldRoundTripCVWhenPullQueryOnTableSync.

@Test
public void shouldRoundTripCVWhenPullQueryOnTableSync() throws Exception {
    // When
    final StreamedQueryResult streamedQueryResult = consistencClient.streamQuery(PULL_QUERY_ON_TABLE).get();
    streamedQueryResult.poll();
    // Then
    assertThatEventually(streamedQueryResult::isComplete, is(true));
    assertThatEventually(() -> ((ClientImpl) consistencClient).getSerializedConsistencyVector(), is(notNullValue()));
    final String serializedCV = ((ClientImpl) consistencClient).getSerializedConsistencyVector();
    verifyConsistencyVector(serializedCV);
}
Also used : ClientImpl(io.confluent.ksql.api.client.impl.ClientImpl) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) Test(org.junit.Test)

Aggregations

StreamedQueryResult (io.confluent.ksql.api.client.StreamedQueryResult)20 Test (org.junit.Test)20 IntegrationTest (io.confluent.common.utils.IntegrationTest)16 Row (io.confluent.ksql.api.client.Row)10 GenericRow (io.confluent.ksql.GenericRow)8 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 KsqlObject (io.confluent.ksql.api.client.KsqlObject)2 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)2 ClientImpl (io.confluent.ksql.api.client.impl.ClientImpl)2 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ZooKeeperClientException (kafka.zookeeper.ZooKeeperClientException)2 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)2 KsqlArray (io.confluent.ksql.api.client.KsqlArray)1 BigDecimal (java.math.BigDecimal)1