Search in sources :

Example 11 with FormatInfo

use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.

the class SchemaKStream method throwOnJoinKeyFormatsMismatch.

void throwOnJoinKeyFormatsMismatch(final SchemaKStream<?> right) {
    final FormatInfo leftFmt = this.keyFormat.getFormatInfo();
    final FormatInfo rightFmt = right.keyFormat.getFormatInfo();
    if (!leftFmt.equals(rightFmt)) {
        throw new IllegalArgumentException("Key format mismatch in join. " + "left: " + leftFmt + ", right: " + rightFmt);
    }
    final SerdeFeatures leftFeats = this.keyFormat.getFeatures();
    final SerdeFeatures rightFeats = right.keyFormat.getFeatures();
    if (!leftFeats.equals(rightFeats)) {
        throw new IllegalArgumentException("Key format features mismatch in join. " + "left: " + leftFeats + ", right: " + rightFeats);
    }
    final Optional<WindowType> leftWnd = this.keyFormat.getWindowInfo().map(WindowInfo::getType);
    final Optional<WindowType> rightWnd = right.keyFormat.getWindowInfo().map(WindowInfo::getType);
    if (leftWnd.isPresent() != rightWnd.isPresent()) {
        throw new IllegalArgumentException("Key format windowing mismatch in join. " + "left: " + leftWnd + ", right: " + rightWnd);
    }
    final boolean leftIsSession = leftWnd.map(type -> type == WindowType.SESSION).orElse(false);
    final boolean rightIsSession = rightWnd.map(type -> type == WindowType.SESSION).orElse(false);
    if (leftIsSession != rightIsSession) {
        throw new IllegalArgumentException("Key format window type mismatch in join. " + "left: " + (leftIsSession ? "Session Windowed" : "Non Session Windowed") + ", right: " + (rightIsSession ? "Session Windowed" : "Non Session Windowed"));
    }
}
Also used : StatementRewriteForMagicPseudoTimestamp(io.confluent.ksql.engine.rewrite.StatementRewriteForMagicPseudoTimestamp) ColumnName(io.confluent.ksql.name.ColumnName) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) StreamFilter(io.confluent.ksql.execution.plan.StreamFilter) KeyFormat(io.confluent.ksql.serde.KeyFormat) QueryContext(io.confluent.ksql.execution.context.QueryContext) JoinType(io.confluent.ksql.execution.plan.JoinType) SerdeFeaturesFactory(io.confluent.ksql.serde.SerdeFeaturesFactory) Formats(io.confluent.ksql.execution.plan.Formats) StreamGroupByKey(io.confluent.ksql.execution.plan.StreamGroupByKey) StepSchemaResolver(io.confluent.ksql.execution.streams.StepSchemaResolver) WindowInfo(io.confluent.ksql.serde.WindowInfo) NoneFormat(io.confluent.ksql.serde.none.NoneFormat) StreamSelect(io.confluent.ksql.execution.plan.StreamSelect) Objects.requireNonNull(java.util.Objects.requireNonNull) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) WindowType(io.confluent.ksql.model.WindowType) Repartitioning(io.confluent.ksql.util.Repartitioning) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ExecutionStepFactory(io.confluent.ksql.execution.streams.ExecutionStepFactory) StreamTableJoin(io.confluent.ksql.execution.plan.StreamTableJoin) ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) PlanBuildContext(io.confluent.ksql.planner.plan.PlanBuildContext) Expression(io.confluent.ksql.execution.expression.tree.Expression) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) KsqlConfig(io.confluent.ksql.util.KsqlConfig) InternalFormats(io.confluent.ksql.serde.InternalFormats) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) Objects(java.util.Objects) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) List(java.util.List) StreamStreamJoin(io.confluent.ksql.execution.plan.StreamStreamJoin) StreamSink(io.confluent.ksql.execution.plan.StreamSink) Stacker(io.confluent.ksql.execution.context.QueryContext.Stacker) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) StreamFlatMap(io.confluent.ksql.execution.plan.StreamFlatMap) FormatInfo(io.confluent.ksql.serde.FormatInfo) StreamGroupBy(io.confluent.ksql.execution.plan.StreamGroupBy) FormatInfo(io.confluent.ksql.serde.FormatInfo) WindowType(io.confluent.ksql.model.WindowType) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) WindowInfo(io.confluent.ksql.serde.WindowInfo)

Example 12 with FormatInfo

use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.

the class DefaultSchemaInjector method getCreateAsKeySchema.

private Optional<SchemaAndId> getCreateAsKeySchema(final ConfiguredStatement<CreateAsSelect> statement, final CreateSourceCommand createSourceCommand) {
    final CreateAsSelect csStmt = statement.getStatement();
    final CreateSourceAsProperties props = csStmt.getProperties();
    final FormatInfo keyFormat = createSourceCommand.getFormats().getKeyFormat();
    if (!shouldInferSchema(props.getKeySchemaId(), statement, keyFormat, true)) {
        return Optional.empty();
    }
    // until we support user-configuration of single key wrapping/unwrapping, we choose
    // to have key schema inference always result in an unwrapped key
    final SerdeFeatures serdeFeatures = SerdeFeaturesFactory.buildKeyFeatures(FormatFactory.of(keyFormat), true);
    if (!shouldInferSchema(props.getKeySchemaId(), statement, keyFormat, true)) {
        return Optional.empty();
    }
    final SchemaAndId schemaAndId = getSchema(props.getKafkaTopic(), props.getKeySchemaId(), keyFormat, serdeFeatures, statement.getStatementText(), true);
    final List<Column> tableColumns = createSourceCommand.getSchema().key();
    checkColumnsCompatibility(props.getKeySchemaId(), tableColumns, schemaAndId.columns, true);
    return Optional.of(schemaAndId);
}
Also used : SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn) Column(io.confluent.ksql.schema.ksql.Column) CreateSourceAsProperties(io.confluent.ksql.parser.properties.with.CreateSourceAsProperties) CreateAsSelect(io.confluent.ksql.parser.tree.CreateAsSelect) FormatInfo(io.confluent.ksql.serde.FormatInfo) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures)

