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