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