Search in sources :

Example 71 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class PullQueryFunctionalTest method setUpClass.

@BeforeClass
public static void setUpClass() {
    TEST_HARNESS.ensureTopics(2, USER_TOPIC);
    final AtomicLong timestampSupplier = new AtomicLong(BASE_TIME);
    final Multimap<GenericKey, RecordMetadata> producedRows = TEST_HARNESS.produceRows(USER_TOPIC, USER_PROVIDER, KEY_FORMAT, VALUE_FORMAT, timestampSupplier::getAndIncrement);
    LOG.info("Produced rows: " + producedRows.size());
    makeAdminRequest("CREATE STREAM " + USERS_STREAM + " (" + USER_PROVIDER.ksqlSchemaString(false) + ")" + " WITH (" + "   kafka_topic='" + USER_TOPIC + "', " + "   value_format='" + VALUE_FORMAT.name() + "'" + ");");
}
Also used : RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) AtomicLong(java.util.concurrent.atomic.AtomicLong) GenericKey(io.confluent.ksql.GenericKey) BeforeClass(org.junit.BeforeClass)

Example 72 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class AssertExecutor method assertContent.

private static void assertContent(final KsqlExecutionContext engine, final KsqlConfig config, final InsertValues values, final TestDriverPipeline driverPipeline, final boolean isTombstone) {
    final boolean compareTimestamp = values.getColumns().stream().anyMatch(SystemColumns.ROWTIME_NAME::equals);
    final DataSource dataSource = engine.getMetaStore().getSource(values.getTarget());
    KsqlGenericRecord expected = new GenericRecordFactory(config, engine.getMetaStore(), System::currentTimeMillis).build(values.getColumns(), values.getValues(), dataSource.getSchema(), dataSource.getDataSourceType());
    if (isTombstone) {
        if (expected.value.values().stream().anyMatch(Objects::nonNull)) {
            throw new AssertionError("Unexpected value columns specified in ASSERT NULL VALUES.");
        }
        expected = KsqlGenericRecord.of(expected.key, null, expected.ts);
    }
    final Iterator<TestRecord<GenericKey, GenericRow>> records = driverPipeline.getRecordsForTopic(dataSource.getKafkaTopicName());
    if (!records.hasNext()) {
        throwAssertionError("Expected another record, but all records have already been read:", dataSource, expected, driverPipeline.getAllRecordsForTopic(dataSource.getKafkaTopicName()).stream().map(rec -> KsqlGenericRecord.of(rec.key(), rec.value(), rec.timestamp())).collect(Collectors.toList()));
    }
    final TestRecord<GenericKey, GenericRow> actualTestRecord = records.next();
    final KsqlGenericRecord actual = KsqlGenericRecord.of(actualTestRecord.key(), actualTestRecord.value(), compareTimestamp ? actualTestRecord.timestamp() : expected.ts);
    if (!actual.equals(expected)) {
        throwAssertionError("Expected record does not match actual.", dataSource, expected, ImmutableList.of(actual));
    }
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericRecordFactory(io.confluent.ksql.engine.generic.GenericRecordFactory) Objects(java.util.Objects) GenericKey(io.confluent.ksql.GenericKey) TestRecord(org.apache.kafka.streams.test.TestRecord) DataSource(io.confluent.ksql.metastore.model.DataSource) KsqlGenericRecord(io.confluent.ksql.engine.generic.KsqlGenericRecord)

Example 73 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class KeyUtilTest method shouldConvertNullKeyToList.

@Test
public void shouldConvertNullKeyToList() {
    // Given:
    final GenericKey key = GenericKey.genericKey((Object) null);
    // When:
    final List<?> result = KeyUtil.asList(key);
    // Then:
    assertThat(result, is(Collections.singletonList((null))));
}
Also used : GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 74 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class TableRowValidationTest method shouldThrowOnKeyFieldCountMismatch.

@Test(expected = IllegalArgumentException.class)
public void shouldThrowOnKeyFieldCountMismatch() {
    // Given:
    final GenericKey key = GenericKey.genericKey("key");
    // When:
    TableRowValidation.validate(SCHEMA, key, A_VALUE);
}
Also used : GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 75 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class KsMaterializedTableIQv2Test method getEmptyIteratorResult.

private static StateQueryResult getEmptyIteratorResult() {
    final StateQueryResult result = new StateQueryResult<>();
    Set<GenericKey> keySet = new HashSet<>();
    Map<GenericKey, ValueAndTimestamp<GenericRow>> map = new HashMap<>();
    final KeyValueIterator iterator = new TestKeyValueIterator(keySet, map);
    final QueryResult queryResult = QueryResult.forResult(iterator);
    queryResult.setPosition(POSITION);
    result.addResult(PARTITION, queryResult);
    return result;
}
Also used : ValueAndTimestamp(org.apache.kafka.streams.state.ValueAndTimestamp) QueryResult(org.apache.kafka.streams.query.QueryResult) StateQueryResult(org.apache.kafka.streams.query.StateQueryResult) HashMap(java.util.HashMap) KeyValueIterator(org.apache.kafka.streams.state.KeyValueIterator) StateQueryResult(org.apache.kafka.streams.query.StateQueryResult) GenericKey(io.confluent.ksql.GenericKey) HashSet(java.util.HashSet)

Aggregations

GenericKey (io.confluent.ksql.GenericKey)147 GenericRow (io.confluent.ksql.GenericRow)100 Test (org.junit.Test)93 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)24 Windowed (org.apache.kafka.streams.kstream.Windowed)20 WindowedRow (io.confluent.ksql.execution.streams.materialization.WindowedRow)14 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)14 Materialized (org.apache.kafka.streams.kstream.Materialized)13 ValueAndTimestamp (org.apache.kafka.streams.state.ValueAndTimestamp)13 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)12 MaterializationException (io.confluent.ksql.execution.streams.materialization.MaterializationException)9 IntegrationTest (io.confluent.common.utils.IntegrationTest)8 Materialization (io.confluent.ksql.execution.streams.materialization.Materialization)8 Row (io.confluent.ksql.execution.streams.materialization.Row)8 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)8 TimeWindow (org.apache.kafka.streams.kstream.internals.TimeWindow)8 IntegrationTest (org.apache.kafka.test.IntegrationTest)8 InOrder (org.mockito.InOrder)8 MaterializedTable (io.confluent.ksql.execution.streams.materialization.MaterializedTable)7 Objects (java.util.Objects)7