use of io.confluent.ksql.execution.windows.HoppingWindowExpression in project ksql by confluentinc.
the class RewrittenAnalysis method getWindowExpression.
@Override
public Optional<WindowExpression> getWindowExpression() {
final Optional<WindowExpression> windowExpression = original.getWindowExpression();
final Optional<RefinementInfo> refinementInfo = original.getRefinementInfo();
/* Return the original window expression, unless there is no grace period provided during a
suppression, in which case we rewrite the window expression to have a default grace period
of zero.
*/
if (!(windowExpression.isPresent() && !windowExpression.get().getKsqlWindowExpression().getGracePeriod().isPresent() && refinementInfo.isPresent() && refinementInfo.get().getOutputRefinement() == OutputRefinement.FINAL)) {
return original.getWindowExpression();
}
final WindowExpression window = original.getWindowExpression().get();
final KsqlWindowExpression ksqlWindowNew;
final KsqlWindowExpression ksqlWindowOld = window.getKsqlWindowExpression();
final Optional<NodeLocation> location = ksqlWindowOld.getLocation();
final Optional<WindowTimeClause> retention = ksqlWindowOld.getRetention();
if (ksqlWindowOld instanceof HoppingWindowExpression) {
ksqlWindowNew = new HoppingWindowExpression(location, ((HoppingWindowExpression) ksqlWindowOld).getSize(), ((HoppingWindowExpression) ksqlWindowOld).getAdvanceBy(), retention, Optional.of(zeroGracePeriod));
} else if (ksqlWindowOld instanceof TumblingWindowExpression) {
ksqlWindowNew = new TumblingWindowExpression(location, ((TumblingWindowExpression) ksqlWindowOld).getSize(), retention, Optional.of(zeroGracePeriod));
} else if (ksqlWindowOld instanceof SessionWindowExpression) {
ksqlWindowNew = new SessionWindowExpression(location, ((SessionWindowExpression) ksqlWindowOld).getGap(), retention, Optional.of(zeroGracePeriod));
} else {
throw new KsqlException("WINDOW type must be HOPPING, TUMBLING, or SESSION");
}
return Optional.of(new WindowExpression(original.getWindowExpression().get().getWindowName(), ksqlWindowNew));
}
use of io.confluent.ksql.execution.windows.HoppingWindowExpression in project ksql by confluentinc.
the class StreamAggregateBuilderTest method givenHoppingWindowedAggregate.
private void givenHoppingWindowedAggregate() {
givenTimeWindowedAggregate();
windowedAggregate = new StreamWindowedAggregate(new ExecutionStepPropertiesV1(CTX), sourceStep, Formats.of(KEY_FORMAT, VALUE_FORMAT, SerdeFeatures.of(), SerdeFeatures.of()), NON_AGG_COLUMNS, FUNCTIONS, new HoppingWindowExpression(Optional.empty(), new WindowTimeClause(WINDOW.getSeconds(), TimeUnit.SECONDS), new WindowTimeClause(HOP.getSeconds(), TimeUnit.SECONDS), Optional.of(retentionClause), Optional.of(gracePeriodClause)));
}
Aggregations