Search in sources :

Example 11 with Row

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

the class ClientMutationIntegrationTest method shouldInsertInto.

@Test
public void shouldInsertInto() throws Exception {
    // Given
    final KsqlObject insertRow = new KsqlObject().put("k", // Column names are case-insensitive
    new KsqlObject().put("F1", new KsqlArray().add("my_key"))).put("str", // Column names are case-insensitive
    "HELLO").put("`LONG`", // Backticks may be used to preserve case-sensitivity
    100L).put("\"DEC\"", // Double quotes may also be used to preserve case-sensitivity
    new BigDecimal("13.31")).put("BYTES_", new byte[] { 0, 1, 2 }).put("ARRAY", new KsqlArray().add("v1").add("v2")).put("MAP", new KsqlObject().put("some_key", "a_value").put("another_key", "")).put("STRUCT", // Nested field names are case-insensitive
    new KsqlObject().put("f1", 12)).put("COMPLEX", COMPLEX_FIELD_VALUE).put("TIMESTAMP", "1970-01-01T00:00:00.001").put("DATE", "1970-01-01").put("TIME", "00:00:01");
    // When
    // Stream name is case-insensitive
    client.insertInto(EMPTY_TEST_STREAM.toLowerCase(), insertRow).get();
    // Then: should receive new row
    final String query = "SELECT * FROM " + EMPTY_TEST_STREAM + " EMIT CHANGES LIMIT 1;";
    final List<Row> rows = client.executeQuery(query).get();
    // Verify inserted row is as expected
    assertThat(rows, hasSize(1));
    assertThat(rows.get(0).getKsqlObject("K"), is(new KsqlObject().put("F1", new KsqlArray().add("my_key"))));
    assertThat(rows.get(0).getString("STR"), is("HELLO"));
    assertThat(rows.get(0).getLong("LONG"), is(100L));
    assertThat(rows.get(0).getDecimal("DEC"), is(new BigDecimal("13.31")));
    assertThat(rows.get(0).getBytes("BYTES_"), is(new byte[] { 0, 1, 2 }));
    assertThat(rows.get(0).getKsqlArray("ARRAY"), is(new KsqlArray().add("v1").add("v2")));
    assertThat(rows.get(0).getKsqlObject("MAP"), is(new KsqlObject().put("some_key", "a_value").put("another_key", "")));
    assertThat(rows.get(0).getKsqlObject("STRUCT"), is(new KsqlObject().put("F1", 12)));
    assertThat(rows.get(0).getKsqlObject("COMPLEX"), is(EXPECTED_COMPLEX_FIELD_VALUE));
    assertThat(rows.get(0).getString("TIMESTAMP"), is("1970-01-01T00:00:00.001"));
    assertThat(rows.get(0).getString("DATE"), is("1970-01-01"));
    assertThat(rows.get(0).getString("TIME"), is("00:00:01"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Row(io.confluent.ksql.api.client.Row) KsqlArray(io.confluent.ksql.api.client.KsqlArray) BigDecimal(java.math.BigDecimal) KsqlObject(io.confluent.ksql.api.client.KsqlObject) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 12 with Row

use of io.confluent.ksql.api.client.Row 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 13 with Row

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

the class ValidateMigrationsCommandTest method givenAppliedMigrations.

/**
 * @param versions versions, in the order they were applied
 * @param checksums corresponding checksums (ordered according to {@code versions})
 * @param states corresponding migration states (ordered according to {@code versions})
 */
private void givenAppliedMigrations(final List<String> versions, final List<String> checksums, final List<MigrationState> states) throws Exception {
    String version = versions.size() > 0 ? versions.get(versions.size() - 1) : MetadataUtil.NONE_VERSION;
    Row row = mock(Row.class);
    BatchedQueryResult queryResult = mock(BatchedQueryResult.class);
    when(ksqlClient.executeQuery("SELECT VERSION FROM " + MIGRATIONS_TABLE + " WHERE version_key = '" + CURRENT_VERSION_KEY + "';")).thenReturn(queryResult);
    when(queryResult.get()).thenReturn(ImmutableList.of(row));
    when(row.getString("VERSION")).thenReturn(version);
    for (int i = versions.size() - 1; i >= 0; i--) {
        version = versions.get(i);
        String prevVersion = i > 0 ? versions.get(i - 1) : MetadataUtil.NONE_VERSION;
        row = mock(Row.class);
        queryResult = mock(BatchedQueryResult.class);
        when(ksqlClient.executeQuery("SELECT version, checksum, previous, state, name, started_on, completed_on, error_reason FROM " + MIGRATIONS_TABLE + " WHERE version_key = '" + version + "';")).thenReturn(queryResult);
        when(queryResult.get()).thenReturn(ImmutableList.of(row));
        when(row.getString(1)).thenReturn(version);
        when(row.getString(2)).thenReturn(checksums.get(i));
        when(row.getString(3)).thenReturn(prevVersion);
        when(row.getString(4)).thenReturn(states.get(i).toString());
        when(row.getString(5)).thenReturn("name");
        when(row.getString(6)).thenReturn("N/A");
        when(row.getString(7)).thenReturn("N/A");
        when(row.getString(8)).thenReturn("no_error");
    }
}
Also used : Row(io.confluent.ksql.api.client.Row) BatchedQueryResult(io.confluent.ksql.api.client.BatchedQueryResult)

Example 14 with Row

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

the class ApplyMigrationCommandTest method givenCurrentMigrationVersion.

private void givenCurrentMigrationVersion(final String version) throws Exception {
    final Row row = mock(Row.class);
    when(row.getString("VERSION")).thenReturn(version);
    when(versionQueryResult.get()).thenReturn(ImmutableList.of(row));
}
Also used : Row(io.confluent.ksql.api.client.Row)

Example 15 with Row

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

the class ApplyMigrationCommandTest method givenAppliedMigration.

private void givenAppliedMigration(final int version, final String name, final MigrationState state) throws Exception {
    final String checksum = MigrationsDirectoryUtil.computeHashForFile(getMigrationFilePath(version, name, migrationsDir));
    final String previous = version == 1 ? MetadataUtil.NONE_VERSION : Integer.toString(version - 1);
    final Row row = mock(Row.class);
    when(row.getString(1)).thenReturn(String.valueOf(version));
    when(row.getString(2)).thenReturn(checksum);
    when(row.getString(3)).thenReturn(previous);
    when(row.getString(4)).thenReturn(state.toString());
    when(row.getString(5)).thenReturn("name");
    when(row.getString(6)).thenReturn("N/A");
    when(row.getString(7)).thenReturn("N/A");
    when(row.getString(8)).thenReturn("no_error");
    when(infoQueryResult.get()).thenReturn(ImmutableList.of(row));
    when(ksqlClient.executeQuery("SELECT version, checksum, previous, state, name, started_on, completed_on, error_reason FROM " + MIGRATIONS_TABLE + " WHERE version_key = '" + version + "';")).thenReturn(infoQueryResult);
}
Also used : Row(io.confluent.ksql.api.client.Row)

Aggregations

Row (io.confluent.ksql.api.client.Row)27 Test (org.junit.Test)16 IntegrationTest (io.confluent.common.utils.IntegrationTest)13 StreamedQueryResult (io.confluent.ksql.api.client.StreamedQueryResult)10 GenericRow (io.confluent.ksql.GenericRow)8 BatchedQueryResult (io.confluent.ksql.api.client.BatchedQueryResult)7 Matchers.containsString (org.hamcrest.Matchers.containsString)6 KsqlObject (io.confluent.ksql.api.client.KsqlObject)5 ExecutionException (java.util.concurrent.ExecutionException)5 KsqlArray (io.confluent.ksql.api.client.KsqlArray)4 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)4 BigDecimal (java.math.BigDecimal)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 ZooKeeperClientException (kafka.zookeeper.ZooKeeperClientException)3 MigrationException (io.confluent.ksql.tools.migrations.MigrationException)2 JsonArray (io.vertx.core.json.JsonArray)2 JsonObject (io.vertx.core.json.JsonObject)2 ArrayList (java.util.ArrayList)2 AcksPublisher (io.confluent.ksql.api.client.AcksPublisher)1