use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.
the class DataSourceNodeTest method givenWindowedSource.
private void givenWindowedSource(final boolean windowed) {
final FormatInfo format = FormatInfo.of(FormatFactory.KAFKA.name());
final KeyFormat keyFormat = windowed ? KeyFormat.windowed(format, SerdeFeatures.of(), WindowInfo.of(WindowType.SESSION, Optional.empty())) : KeyFormat.nonWindowed(format, SerdeFeatures.of());
when(topic.getKeyFormat()).thenReturn(keyFormat);
}
use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.
the class CreateSourceFactory method buildFormats.
private Formats buildFormats(final SourceName name, final LogicalSchema schema, final CreateSourceProperties props, final KsqlConfig ksqlConfig) {
final FormatInfo keyFormat = SourcePropertiesUtil.getKeyFormat(props, name);
final FormatInfo valueFormat = SourcePropertiesUtil.getValueFormat(props);
final SerdeFeatures keyFeatures = keySerdeFeaturesSupplier.build(schema, FormatFactory.of(keyFormat), SerdeFeatures.of(), ksqlConfig);
final SerdeFeatures valFeatures = valueSerdeFeaturesSupplier.build(schema, FormatFactory.of(valueFormat), props.getValueSerdeFeatures(), ksqlConfig);
final Formats formats = Formats.of(keyFormat, valueFormat, keyFeatures, valFeatures);
validateSerdesCanHandleSchemas(ksqlConfig, schema, formats);
return formats;
}
use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.
the class DefaultFormatInjector method injectForCreateStatement.
private Optional<ConfiguredStatement<CreateSource>> injectForCreateStatement(final ConfiguredStatement<CreateSource> original) {
final CreateSource statement = original.getStatement();
final CreateSourceProperties properties = statement.getProperties();
final Optional<FormatInfo> keyFormat = properties.getKeyFormat(statement.getName());
final Optional<FormatInfo> valueFormat = properties.getValueFormat();
if (keyFormat.isPresent() && valueFormat.isPresent()) {
return Optional.empty();
}
final KsqlConfig config = getConfig(original);
final CreateSourceProperties injectedProps = properties.withFormats(keyFormat.map(FormatInfo::getFormat).orElseGet(() -> getDefaultKeyFormat(config)), valueFormat.map(FormatInfo::getFormat).orElseGet(() -> getDefaultValueFormat(config)));
final CreateSource withFormats = statement.copyWith(original.getStatement().getElements(), injectedProps);
final PreparedStatement<CreateSource> prepared = buildPreparedStatement(withFormats);
final ConfiguredStatement<CreateSource> configured = ConfiguredStatement.of(prepared, original.getSessionConfig());
return Optional.of(configured);
}
use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.
the class CreateSourcePropertiesTest method shouldSetValidAvroSchemaName.
@Test
public void shouldSetValidAvroSchemaName() {
// When:
final CreateSourceProperties properties = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral("AvRo")).put(CommonCreateConfigs.VALUE_AVRO_SCHEMA_FULL_NAME, new StringLiteral("schema")).build());
// Then:
assertThat(properties.getValueFormat().map(FormatInfo::getProperties).map(props -> props.get(ConnectProperties.FULL_SCHEMA_NAME)), is(Optional.of("schema")));
}
use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.
the class DefaultSchemaInjector method getValueSchema.
private Optional<SchemaAndId> getValueSchema(final ConfiguredStatement<CreateSource> statement) {
final CreateSourceProperties props = statement.getStatement().getProperties();
final FormatInfo valueFormat = SourcePropertiesUtil.getValueFormat(props);
if (!shouldInferSchema(props.getValueSchemaId(), statement, valueFormat, false)) {
return Optional.empty();
}
return Optional.of(getSchema(Optional.of(props.getKafkaTopic()), props.getValueSchemaId(), valueFormat, props.getValueSerdeFeatures(), statement.getStatementText(), false));
}
Aggregations