use of com.hazelcast.jet.core.function.KeyedWindowResultFunction in project hazelcast by hazelcast.
the class CreateDagVisitor method onSlidingWindowAggregate.
public Vertex onSlidingWindowAggregate(SlidingWindowAggregatePhysicalRel rel) {
FunctionEx<JetSqlRow, ?> groupKeyFn = rel.groupKeyFn();
AggregateOperation<?, JetSqlRow> aggregateOperation = rel.aggrOp();
Expression<?> timestampExpression = rel.timestampExpression();
ToLongFunctionEx<JetSqlRow> timestampFn = row -> WindowUtils.extractMillis(timestampExpression.eval(row.getRow(), MOCK_EEC));
SlidingWindowPolicy windowPolicy = rel.windowPolicyProvider().apply(MOCK_EEC);
KeyedWindowResultFunction<? super Object, ? super JetSqlRow, ?> resultMapping = rel.outputValueMapping();
if (rel.numStages() == 1) {
Vertex vertex = dag.newUniqueVertex("Sliding-Window-AggregateByKey", Processors.aggregateToSlidingWindowP(singletonList(groupKeyFn), singletonList(timestampFn), TimestampKind.EVENT, windowPolicy, 0, aggregateOperation, resultMapping));
connectInput(rel.getInput(), vertex, edge -> edge.distributeTo(localMemberAddress).allToOne(""));
return vertex;
} else {
assert rel.numStages() == 2;
Vertex vertex1 = dag.newUniqueVertex("Sliding-Window-AccumulateByKey", Processors.accumulateByFrameP(singletonList(groupKeyFn), singletonList(timestampFn), TimestampKind.EVENT, windowPolicy, aggregateOperation));
Vertex vertex2 = dag.newUniqueVertex("Sliding-Window-CombineByKey", Processors.combineToSlidingWindowP(windowPolicy, aggregateOperation, resultMapping));
connectInput(rel.getInput(), vertex1, edge -> edge.partitioned(groupKeyFn));
dag.edge(between(vertex1, vertex2).distributed().partitioned(entryKey()));
return vertex2;
}
}
use of com.hazelcast.jet.core.function.KeyedWindowResultFunction in project hazelcast by hazelcast.
the class SlidingWindowAggregatePhysicalRel method outputValueMapping.
@SuppressWarnings("checkstyle:MagicNumber")
public KeyedWindowResultFunction<? super Object, ? super JetSqlRow, ?> outputValueMapping() {
int[] windowBoundsIndexMask = new int[getRowType().getFieldCount()];
QueryDataType descriptorType = HazelcastTypeUtils.toHazelcastType(timestampExpression.getType());
for (Integer index : windowStartIndexes) {
windowBoundsIndexMask[index] = -1;
}
for (Integer index : windowEndIndexes) {
windowBoundsIndexMask[index] = -2;
}
for (int i = 0, j = 0; i < windowBoundsIndexMask.length; i++) {
if (windowBoundsIndexMask[i] >= 0) {
windowBoundsIndexMask[i] = j++;
}
}
return (start, end, ignoredKey, result, isEarly) -> insertWindowBound(result, start, end, descriptorType, windowBoundsIndexMask);
}
Aggregations