use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class TableAggregateBuilder method build.
public static KTableHolder<GenericKey> build(final KGroupedTableHolder groupedTable, final TableAggregate aggregate, final RuntimeBuildContext buildContext, final MaterializedFactory materializedFactory, final AggregateParamsFactory aggregateParamsFactory) {
final LogicalSchema sourceSchema = groupedTable.getSchema();
final List<ColumnName> nonFuncColumns = aggregate.getNonAggregateColumns();
final AggregateParams aggregateParams = aggregateParamsFactory.createUndoable(sourceSchema, nonFuncColumns, buildContext.getFunctionRegistry(), aggregate.getAggregationFunctions(), buildContext.getKsqlConfig());
final LogicalSchema aggregateSchema = aggregateParams.getAggregateSchema();
final LogicalSchema resultSchema = aggregateParams.getSchema();
final Materialized<GenericKey, GenericRow, KeyValueStore<Bytes, byte[]>> materialized = MaterializationUtil.buildMaterialized(aggregate, aggregateSchema, aggregate.getInternalFormats(), buildContext, materializedFactory, ExecutionKeyFactory.unwindowed(buildContext));
final KTable<GenericKey, GenericRow> aggregated = groupedTable.getGroupedTable().aggregate(aggregateParams.getInitializer(), aggregateParams.getAggregator(), aggregateParams.getUndoAggregator().get(), materialized).transformValues(() -> new KsTransformer<>(aggregateParams.<GenericKey>getAggregator().getResultMapper()), Named.as(StreamsUtil.buildOpName(AggregateBuilderUtils.outputContext(aggregate))));
final MaterializationInfo.Builder materializationBuilder = AggregateBuilderUtils.materializationInfoBuilder(aggregateParams.getAggregator(), aggregate, aggregateSchema, resultSchema);
return KTableHolder.materialized(aggregated, resultSchema, ExecutionKeyFactory.unwindowed(buildContext), materializationBuilder);
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class StreamAggregateBuilder method build.
static KTableHolder<GenericKey> build(final KGroupedStreamHolder groupedStream, final StreamAggregate aggregate, final RuntimeBuildContext buildContext, final MaterializedFactory materializedFactory, final AggregateParamsFactory aggregateParamsFactory) {
final LogicalSchema sourceSchema = groupedStream.getSchema();
final List<ColumnName> nonFuncColumns = aggregate.getNonAggregateColumns();
final AggregateParams aggregateParams = aggregateParamsFactory.create(sourceSchema, nonFuncColumns, buildContext.getFunctionRegistry(), aggregate.getAggregationFunctions(), false, buildContext.getKsqlConfig());
final LogicalSchema aggregateSchema = aggregateParams.getAggregateSchema();
final LogicalSchema resultSchema = aggregateParams.getSchema();
final Materialized<GenericKey, GenericRow, KeyValueStore<Bytes, byte[]>> materialized = MaterializationUtil.buildMaterialized(aggregate, aggregateSchema, aggregate.getInternalFormats(), buildContext, materializedFactory, ExecutionKeyFactory.unwindowed(buildContext));
final KudafAggregator<GenericKey> aggregator = aggregateParams.getAggregator();
final KTable<GenericKey, GenericRow> aggregated = groupedStream.getGroupedStream().aggregate(aggregateParams.getInitializer(), aggregateParams.getAggregator(), materialized);
final MaterializationInfo.Builder materializationBuilder = AggregateBuilderUtils.materializationInfoBuilder(aggregateParams.getAggregator(), aggregate, aggregateSchema, resultSchema);
final KTable<GenericKey, GenericRow> result = aggregated.transformValues(() -> new KsTransformer<>(aggregator.getResultMapper()), Named.as(StreamsUtil.buildOpName(AggregateBuilderUtils.outputContext(aggregate))));
return KTableHolder.materialized(result, resultSchema, ExecutionKeyFactory.unwindowed(buildContext), materializationBuilder);
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class CliTest method testSelectProject.
@Test
public void testSelectProject() {
final Map<GenericKey, GenericRow> expectedResults = ImmutableMap.<GenericKey, GenericRow>builder().put(genericKey("ORDER_1"), genericRow("ITEM_1", 10.0, ImmutableList.of(100.0, 110.99, 90.0))).put(genericKey("ORDER_2"), genericRow("ITEM_2", 20.0, ImmutableList.of(10.0, 10.99, 9.0))).put(genericKey("ORDER_3"), genericRow("ITEM_3", 30.0, ImmutableList.of(10.0, 10.99, 91.0))).put(genericKey("ORDER_4"), genericRow("ITEM_4", 40.0, ImmutableList.of(10.0, 140.99, 94.0))).put(genericKey("ORDER_5"), genericRow("ITEM_5", 50.0, ImmutableList.of(160.0, 160.99, 98.0))).put(genericKey("ORDER_6"), genericRow("ITEM_8", 80.0, ImmutableList.of(1100.0, 1110.99, 970.0))).build();
final PhysicalSchema resultSchema = PhysicalSchema.from(LogicalSchema.builder().keyColumn(ColumnName.of("ORDERID"), SqlTypes.STRING).valueColumn(ColumnName.of("ITEMID"), SqlTypes.STRING).valueColumn(ColumnName.of("ORDERUNITS"), SqlTypes.DOUBLE).valueColumn(ColumnName.of("PRICEARRAY"), SqlTypes.array(SqlTypes.DOUBLE)).build(), SerdeFeatures.of(), SerdeFeatures.of());
testCreateStreamAsSelect("SELECT ORDERID, ITEMID, ORDERUNITS, PRICEARRAY " + "FROM " + ORDER_DATA_PROVIDER.sourceName() + ";", resultSchema, expectedResults);
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class CliTest method testSelectUDFs.
@Test
public void testSelectUDFs() {
final String queryString = String.format("SELECT " + "ORDERID, " + "ITEMID, " + "ORDERUNITS*10 AS Col1, " + "PRICEARRAY[1]+10 AS Col2, " + "KEYVALUEMAP['key1']*KEYVALUEMAP['key2']+10 AS Col3, " + "PRICEARRAY[2]>1000 AS Col4 " + "FROM %s " + "WHERE ORDERUNITS > 20 AND ITEMID LIKE '%%_8';", ORDER_DATA_PROVIDER.sourceName());
final PhysicalSchema resultSchema = PhysicalSchema.from(LogicalSchema.builder().keyColumn(ColumnName.of("ORDERID"), SqlTypes.STRING).valueColumn(ColumnName.of("ITEMID"), SqlTypes.STRING).valueColumn(ColumnName.of("COL1"), SqlTypes.DOUBLE).valueColumn(ColumnName.of("COL2"), SqlTypes.DOUBLE).valueColumn(ColumnName.of("COL3"), SqlTypes.DOUBLE).valueColumn(ColumnName.of("COL4"), SqlTypes.BOOLEAN).build(), SerdeFeatures.of(), SerdeFeatures.of());
final Map<GenericKey, GenericRow> expectedResults = ImmutableMap.of(genericKey("ORDER_6"), genericRow("ITEM_8", 800.0, 1110.0, 12.0, true));
testCreateStreamAsSelect(queryString, resultSchema, expectedResults);
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class DecimalMaxKudafTest method shouldFindCorrectMaxForMerge.
@Test
public void shouldFindCorrectMaxForMerge() {
final DecimalMaxKudaf doubleMaxKudaf = getDecimalMaxKudaf(3);
final Merger<GenericKey, BigDecimal> merger = doubleMaxKudaf.getMerger();
final BigDecimal mergeResult1 = merger.apply(null, new BigDecimal(10.0), new BigDecimal(12.0));
assertThat(mergeResult1, equalTo(new BigDecimal(12.0, new MathContext(3))));
final BigDecimal mergeResult2 = merger.apply(null, new BigDecimal(10.0), new BigDecimal(-12.0));
assertThat(mergeResult2, equalTo(new BigDecimal(10.0, new MathContext(3))));
final BigDecimal mergeResult3 = merger.apply(null, new BigDecimal(-10.0), new BigDecimal(0.0));
assertThat(mergeResult3, equalTo(new BigDecimal(0.0, new MathContext(3))));
}
Aggregations