Search in sources :

Example 1 with SchemaAndId

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

the class SchemaRegisterInjectorTest method shouldRegisterKeyOverrideSchemaAvro.

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

Example 2 with SchemaAndId

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

the class SchemaRegisterInjectorTest method shouldThrowWrongValueFormatExceptionWithOverrideSchema.

@Test
public void shouldThrowWrongValueFormatExceptionWithOverrideSchema() {
    // Given:
    final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
    givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='KAFKA', " + "value_format='JSON', " + "value_schema_id=1, " + "partitions=1" + ");", Pair.of(null, schemaAndId));
    // When:
    final Exception e = assertThrows(KsqlStatementException.class, () -> injector.inject(statement));
    // Then:
    assertThat(e.getMessage(), containsString("VALUE_SCHEMA_ID is provided but format JSON doesn't " + "support registering in Schema Registry"));
}
Also used : SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) 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 3 with SchemaAndId

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

the class SchemaRegisterInjectorTest method shouldRegisterKeyValueOverrideSchema.

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

Example 4 with SchemaAndId

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

the class SchemaRegisterInjectorTest method shouldThrowInconsistentKeySchemaTypeExceptionWithOverrideSchema.

@Test
public void shouldThrowInconsistentKeySchemaTypeExceptionWithOverrideSchema() {
    // Given:
    final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
    givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='PROTOBUF', " + "value_format='JSON', " + "key_schema_id=1, " + "partitions=1" + ");", Pair.of(schemaAndId, null));
    // When:
    final Exception e = assertThrows(KsqlStatementException.class, () -> injector.inject(statement));
    // Then:
    assertThat(e.getMessage(), containsString("Format and fetched schema type using " + "KEY_SCHEMA_ID 1 are different. Format: [PROTOBUF], Fetched schema type: [AVRO]."));
}
Also used : SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) 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 5 with SchemaAndId

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

the class SchemaRegisterInjectorTest method shouldThrowInconsistentValueSchemaTypeExceptionWithOverrideSchema.

@Test
public void shouldThrowInconsistentValueSchemaTypeExceptionWithOverrideSchema() {
    // Given:
    final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
    givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='PROTOBUF', " + "value_format='PROTOBUF', " + "value_schema_id=1, " + "partitions=1" + ");", Pair.of(null, schemaAndId));
    // When:
    final Exception e = assertThrows(KsqlStatementException.class, () -> injector.inject(statement));
    // Then:
    assertThat(e.getMessage(), containsString("Format and fetched schema type using " + "VALUE_SCHEMA_ID 1 are different. Format: [PROTOBUF], Fetched schema type: [AVRO]."));
}
Also used : SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) 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)

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