Search in sources :

Example 16 with SchemaAndId

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.

the class SchemaRegisterInjectorTest method shouldRegisterValueOverrideSchemaProtobuf.

@Test
public void shouldRegisterValueOverrideSchemaProtobuf() throws IOException, RestClientException {
    // Given:
    when(schemaRegistryClient.register(anyString(), any(ParsedSchema.class))).thenReturn(1);
    final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), PROTOBUF_SCHEMA, 1);
    givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='JSON', " + "value_format='PROTOBUF', " + "value_schema_id=1, " + "partitions=1" + ");", Pair.of(null, schemaAndId));
    // When:
    injector.inject(statement);
    // Then:
    verify(schemaRegistryClient).register("expectedName-value", PROTOBUF_SCHEMA);
}
Also used : SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Test(org.junit.Test)

Example 17 with SchemaAndId

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.

the class SchemaRegisterInjectorTest method shouldThrowWrongKeyFormatExceptionWithOverrideSchema.

@Test
public void shouldThrowWrongKeyFormatExceptionWithOverrideSchema() throws Exception {
    // Given:
    final SchemaAndId keySchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
    final SchemaAndId valueSchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 2);
    givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='KAFKA', " + "value_format='AVRO', " + "key_schema_id=1, " + "value_schema_id=1, " + "partitions=1" + ");", Pair.of(keySchemaAndId, valueSchemaAndId));
    // When:
    final Exception e = assertThrows(KsqlStatementException.class, () -> injector.inject(statement));
    // Then:
    assertThat(e.getMessage(), containsString("KEY_SCHEMA_ID is provided but format KAFKA doesn't " + "support registering in Schema Registry"));
    verify(schemaRegistryClient, never()).register(anyString(), any(ParsedSchema.class));
}
Also used : SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) KsqlSchemaRegistryNotConfiguredException(io.confluent.ksql.util.KsqlSchemaRegistryNotConfiguredException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlException(io.confluent.ksql.util.KsqlException) IOException(java.io.IOException) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) KsqlSchemaAuthorizationException(io.confluent.ksql.exception.KsqlSchemaAuthorizationException) Test(org.junit.Test)

Example 18 with SchemaAndId

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.

the class SchemaRegisterInjectorTest method shouldRegisterKeyOverrideSchemaAvroForCreateAs.

@Test
public void shouldRegisterKeyOverrideSchemaAvroForCreateAs() throws IOException, RestClientException {
    // Given:
    when(schemaRegistryClient.register(anyString(), any(ParsedSchema.class))).thenReturn(1);
    final SchemaAndId keySchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
    final SchemaAndId valueSchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
    givenStatement("CREATE STREAM sink WITH (key_schema_id=1, value_schema_id=1, partitions=1" + ") AS SELECT * FROM SOURCE;", Pair.of(keySchemaAndId, valueSchemaAndId));
    // When:
    injector.inject(statement);
    // Then:
    verify(schemaRegistryClient).register("SINK-key", AVRO_SCHEMA);
    verify(schemaRegistryClient).register("SINK-value", AVRO_SCHEMA);
}
Also used : SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Test(org.junit.Test)

Aggregations

SchemaAndId (io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId)18 Test (org.junit.Test)10 KsqlException (io.confluent.ksql.util.KsqlException)8 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)8 KsqlSchemaRegistryNotConfiguredException (io.confluent.ksql.util.KsqlSchemaRegistryNotConfiguredException)6 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)5 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)5 KsqlSchemaAuthorizationException (io.confluent.ksql.exception.KsqlSchemaAuthorizationException)5 IOException (java.io.IOException)5 CreateSourceAsProperties (io.confluent.ksql.parser.properties.with.CreateSourceAsProperties)4 CreateAsSelect (io.confluent.ksql.parser.tree.CreateAsSelect)4 FormatInfo (io.confluent.ksql.serde.FormatInfo)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 CreateSourceCommand (io.confluent.ksql.execution.ddl.commands.CreateSourceCommand)3 CreateSource (io.confluent.ksql.parser.tree.CreateSource)3 Column (io.confluent.ksql.schema.ksql.Column)3 SimpleColumn (io.confluent.ksql.schema.ksql.SimpleColumn)3 SerdeFeatures (io.confluent.ksql.serde.SerdeFeatures)3 CreateStream (io.confluent.ksql.parser.tree.CreateStream)2 Format (io.confluent.ksql.serde.Format)2