Search in sources :

Example 46 with LogicalSchema

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

the class Selection method buildSchema.

private static LogicalSchema buildSchema(final LogicalSchema sourceSchema, final SelectValueMapper<?> mapper, final List<ColumnName> keyColumnNames) {
    final List<ColumnName> keyNames = keyColumnNames.isEmpty() ? getKeyColumnNames(sourceSchema) : keyColumnNames;
    final List<Column> keyCols = sourceSchema.key();
    if (keyNames.size() != keyCols.size()) {
        throw new IllegalArgumentException("key name count mismatch. " + "names: " + keyNames + ", " + "keys: " + keyCols);
    }
    final LogicalSchema.Builder schemaBuilder = LogicalSchema.builder();
    for (int i = 0; i != keyCols.size(); ++i) {
        schemaBuilder.keyColumn(keyNames.get(i), keyCols.get(i).type());
    }
    for (final SelectInfo select : mapper.getSelects()) {
        schemaBuilder.valueColumn(select.getFieldName(), select.getEvaluator().getExpressionType());
    }
    return schemaBuilder.build();
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) SelectInfo(io.confluent.ksql.execution.transform.select.SelectValueMapper.SelectInfo) Column(io.confluent.ksql.schema.ksql.Column) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Example 47 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForStreamGroupByKey.

@Test
public void shouldResolveSchemaForStreamGroupByKey() {
    // Given:
    final StreamGroupByKey step = new StreamGroupByKey(PROPERTIES, streamSource, formats);
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(SCHEMA));
}
Also used : StreamGroupByKey(io.confluent.ksql.execution.plan.StreamGroupByKey) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 48 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForStreamFlatMap.

@Test
public void shouldResolveSchemaForStreamFlatMap() {
    // Given:
    givenTableFunction("EXPLODE", SqlTypes.DOUBLE);
    final StreamFlatMap<?> step = new StreamFlatMap<>(PROPERTIES, streamSource, ImmutableList.of(functionCall("EXPLODE", "BANANA")));
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(LogicalSchema.builder().keyColumn(ColumnName.of("K0"), SqlTypes.INTEGER).valueColumn(ColumnName.of("ORANGE"), SqlTypes.INTEGER).valueColumn(ColumnName.of("APPLE"), SqlTypes.BIGINT).valueColumn(ColumnName.of("BANANA"), SqlTypes.STRING).valueColumn(ColumnNames.synthesisedSchemaColumn(0), SqlTypes.DOUBLE).build()));
}
Also used : StreamFlatMap(io.confluent.ksql.execution.plan.StreamFlatMap) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 49 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForTableAggregate.

@Test
public void shouldResolveSchemaForTableAggregate() {
    // Given:
    givenAggregateFunction("SUM", SqlTypes.BIGINT);
    final TableAggregate step = new TableAggregate(PROPERTIES, groupedTableSource, formats, ImmutableList.of(ColumnName.of("ORANGE")), ImmutableList.of(functionCall("SUM", "APPLE")));
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(LogicalSchema.builder().keyColumn(ColumnName.of("K0"), SqlTypes.INTEGER).valueColumn(ColumnName.of("ORANGE"), SqlTypes.INTEGER).valueColumn(ColumnNames.aggregateColumn(0), SqlTypes.BIGINT).build()));
}
Also used : TableAggregate(io.confluent.ksql.execution.plan.TableAggregate) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 50 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForTableSource.

@Test
public void shouldResolveSchemaForTableSource() {
    // Given:
    final TableSource step = new TableSource(PROPERTIES, "foo", formats, Optional.empty(), SCHEMA, SystemColumns.CURRENT_PSEUDOCOLUMN_VERSION_NUMBER, formats);
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(SCHEMA.withPseudoAndKeyColsInValue(false)));
}
Also used : TableSource(io.confluent.ksql.execution.plan.TableSource) WindowedTableSource(io.confluent.ksql.execution.plan.WindowedTableSource) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Aggregations

LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)223 Test (org.junit.Test)152 Expression (io.confluent.ksql.execution.expression.tree.Expression)44 ColumnName (io.confluent.ksql.name.ColumnName)31 GenericRow (io.confluent.ksql.GenericRow)30 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)29 KsqlException (io.confluent.ksql.util.KsqlException)27 GenericKey (io.confluent.ksql.GenericKey)20 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)19 List (java.util.List)16 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)14 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)14 Optional (java.util.Optional)14 Collectors (java.util.stream.Collectors)14 QueryContext (io.confluent.ksql.execution.context.QueryContext)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)12 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)12 Column (io.confluent.ksql.schema.ksql.Column)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)11