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);
}
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);
}
}
Aggregations