Search in sources :

Example 26 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class ColumnNamesTest method shouldStartGeneratingFromZeroIfSourceSchemasHaveNoGeneratedAliases.

@Test
public void shouldStartGeneratingFromZeroIfSourceSchemasHaveNoGeneratedAliases() {
    // Given:
    final ColumnAliasGenerator generator = ColumnNames.columnAliasGenerator(Stream.of(LogicalSchema.builder().build()));
    // When:
    final ColumnName result = generator.nextKsqlColAlias();
    // Then:
    assertThat(result, is(ColumnName.of("KSQL_COL_0")));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) Test(org.junit.Test)

Example 27 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class TombstoneFactory method buildKeyIdx.

private static ImmutableMap<Integer, Integer> buildKeyIdx(final LogicalSchema schema, final ResultType resultType) {
    final List<ColumnName> keyColumns = keyColumnNames(schema, resultType);
    final List<Column> projection = schema.value();
    final Map<ColumnName, Integer> columnIndexes = new HashMap<>(projection.size());
    for (int columnIndex = 0; columnIndex < projection.size(); columnIndex++) {
        final Column column = projection.get(columnIndex);
        columnIndexes.put(column.name(), columnIndex);
    }
    final Builder<Integer, Integer> builder = ImmutableMap.builder();
    for (int keyIndex = 0; keyIndex < keyColumns.size(); keyIndex++) {
        final Integer columnIndex = columnIndexes.get(keyColumns.get(keyIndex));
        if (columnIndex == null) {
            // Not in projection
            continue;
        }
        builder.put(columnIndex, keyIndex);
    }
    return builder.build();
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn) Column(io.confluent.ksql.schema.ksql.Column) HashMap(java.util.HashMap)

Example 28 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class ConnectFormatSchemaTranslator method toColumn.

private static SimpleColumn toColumn(final Field field) {
    final ColumnName name = ColumnName.of(field.name());
    final SqlType type = SchemaConverters.connectToSqlConverter().toSqlType(field.schema());
    return new ConnectColumn(name, type);
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) SqlType(io.confluent.ksql.schema.ksql.types.SqlType)

Example 29 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class TableAggregateBuilder method build.

public static KTableHolder<GenericKey> build(final KGroupedTableHolder groupedTable, final TableAggregate aggregate, final RuntimeBuildContext buildContext, final MaterializedFactory materializedFactory, final AggregateParamsFactory aggregateParamsFactory) {
    final LogicalSchema sourceSchema = groupedTable.getSchema();
    final List<ColumnName> nonFuncColumns = aggregate.getNonAggregateColumns();
    final AggregateParams aggregateParams = aggregateParamsFactory.createUndoable(sourceSchema, nonFuncColumns, buildContext.getFunctionRegistry(), aggregate.getAggregationFunctions(), buildContext.getKsqlConfig());
    final LogicalSchema aggregateSchema = aggregateParams.getAggregateSchema();
    final LogicalSchema resultSchema = aggregateParams.getSchema();
    final Materialized<GenericKey, GenericRow, KeyValueStore<Bytes, byte[]>> materialized = MaterializationUtil.buildMaterialized(aggregate, aggregateSchema, aggregate.getInternalFormats(), buildContext, materializedFactory, ExecutionKeyFactory.unwindowed(buildContext));
    final KTable<GenericKey, GenericRow> aggregated = groupedTable.getGroupedTable().aggregate(aggregateParams.getInitializer(), aggregateParams.getAggregator(), aggregateParams.getUndoAggregator().get(), materialized).transformValues(() -> new KsTransformer<>(aggregateParams.<GenericKey>getAggregator().getResultMapper()), Named.as(StreamsUtil.buildOpName(AggregateBuilderUtils.outputContext(aggregate))));
    final MaterializationInfo.Builder materializationBuilder = AggregateBuilderUtils.materializationInfoBuilder(aggregateParams.getAggregator(), aggregate, aggregateSchema, resultSchema);
    return KTableHolder.materialized(aggregated, resultSchema, ExecutionKeyFactory.unwindowed(buildContext), materializationBuilder);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) ColumnName(io.confluent.ksql.name.ColumnName) MaterializationInfo(io.confluent.ksql.execution.materialization.MaterializationInfo) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) GenericKey(io.confluent.ksql.GenericKey)

Example 30 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class StreamAggregateBuilder method build.

static KTableHolder<GenericKey> build(final KGroupedStreamHolder groupedStream, final StreamAggregate aggregate, final RuntimeBuildContext buildContext, final MaterializedFactory materializedFactory, final AggregateParamsFactory aggregateParamsFactory) {
    final LogicalSchema sourceSchema = groupedStream.getSchema();
    final List<ColumnName> nonFuncColumns = aggregate.getNonAggregateColumns();
    final AggregateParams aggregateParams = aggregateParamsFactory.create(sourceSchema, nonFuncColumns, buildContext.getFunctionRegistry(), aggregate.getAggregationFunctions(), false, buildContext.getKsqlConfig());
    final LogicalSchema aggregateSchema = aggregateParams.getAggregateSchema();
    final LogicalSchema resultSchema = aggregateParams.getSchema();
    final Materialized<GenericKey, GenericRow, KeyValueStore<Bytes, byte[]>> materialized = MaterializationUtil.buildMaterialized(aggregate, aggregateSchema, aggregate.getInternalFormats(), buildContext, materializedFactory, ExecutionKeyFactory.unwindowed(buildContext));
    final KudafAggregator<GenericKey> aggregator = aggregateParams.getAggregator();
    final KTable<GenericKey, GenericRow> aggregated = groupedStream.getGroupedStream().aggregate(aggregateParams.getInitializer(), aggregateParams.getAggregator(), materialized);
    final MaterializationInfo.Builder materializationBuilder = AggregateBuilderUtils.materializationInfoBuilder(aggregateParams.getAggregator(), aggregate, aggregateSchema, resultSchema);
    final KTable<GenericKey, GenericRow> result = aggregated.transformValues(() -> new KsTransformer<>(aggregator.getResultMapper()), Named.as(StreamsUtil.buildOpName(AggregateBuilderUtils.outputContext(aggregate))));
    return KTableHolder.materialized(result, resultSchema, ExecutionKeyFactory.unwindowed(buildContext), materializationBuilder);
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) GenericRow(io.confluent.ksql.GenericRow) ColumnName(io.confluent.ksql.name.ColumnName) MaterializationInfo(io.confluent.ksql.execution.materialization.MaterializationInfo) GenericKey(io.confluent.ksql.GenericKey)

Aggregations

ColumnName (io.confluent.ksql.name.ColumnName)63 Test (org.junit.Test)32 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)31 Expression (io.confluent.ksql.execution.expression.tree.Expression)23 KsqlException (io.confluent.ksql.util.KsqlException)13 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)11 Column (io.confluent.ksql.schema.ksql.Column)11 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)10 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)9 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)8 Optional (java.util.Optional)8 Collectors (java.util.stream.Collectors)8 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)7 List (java.util.List)7 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)6 Builder (io.confluent.ksql.schema.ksql.LogicalSchema.Builder)6 Set (java.util.Set)6 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)5 QualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp)5 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)5