Search in sources :

Example 1 with AvroFormat

use of io.confluent.ksql.serde.avro.AvroFormat in project ksql by confluentinc.

the class KsqlResourceFunctionalTest method shouldInsertIntoValuesForAvroTopic.

@Test
public void shouldInsertIntoValuesForAvroTopic() throws Exception {
    // Given:
    final PhysicalSchema schema = PhysicalSchema.from(LogicalSchema.builder().keyColumn(ColumnName.of("AUTHOR"), SqlTypes.STRING).valueColumn(ColumnName.of("TITLE"), SqlTypes.STRING).build(), SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES), SerdeFeatures.of());
    final SchemaTranslator translator = new AvroFormat().getSchemaTranslator(ImmutableMap.of(ConnectProperties.FULL_SCHEMA_NAME, "books_value"));
    final ParsedSchema keySchema = translator.toParsedSchema(PersistenceSchema.from(schema.logicalSchema().key(), schema.keySchema().features()));
    TEST_HARNESS.getSchemaRegistryClient().register(KsqlConstants.getSRSubject("books", true), keySchema);
    final ParsedSchema valueSchema = translator.toParsedSchema(PersistenceSchema.from(schema.logicalSchema().value(), schema.valueSchema().features()));
    TEST_HARNESS.getSchemaRegistryClient().register(KsqlConstants.getSRSubject("books", false), valueSchema);
    // When:
    final List<KsqlEntity> results = makeKsqlRequest("" + "CREATE STREAM books (author VARCHAR KEY, title VARCHAR) " + "WITH (kafka_topic='books', format='avro', partitions=1);" + " " + "INSERT INTO BOOKS (ROWTIME, author, title) VALUES (123, 'Metamorphosis', 'Franz Kafka');");
    // Then:
    assertSuccessful(results);
    TEST_HARNESS.verifyAvailableRows("books", contains(matches(genericKey("Metamorphosis"), genericRow("Franz Kafka"), 0, 0L, 123L)), FormatFactory.AVRO, FormatFactory.AVRO, schema);
}
Also used : SchemaTranslator(io.confluent.ksql.serde.SchemaTranslator) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) AvroFormat(io.confluent.ksql.serde.avro.AvroFormat) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 2 with AvroFormat

use of io.confluent.ksql.serde.avro.AvroFormat in project ksql by confluentinc.

the class IntegrationTestHarness method ensureSchema.

public void ensureSchema(final String topicName, final PhysicalSchema schema, final boolean keySchema) {
    final SchemaRegistryClient srClient = serviceContext.get().getSchemaRegistryClient();
    try {
        final Map<String, String> formatProps = ImmutableMap.of(ConnectProperties.FULL_SCHEMA_NAME, "test_" + topicName);
        final SchemaTranslator translator = new AvroFormat().getSchemaTranslator(formatProps);
        final ParsedSchema parsedSchema = translator.toParsedSchema(PersistenceSchema.from(keySchema ? schema.logicalSchema().key() : schema.logicalSchema().value(), keySchema ? schema.keySchema().features() : schema.valueSchema().features()));
        srClient.register(KsqlConstants.getSRSubject(topicName, keySchema), parsedSchema);
    } catch (final Exception e) {
        throw new AssertionError(e);
    }
}
Also used : SchemaTranslator(io.confluent.ksql.serde.SchemaTranslator) AvroFormat(io.confluent.ksql.serde.avro.AvroFormat) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)

Aggregations

ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)2 SchemaTranslator (io.confluent.ksql.serde.SchemaTranslator)2 AvroFormat (io.confluent.ksql.serde.avro.AvroFormat)2 IntegrationTest (io.confluent.common.utils.IntegrationTest)1 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)1 Test (org.junit.Test)1