Example 13 with FormatInfo

use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.

the class DefaultSchemaInjector method getKeySchema.

private Optional<SchemaAndId> getKeySchema(final ConfiguredStatement<CreateSource> statement) {
    final CreateSource csStmt = statement.getStatement();
    final CreateSourceProperties props = csStmt.getProperties();
    final FormatInfo keyFormat = SourcePropertiesUtil.getKeyFormat(props, csStmt.getName());
    if (!shouldInferSchema(props.getKeySchemaId(), statement, keyFormat, true)) {
        return Optional.empty();
    }
    return Optional.of(getSchema(Optional.of(props.getKafkaTopic()), props.getKeySchemaId(), keyFormat, // to have key schema inference always result in an unwrapped key
    SerdeFeaturesFactory.buildKeyFeatures(FormatFactory.of(keyFormat), true), statement.getStatementText(), true));
}
Also used : CreateSource(io.confluent.ksql.parser.tree.CreateSource) FormatInfo(io.confluent.ksql.serde.FormatInfo) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties)

Example 14 with FormatInfo

use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.

the class DefaultSchemaInjector method getCreateAsValueSchema.

private Optional<SchemaAndId> getCreateAsValueSchema(final ConfiguredStatement<CreateAsSelect> statement, final CreateSourceCommand createSourceCommand) {
    final CreateAsSelect csStmt = statement.getStatement();
    final CreateSourceAsProperties props = csStmt.getProperties();
    final FormatInfo valueFormat = createSourceCommand.getFormats().getValueFormat();
    if (!shouldInferSchema(props.getValueSchemaId(), statement, valueFormat, false)) {
        return Optional.empty();
    }
    final SchemaAndId schemaAndId = getSchema(props.getKafkaTopic(), props.getValueSchemaId(), valueFormat, createSourceCommand.getFormats().getValueFeatures(), statement.getStatementText(), false);
    final List<Column> tableColumns = createSourceCommand.getSchema().value();
    checkColumnsCompatibility(props.getValueSchemaId(), tableColumns, schemaAndId.columns, false);
    return Optional.of(schemaAndId);
}
Also used : SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn) Column(io.confluent.ksql.schema.ksql.Column) CreateSourceAsProperties(io.confluent.ksql.parser.properties.with.CreateSourceAsProperties) CreateAsSelect(io.confluent.ksql.parser.tree.CreateAsSelect) FormatInfo(io.confluent.ksql.serde.FormatInfo)

Example 15 with FormatInfo

use of io.confluent.ksql.serde.FormatInfo in project ksql by confluentinc.

the class SchemaRegisterInjector method registerForCreateSource.

private void registerForCreateSource(final ConfiguredStatement<? extends CreateSource> cs) {
    // since this injector is chained after the TopicCreateInjector,
    // we can assume that the kafka topic is always present in the
    // statement properties
    final CreateSource statement = cs.getStatement();
    final LogicalSchema schema = statement.getElements().toLogicalSchema();
    final FormatInfo keyFormatInfo = SourcePropertiesUtil.getKeyFormat(statement.getProperties(), statement.getName());
    final Format keyFormat = tryGetFormat(keyFormatInfo, true, cs.getStatementText());
    final SerdeFeatures keyFeatures = SerdeFeaturesFactory.buildKeyFeatures(schema, keyFormat);
    final FormatInfo valueFormatInfo = SourcePropertiesUtil.getValueFormat(statement.getProperties());
    final Format valueFormat = tryGetFormat(valueFormatInfo, false, cs.getStatementText());
    final SerdeFeatures valFeatures = SerdeFeaturesFactory.buildValueFeatures(schema, valueFormat, statement.getProperties().getValueSerdeFeatures(), cs.getSessionConfig().getConfig(false));
    final SchemaAndId rawKeySchema = (SchemaAndId) cs.getSessionConfig().getOverrides().get(CommonCreateConfigs.KEY_SCHEMA_ID);
    final SchemaAndId rawValueSchema = (SchemaAndId) cs.getSessionConfig().getOverrides().get(CommonCreateConfigs.VALUE_SCHEMA_ID);
    registerSchemas(schema, Pair.of(rawKeySchema, rawValueSchema), statement.getProperties().getKafkaTopic(), keyFormatInfo, keyFeatures, valueFormatInfo, valFeatures, cs.getSessionConfig().getConfig(false), cs.getStatementText(), false);
}
Also used : Format(io.confluent.ksql.serde.Format) SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) CreateSource(io.confluent.ksql.parser.tree.CreateSource) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FormatInfo(io.confluent.ksql.serde.FormatInfo) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures)

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