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")));
}
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();
}
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);
}
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);
}
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);
}
Aggregations