Search in sources :

Example 21 with Column

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

the class SchemaKStreamTest method buildJoinSchema.

@SuppressWarnings("rawtypes")
private LogicalSchema buildJoinSchema(final KsqlStream stream) {
    final LogicalSchema.Builder builder = LogicalSchema.builder();
    builder.keyColumns(stream.getSchema().key());
    for (final Column c : stream.getSchema().value()) {
        builder.valueColumn(ColumnNames.generatedJoinColumnAlias(stream.getName(), c.name()), c.type());
    }
    return builder.build();
}
Also used : Column(io.confluent.ksql.schema.ksql.Column) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Example 22 with Column

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

the class AssertExecutor method fromGenericRow.

private static TabularRow fromGenericRow(final boolean expected, final DataSource source, final KsqlGenericRecord row) {
    final GenericRow contents = new GenericRow();
    contents.append(expected ? "EXPECTED" : "ACTUAL");
    contents.appendAll(row.key.values());
    contents.append(row.ts);
    if (row.value == null) {
        for (final Column ignored : source.getSchema().value()) {
            contents.append("<TOMBSTONE>");
        }
    } else {
        contents.appendAll(row.value.values());
    }
    return TabularRow.createRow(80, contents.values(), false, 0);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Column(io.confluent.ksql.schema.ksql.Column)

Example 23 with Column

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

the class AssertExecutor method throwAssertionError.

private static void throwAssertionError(final String message, final DataSource dataSource, final KsqlGenericRecord expected, final List<KsqlGenericRecord> actual) {
    final List<Column> columns = ImmutableList.<Column>builder().add(Column.of(ColumnName.of("."), SqlTypes.STRING, Namespace.KEY, 0)).add(Column.of(SystemColumns.ROWTIME_NAME, SqlTypes.BIGINT, Namespace.KEY, 0)).addAll(dataSource.getSchema().columns()).build();
    final TabularRow headerRow = TabularRow.createHeader(80, columns, false, 0);
    final StringBuilder actualRows = new StringBuilder();
    actual.forEach(a -> actualRows.append(fromGenericRow(false, dataSource, a)).append('\n'));
    throw new AssertionError(String.format("%s%n%s%n%s%n%s", message, headerRow, fromGenericRow(true, dataSource, expected), actualRows.toString()));
}
Also used : TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Column(io.confluent.ksql.schema.ksql.Column) TabularRow(io.confluent.ksql.util.TabularRow)

Example 24 with Column

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

the class JoinNodeTest method prependAlias.

private static LogicalSchema prependAlias(final SourceName alias, final LogicalSchema schema) {
    final LogicalSchema.Builder builder = LogicalSchema.builder();
    builder.keyColumns(schema.key());
    for (final Column c : schema.value()) {
        builder.valueColumn(ColumnNames.generatedJoinColumnAlias(alias, c.name()), c.type());
    }
    return builder.build();
}
Also used : Column(io.confluent.ksql.schema.ksql.Column) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Example 25 with Column

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

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