Search in sources :

Example 1 with ColumnAliasGenerator

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

the class GroupByParamsFactory method expressionSchema.

private static LogicalSchema expressionSchema(final LogicalSchema sourceSchema, final List<CompiledExpression> groupBys) {
    final ColumnAliasGenerator columnAliasGenerator = ColumnNames.columnAliasGenerator(Stream.of(sourceSchema));
    final LogicalSchema.Builder schemaBuilder = LogicalSchema.builder();
    for (final CompiledExpression groupBy : groupBys) {
        final Expression groupByExp = groupBy.getExpression();
        final ColumnName columnName = groupByExp instanceof ColumnReferenceExp ? ((ColumnReferenceExp) groupByExp).getColumnName() : columnAliasGenerator.uniqueAliasFor(groupByExp);
        schemaBuilder.keyColumn(columnName, groupBy.getExpressionType());
    }
    schemaBuilder.valueColumns(sourceSchema.value());
    return schemaBuilder.build();
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) Expression(io.confluent.ksql.execution.expression.tree.Expression) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) ColumnAliasGenerator(io.confluent.ksql.schema.ksql.ColumnAliasGenerator) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression)

Aggregations

CompiledExpression (io.confluent.ksql.execution.codegen.CompiledExpression)1 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 ColumnName (io.confluent.ksql.name.ColumnName)1 ColumnAliasGenerator (io.confluent.ksql.schema.ksql.ColumnAliasGenerator)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1