use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class TableGroupByBuilderBase method build.
public <K> KGroupedTableHolder build(final KTableHolder<K> table, final QueryContext queryContext, final Formats formats, final List<Expression> groupByExpressions) {
final LogicalSchema sourceSchema = table.getSchema();
final List<CompiledExpression> groupBy = CodeGenRunner.compileExpressions(groupByExpressions.stream(), "Group By", sourceSchema, buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
final ProcessingLogger logger = buildContext.getProcessingLogger(queryContext);
final GroupByParams params = paramsFactory.build(sourceSchema, groupBy, logger);
final PhysicalSchema physicalSchema = PhysicalSchema.from(params.getSchema(), formats.getKeyFeatures(), formats.getValueFeatures());
final Serde<GenericKey> keySerde = buildContext.buildKeySerde(formats.getKeyFormat(), physicalSchema, queryContext);
final Serde<GenericRow> valSerde = buildContext.buildValueSerde(formats.getValueFormat(), physicalSchema, queryContext);
final Grouped<GenericKey, GenericRow> grouped = groupedFactory.create(StreamsUtil.buildOpName(queryContext), keySerde, valSerde);
final KGroupedTable<GenericKey, GenericRow> groupedTable = table.getTable().filter((k, v) -> v != null).groupBy(new TableKeyValueMapper<>(params.getMapper()), grouped);
return KGroupedTableHolder.of(groupedTable, params.getSchema());
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class WindowStoreCacheBypass method fetchRangeUncached.
/*
This method is used for range queries. It is invoked by the fetchRange method
*/
private static KeyValueIterator<Windowed<GenericKey>, ValueAndTimestamp<GenericRow>> fetchRangeUncached(final ReadOnlyWindowStore<GenericKey, ValueAndTimestamp<GenericRow>> windowStore, final GenericKey keyFrom, final GenericKey keyTo, final Instant lower, final Instant upper) {
if (!(windowStore instanceof MeteredWindowStore)) {
throw new IllegalStateException("Expecting a MeteredWindowStore");
}
final StateSerdes<GenericKey, ValueAndTimestamp<GenericRow>> serdes = getSerdes(windowStore);
final WindowStore<Bytes, byte[]> wrapped = getInnermostStore(windowStore);
final Bytes rawKeyFrom = Bytes.wrap(serdes.rawKey(keyFrom));
final Bytes rawKeyTo = Bytes.wrap(serdes.rawKey(keyTo));
final KeyValueIterator<Windowed<Bytes>, byte[]> fetch = wrapped.fetch(rawKeyFrom, rawKeyTo, lower, upper);
return new DeserializingKeyValueIterator(fetch, serdes);
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class GroupByParamsFactoryTest method shouldGenerateExpressionGroupByKeyForMultipleExpressions.
@Test
public void shouldGenerateExpressionGroupByKeyForMultipleExpressions() {
// Given:
when(groupBy0.evaluate(any(), any(), any(), any())).thenReturn(99);
when(groupBy1.evaluate(any(), any(), any(), any())).thenReturn(-100L);
// When:
final GenericKey result = multiParams.getMapper().apply(value);
// Then:
assertThat(result, is(genericKey(99, -100L)));
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class GroupByParamsFactoryTest method shouldGenerateGroupByKeyForSingleExpression.
@Test
public void shouldGenerateGroupByKeyForSingleExpression() {
// 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 GroupByParamsFactoryTest method shouldReturnNullIfAnyMultiExpressionResolvesToNull.
@Test
public void shouldReturnNullIfAnyMultiExpressionResolvesToNull() {
// Given:
when(groupBy0.evaluate(any(), any(), any(), any())).thenReturn(null);
// When:
final GenericKey result = multiParams.getMapper().apply(value);
// Then:
assertThat(result, is(nullValue()));
}
Aggregations