Search in sources :

Example 1 with FormatInfo

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);
}
Also used : FormatInfo(io.confluent.ksql.serde.FormatInfo) KeyFormat(io.confluent.ksql.serde.KeyFormat)

Example 2 with FormatInfo

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;
}
Also used : Formats(io.confluent.ksql.execution.plan.Formats) FormatInfo(io.confluent.ksql.serde.FormatInfo) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures)

Example 3 with FormatInfo

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);
}
Also used : CreateSource(io.confluent.ksql.parser.tree.CreateSource) KsqlConfig(io.confluent.ksql.util.KsqlConfig) FormatInfo(io.confluent.ksql.serde.FormatInfo) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties)

Example 4 with FormatInfo

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")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KAFKA_TOPIC_NAME_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.KAFKA_TOPIC_NAME_PROPERTY) FORMAT_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.FORMAT_PROPERTY) CreateSourceAsProperties.from(io.confluent.ksql.parser.properties.with.CreateSourceAsProperties.from) ColumnName(io.confluent.ksql.name.ColumnName) SourceName(io.confluent.ksql.name.SourceName) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CommonCreateConfigs(io.confluent.ksql.properties.with.CommonCreateConfigs) Function(java.util.function.Function) VALUE_SCHEMA_ID(io.confluent.ksql.properties.with.CommonCreateConfigs.VALUE_SCHEMA_ID) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ConnectProperties(io.confluent.ksql.serde.connect.ConnectProperties) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Duration(java.time.Duration) Map(java.util.Map) WindowType(io.confluent.ksql.model.WindowType) CreateConfigs(io.confluent.ksql.properties.with.CreateConfigs) WINDOW_SIZE_PROPERTY(io.confluent.ksql.properties.with.CreateConfigs.WINDOW_SIZE_PROPERTY) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) TIMESTAMP_FORMAT_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.TIMESTAMP_FORMAT_PROPERTY) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) KEY_FORMAT_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.KEY_FORMAT_PROPERTY) VALUE_FORMAT_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.VALUE_FORMAT_PROPERTY) VALUE_AVRO_SCHEMA_FULL_NAME(io.confluent.ksql.properties.with.CommonCreateConfigs.VALUE_AVRO_SCHEMA_FULL_NAME) ImmutableMap(com.google.common.collect.ImmutableMap) SerdeFeature(io.confluent.ksql.serde.SerdeFeature) Literal(io.confluent.ksql.execution.expression.tree.Literal) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) EqualsTester(com.google.common.testing.EqualsTester) KEY_SCHEMA_FULL_NAME(io.confluent.ksql.properties.with.CommonCreateConfigs.KEY_SCHEMA_FULL_NAME) VALUE_SCHEMA_FULL_NAME(io.confluent.ksql.properties.with.CommonCreateConfigs.VALUE_SCHEMA_FULL_NAME) WINDOW_TYPE_PROPERTY(io.confluent.ksql.properties.with.CreateConfigs.WINDOW_TYPE_PROPERTY) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) KEY_SCHEMA_ID(io.confluent.ksql.properties.with.CommonCreateConfigs.KEY_SCHEMA_ID) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FormatInfo(io.confluent.ksql.serde.FormatInfo) Matchers.containsString(org.hamcrest.Matchers.containsString) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) FormatInfo(io.confluent.ksql.serde.FormatInfo) Test(org.junit.Test)

Example 5 with FormatInfo

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));
}
Also used : FormatInfo(io.confluent.ksql.serde.FormatInfo) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties)

Aggregations

FormatInfo (io.confluent.ksql.serde.FormatInfo)16 SerdeFeatures (io.confluent.ksql.serde.SerdeFeatures)8 Optional (java.util.Optional)5 ColumnName (io.confluent.ksql.name.ColumnName)4 CreateSourceProperties (io.confluent.ksql.parser.properties.with.CreateSourceProperties)4 CreateSource (io.confluent.ksql.parser.tree.CreateSource)4 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)4 KeyFormat (io.confluent.ksql.serde.KeyFormat)4 KsqlException (io.confluent.ksql.util.KsqlException)4 WindowType (io.confluent.ksql.model.WindowType)3 SchemaAndId (io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId)3 KsqlConfig (io.confluent.ksql.util.KsqlConfig)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.of (com.google.common.collect.ImmutableMap.of)2 EqualsTester (com.google.common.testing.EqualsTester)2 QueryContext (io.confluent.ksql.execution.context.QueryContext)2 Stacker (io.confluent.ksql.execution.context.QueryContext.Stacker)2 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)2 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)2 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)2