Search in sources :

Example 11 with SimpleColumn

use of io.confluent.ksql.schema.ksql.SimpleColumn in project ksql by confluentinc.

the class ConnectFormatTest method createColumn.

private static SimpleColumn createColumn(final String name, final SqlType sqlType) {
    final SimpleColumn column = mock(SimpleColumn.class);
    when(column.name()).thenReturn(ColumnName.of(name));
    when(column.type()).thenReturn(sqlType);
    return column;
}
Also used : SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn)

Example 12 with SimpleColumn

use of io.confluent.ksql.schema.ksql.SimpleColumn in project ksql by confluentinc.

the class ConnectFormatTest method shouldCallSubclassToCreateInnerWhenUnwrapped.

@Test
public void shouldCallSubclassToCreateInnerWhenUnwrapped() {
    // Given:
    final SimpleColumn singleColumn = createColumn("bob", SqlTypes.INTEGER);
    when(persistenceSchema.columns()).thenReturn(ImmutableList.of(singleColumn));
    when(persistenceSchema.features()).thenReturn(SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
    final ConnectSchema fieldSchema = (ConnectSchema) SINGLE_FIELD_SCHEMA.fields().get(0).schema();
    // When:
    final Serde<List<?>> result = format.getSerde(persistenceSchema, formatProps, config, srFactory, false);
    // Then:
    verify(format).getConnectSerde(fieldSchema, formatProps, config, srFactory, Integer.class, false);
    assertThat(result.serializer(), instanceOf(UnwrappedSerializer.class));
    assertThat(result.deserializer(), instanceOf(UnwrappedDeserializer.class));
}
Also used : UnwrappedDeserializer(io.confluent.ksql.serde.unwrapped.UnwrappedDeserializer) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) UnwrappedSerializer(io.confluent.ksql.serde.unwrapped.UnwrappedSerializer) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn) Test(org.junit.Test)

Example 13 with SimpleColumn

use of io.confluent.ksql.schema.ksql.SimpleColumn in project ksql by confluentinc.

the class ConnectFormatTest method shouldThrowOnSerializationIfStructColumnValueDoesNotMatchSchema.

@Test
public void shouldThrowOnSerializationIfStructColumnValueDoesNotMatchSchema() {
    // Given:
    final SimpleColumn singleColumn = createColumn("bob", SqlTypes.struct().field("vic", SqlTypes.STRING).build());
    when(persistenceSchema.columns()).thenReturn(ImmutableList.of(singleColumn));
    final ConnectSchema connectSchema = (ConnectSchema) SchemaBuilder.struct().field("vic", Schema.STRING_SCHEMA).build();
    final Serializer<List<?>> serializer = format.getSerde(persistenceSchema, formatProps, config, srFactory, false).serializer();
    final List<?> values = ImmutableList.of(new Struct(connectSchema));
    // When:
    final Exception e = assertThrows(SerializationException.class, () -> serializer.serialize("topicName", values));
    // Then:
    assertThat(e.getMessage(), is("Failed to prepare Struct value field 'bob' for serialization. " + "This could happen if the value was produced by a user-defined function " + "where the schema has non-optional return types. ksqlDB requires all " + "schemas to be optional at all levels of the Struct: the Struct itself, " + "schemas for all fields within the Struct, and so on."));
}
Also used : ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn) SerializationException(org.apache.kafka.common.errors.SerializationException) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Aggregations

SimpleColumn (io.confluent.ksql.schema.ksql.SimpleColumn)13 Test (org.junit.Test)4 KsqlException (io.confluent.ksql.util.KsqlException)3 ConnectSchema (org.apache.kafka.connect.data.ConnectSchema)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)1 CreateTable (io.confluent.ksql.parser.tree.CreateTable)1 SqlToConnectTypeConverter (io.confluent.ksql.schema.ksql.SchemaConverters.SqlToConnectTypeConverter)1 SqlBaseType (io.confluent.ksql.schema.ksql.types.SqlBaseType)1 Format (io.confluent.ksql.serde.Format)1 SchemaTranslator (io.confluent.ksql.serde.SchemaTranslator)1 UnwrappedDeserializer (io.confluent.ksql.serde.unwrapped.UnwrappedDeserializer)1 UnwrappedSerializer (io.confluent.ksql.serde.unwrapped.UnwrappedSerializer)1 KsqlVoidSerde (io.confluent.ksql.serde.voids.KsqlVoidSerde)1 ArrayList (java.util.ArrayList)1 CSVParser (org.apache.commons.csv.CSVParser)1 SerializationException (org.apache.kafka.common.errors.SerializationException)1 Schema (org.apache.kafka.connect.data.Schema)1 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)1