use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class TableAggregateBuilderTest method shouldBuildMaterializationCorrectlyForAggregate.
@Test
public void shouldBuildMaterializationCorrectlyForAggregate() {
// When:
final KTableHolder<?> result = aggregate.build(planBuilder, planInfo);
// Then:
assertThat(result.getMaterializationBuilder().isPresent(), is(true));
final MaterializationInfo info = result.getMaterializationBuilder().get().build();
assertThat(info.stateStoreName(), equalTo("agg-regate-Materialize"));
assertThat(info.getSchema(), equalTo(AGGREGATE_SCHEMA));
assertThat(info.getStateStoreSchema(), equalTo(AGGREGATE_SCHEMA));
assertThat(info.getTransforms(), hasSize(1));
final MapperInfo aggMapInfo = (MapperInfo) info.getTransforms().get(0);
final KsqlTransformer<Object, GenericRow> mapper = aggMapInfo.getMapper(name -> null);
// Given:
final GenericKey key = mock(GenericKey.class);
final GenericRow value = mock(GenericRow.class);
// When:
mapper.transform(key, value, ctx);
// Then:
verify(resultMapper).transform(key, value, ctx);
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class ForeignKeyTableTableJoinBuilderTest method shouldDoInnerJoinOnKey.
// this is actually a PK-PK join and the logical planner would not compile a FK-join plan
// for this case atm
// however, from a physical plan POV this should still work, so we would like to keep this test
//
// it might be possible to actually change the logical planner to compile a PK-PK join as
// FK-join if input tables are not co-partitioned (instead of throwing an error an rejecting
// the query), ie, if key-format or partition-count do not match -- it's an open question
// if it would be a good idea to do this though
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldDoInnerJoinOnKey() {
// Given:
givenInnerJoin(left, L_KEY);
// When:
final KTableHolder<Struct> result = join.build(planBuilder, planInfo);
// Then:
final ArgumentCaptor<KsqlKeyExtractor> ksqlKeyExtractor = ArgumentCaptor.forClass(KsqlKeyExtractor.class);
verify(leftKTable).join(same(rightKTable), ksqlKeyExtractor.capture(), eq(new KsqlValueJoiner(LEFT_SCHEMA.value().size(), RIGHT_SCHEMA.value().size(), 0)), any(Materialized.class));
verifyNoMoreInteractions(leftKTable, rightKTable, resultKTable);
final GenericKey extractedKey = GenericKey.genericKey(LEFT_KEY);
assertThat(ksqlKeyExtractor.getValue().apply(LEFT_ROW), is(extractedKey));
assertThat(result.getTable(), is(resultKTable));
assertThat(result.getExecutionKeyFactory(), is(executionKeyFactory));
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class GroupByParamsV1FactoryTest method shouldGenerateSingleExpressionGroupByKey.
@Test
public void shouldGenerateSingleExpressionGroupByKey() {
// Given:
when(groupBy0.evaluate(any(), any(), any(), any())).thenReturn(10);
// When:
final GenericKey result = singleParams.getMapper().apply(value);
// Then:
assertThat(result, is(genericKey(10)));
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class GenericRecordFactory method build.
public KsqlGenericRecord build(final List<ColumnName> columnNames, final List<Expression> expressions, final LogicalSchema schema, final DataSourceType dataSourceType) {
final List<ColumnName> columns = columnNames.isEmpty() ? implicitColumns(schema) : columnNames;
if (columns.size() != expressions.size()) {
throw new KsqlException("Expected a value for each column." + " Expected Columns: " + columnNames + ". Got " + expressions);
}
final LogicalSchema schemaWithPseudoColumns = withPseudoColumns(schema, config);
for (ColumnName col : columns) {
if (!schemaWithPseudoColumns.findColumn(col).isPresent()) {
throw new KsqlException("Column name " + col + " does not exist.");
}
if (SystemColumns.isDisallowedForInsertValues(col, config)) {
throw new KsqlException("Inserting into column " + col + " is not allowed.");
}
}
final Map<ColumnName, Object> values = resolveValues(columns, expressions, schemaWithPseudoColumns, functionRegistry, config);
if (dataSourceType == DataSourceType.KTABLE) {
final String noValue = schemaWithPseudoColumns.key().stream().map(Column::name).filter(colName -> !values.containsKey(colName)).map(ColumnName::text).collect(Collectors.joining(", "));
if (!noValue.isEmpty()) {
throw new KsqlException("Value for primary key column(s) " + noValue + " is required for tables");
}
}
final long ts = (long) values.getOrDefault(SystemColumns.ROWTIME_NAME, clock.getAsLong());
final GenericKey key = buildKey(schema, values);
final GenericRow value = buildValue(schema, values);
return KsqlGenericRecord.of(key, value, ts);
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class TestDriverPipelineTest method shouldHandleTwoTopologiesWithSameInputDifferentOutput.
@Test
public void shouldHandleTwoTopologiesWithSameInputDifferentOutput() {
// Given (two topologies that pipe a to b and a to c):
final TopologyTestDriver driver1 = mock(TopologyTestDriver.class);
final TopologyTestDriver driver2 = mock(TopologyTestDriver.class);
final TestInputTopic<GenericKey, GenericRow> inA1 = givenInput(driver1, "a");
final TestInputTopic<GenericKey, GenericRow> inA2 = givenInput(driver2, "a");
givenOutput(driver1, "b");
givenOutput(driver2, "c");
givenPipe(inA1, "b");
givenPipe(inA2, "c");
pipeline.addDriver(driver1, ImmutableList.of(inf("a")), inf("b"));
pipeline.addDriver(driver2, ImmutableList.of(inf("a")), inf("c"));
// When:
pipeline.pipeInput("a", KEY, ROW1, 1);
// Then:
assertThat(pipeline.getAllRecordsForTopic("b"), is(ImmutableList.of(new TestRecord<>(KEY, ROW1, Instant.ofEpochMilli(1)))));
assertThat(pipeline.getAllRecordsForTopic("c"), is(ImmutableList.of(new TestRecord<>(KEY, ROW1, Instant.ofEpochMilli(1)))));
}
Aggregations