Search in sources :

Example 26 with Column

use of io.confluent.ksql.schema.ksql.Column 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 27 with Column

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

the class SourceBuilderUtils method timestampExtractor.

static TimestampExtractor timestampExtractor(final KsqlConfig ksqlConfig, final LogicalSchema sourceSchema, final Optional<TimestampColumn> timestampColumn, final SourceStep<?> streamSource, final RuntimeBuildContext buildContext) {
    final TimestampExtractionPolicy timestampPolicy = TimestampExtractionPolicyFactory.create(ksqlConfig, sourceSchema, timestampColumn);
    final Optional<Column> tsColumn = timestampColumn.map(TimestampColumn::getColumn).map(c -> sourceSchema.findColumn(c).orElseThrow(IllegalStateException::new));
    final QueryContext queryContext = streamSource.getProperties().getQueryContext();
    return timestampPolicy.create(tsColumn, ksqlConfig.getBoolean(KsqlConfig.KSQL_TIMESTAMP_THROW_ON_INVALID), buildContext.getProcessingLogger(queryContext));
}
Also used : TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Column(io.confluent.ksql.schema.ksql.Column) TimestampExtractionPolicy(io.confluent.ksql.execution.streams.timestamp.TimestampExtractionPolicy) QueryContext(io.confluent.ksql.execution.context.QueryContext)

Example 28 with Column

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

the class StreamFlatMapBuilder method buildSchema.

public static LogicalSchema buildSchema(final LogicalSchema inputSchema, final List<FunctionCall> tableFunctions, final FunctionRegistry functionRegistry) {
    final LogicalSchema.Builder schemaBuilder = LogicalSchema.builder();
    final List<Column> cols = inputSchema.value();
    // We copy all the original columns to the output schema
    schemaBuilder.keyColumns(inputSchema.key());
    for (final Column col : cols) {
        schemaBuilder.valueColumn(col);
    }
    final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(inputSchema, functionRegistry);
    // And add new columns representing the exploded values at the end
    for (int i = 0; i < tableFunctions.size(); i++) {
        final FunctionCall functionCall = tableFunctions.get(i);
        final ColumnName colName = ColumnNames.synthesisedSchemaColumn(i);
        final SqlType fieldType = expressionTypeManager.getExpressionSqlType(functionCall);
        schemaBuilder.valueColumn(colName, fieldType);
    }
    return schemaBuilder.build();
}
Also used : ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) ColumnName(io.confluent.ksql.name.ColumnName) Column(io.confluent.ksql.schema.ksql.Column) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall)

Example 29 with Column

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

the class JoinParamsFactory method throwOnKeyMismatch.

private static SqlType throwOnKeyMismatch(final LogicalSchema leftSchema, final LogicalSchema rightSchema) {
    final List<Column> leftKeyCols = leftSchema.key();
    final List<Column> rightKeyCols = rightSchema.key();
    if (leftKeyCols.size() != 1 || rightKeyCols.size() != 1) {
        throw new UnsupportedOperationException("Multi-key joins not supported");
    }
    final Column leftKey = leftKeyCols.get(0);
    final Column rightKey = rightKeyCols.get(0);
    if (!leftKey.type().equals(rightKey.type())) {
        throw new KsqlException("Invalid join. Key types differ: " + leftKey.type() + " vs " + rightKey.type());
    }
    return leftKey.type();
}
Also used : Column(io.confluent.ksql.schema.ksql.Column) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

Column (io.confluent.ksql.schema.ksql.Column)29 ColumnName (io.confluent.ksql.name.ColumnName)14 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)14 Collectors (java.util.stream.Collectors)9 Expression (io.confluent.ksql.execution.expression.tree.Expression)8 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)8 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)8 KsqlException (io.confluent.ksql.util.KsqlException)8 List (java.util.List)8 Optional (java.util.Optional)8 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)7 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)7 ExpressionTypeManager (io.confluent.ksql.execution.util.ExpressionTypeManager)7 Set (java.util.Set)7 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)6 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)5 DataSource (io.confluent.ksql.metastore.model.DataSource)5 SourceName (io.confluent.ksql.name.SourceName)5 Builder (io.confluent.ksql.schema.ksql.LogicalSchema.Builder)5 FormatInfo (io.confluent.ksql.serde.FormatInfo)5