use of io.confluent.ksql.execution.plan.TableSelect in project ksql by confluentinc.
the class StepSchemaResolverTest method shouldResolveSchemaForTableSelectWithColumnNames.
@Test
public void shouldResolveSchemaForTableSelectWithColumnNames() {
// Given:
final TableSelect<?> step = new TableSelect<>(PROPERTIES, tableSource, ImmutableList.of(ColumnName.of("NEW_KEY")), ImmutableList.of(add("JUICE", "ORANGE", "APPLE"), ref("PLANTAIN", "BANANA"), ref("CITRUS", "ORANGE")), internalFormats);
// When:
final LogicalSchema result = resolver.resolve(step, SCHEMA);
// Then:
assertThat(result, is(LogicalSchema.builder().keyColumn(ColumnName.of("NEW_KEY"), SqlTypes.INTEGER).valueColumn(ColumnName.of("JUICE"), SqlTypes.BIGINT).valueColumn(ColumnName.of("PLANTAIN"), SqlTypes.STRING).valueColumn(ColumnName.of("CITRUS"), SqlTypes.INTEGER).build()));
}
use of io.confluent.ksql.execution.plan.TableSelect in project ksql by confluentinc.
the class StepSchemaResolverTest method shouldResolveSchemaForTableSelect.
@Test
public void shouldResolveSchemaForTableSelect() {
// Given:
final TableSelect<?> step = new TableSelect<>(PROPERTIES, tableSource, ImmutableList.of(), ImmutableList.of(add("JUICE", "ORANGE", "APPLE"), ref("PLANTAIN", "BANANA"), ref("CITRUS", "ORANGE")), internalFormats);
// When:
final LogicalSchema result = resolver.resolve(step, SCHEMA);
// Then:
assertThat(result, is(LogicalSchema.builder().keyColumn(ColumnName.of("K0"), SqlTypes.INTEGER).valueColumn(ColumnName.of("JUICE"), SqlTypes.BIGINT).valueColumn(ColumnName.of("PLANTAIN"), SqlTypes.STRING).valueColumn(ColumnName.of("CITRUS"), SqlTypes.INTEGER).build()));
}
use of io.confluent.ksql.execution.plan.TableSelect in project ksql by confluentinc.
the class TableSelectBuilder method build.
@SuppressWarnings("unchecked")
public static <K> KTableHolder<K> build(final KTableHolder<K> table, final TableSelect<K> step, final RuntimeBuildContext buildContext, final Optional<Formats> formats, final MaterializedFactory materializedFactory) {
final LogicalSchema sourceSchema = table.getSchema();
final QueryContext queryContext = step.getProperties().getQueryContext();
final Selection<K> selection = Selection.of(sourceSchema, step.getKeyColumnNames(), step.getSelectExpressions(), buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
final SelectValueMapper<K> selectMapper = selection.getMapper();
final ProcessingLogger logger = buildContext.getProcessingLogger(queryContext);
final Named selectName = Named.as(StreamsUtil.buildOpName(queryContext));
final Optional<MaterializationInfo.Builder> matBuilder = table.getMaterializationBuilder();
final boolean forceMaterialize = !matBuilder.isPresent();
final Serde<K> keySerde;
final Serde<GenericRow> valSerde;
if (formats.isPresent()) {
final Formats materializationFormat = formats.get();
final PhysicalSchema physicalSchema = PhysicalSchema.from(selection.getSchema(), materializationFormat.getKeyFeatures(), materializationFormat.getValueFeatures());
keySerde = (Serde<K>) buildContext.buildKeySerde(materializationFormat.getKeyFormat(), physicalSchema, queryContext);
valSerde = buildContext.buildValueSerde(materializationFormat.getValueFormat(), physicalSchema, queryContext);
if (forceMaterialize) {
final Stacker stacker = Stacker.of(step.getProperties().getQueryContext());
final String stateStoreName = StreamsUtil.buildOpName(stacker.push(PROJECT_OP).getQueryContext());
final Materialized<K, GenericRow, KeyValueStore<Bytes, byte[]>> materialized = materializedFactory.create(keySerde, valSerde, stateStoreName);
final KTable<K, GenericRow> transFormedTable = table.getTable().transformValues(() -> new KsTransformer<>(selectMapper.getTransformer(logger)), materialized);
return KTableHolder.materialized(transFormedTable, selection.getSchema(), table.getExecutionKeyFactory(), MaterializationInfo.builder(stateStoreName, selection.getSchema()));
}
} else {
keySerde = null;
valSerde = null;
}
final KTable<K, GenericRow> transFormedTable = table.getTable().transformValues(() -> new KsTransformer<>(selectMapper.getTransformer(logger)), Materialized.with(keySerde, valSerde), selectName);
final Optional<MaterializationInfo.Builder> materialization = matBuilder.map(b -> b.map(pl -> (KsqlTransformer<Object, GenericRow>) selectMapper.getTransformer(pl), selection.getSchema(), queryContext));
return table.withTable(transFormedTable, selection.getSchema()).withMaterialization(materialization);
}
Aggregations