use of io.confluent.ksql.execution.windows.TumblingWindowExpression 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.TumblingWindowExpression in project ksql by confluentinc.
the class ExpressionParserTest method shouldParseWindowExpressionWithRetention.
@Test
public void shouldParseWindowExpressionWithRetention() {
// When:
final KsqlWindowExpression parsed = ExpressionParser.parseWindowExpression("TUMBLING (SIZE 1 DAYS, RETENTION 2 DAYS, GRACE PERIOD 2 DAYS)");
// Then:
assertThat(parsed, equalTo(new TumblingWindowExpression(parsed.getLocation(), new WindowTimeClause(1, TimeUnit.DAYS), Optional.of(new WindowTimeClause(2, TimeUnit.DAYS)), Optional.of(new WindowTimeClause(2, TimeUnit.DAYS)))));
}
use of io.confluent.ksql.execution.windows.TumblingWindowExpression in project ksql by confluentinc.
the class ScalablePushUtilTest method isScalablePushQuery_false_hasWindow.
@Test
public void isScalablePushQuery_false_hasWindow() {
try (MockedStatic<ColumnExtractor> columnExtractor = mockStatic(ColumnExtractor.class)) {
// When:
expectIsSPQ(ColumnName.of("foo"), columnExtractor);
when(query.getWindow()).thenReturn(Optional.of(new WindowExpression("foo", new TumblingWindowExpression(new WindowTimeClause(1, TimeUnit.MILLISECONDS)))));
// Then:
assertThat(ScalablePushUtil.isScalablePushQuery(query, ksqlEngine, ksqlConfig, ImmutableMap.of(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest")), equalTo(false));
}
}
use of io.confluent.ksql.execution.windows.TumblingWindowExpression in project ksql by confluentinc.
the class ExpressionParserTest method shouldParseWindowExpression.
@Test
public void shouldParseWindowExpression() {
// When:
final KsqlWindowExpression parsed = ExpressionParser.parseWindowExpression("TUMBLING (SIZE 1 DAYS)");
// Then:
assertThat(parsed, equalTo(new TumblingWindowExpression(parsed.getLocation(), new WindowTimeClause(1, TimeUnit.DAYS), Optional.empty(), Optional.empty())));
}
use of io.confluent.ksql.execution.windows.TumblingWindowExpression in project ksql by confluentinc.
the class TumblingWindowExpressionTest method shouldReturnWindowInfo.
@Test
public void shouldReturnWindowInfo() {
assertThat(new TumblingWindowExpression(new WindowTimeClause(11, SECONDS)).getWindowInfo(), is(WindowInfo.of(WindowType.TUMBLING, Optional.of(Duration.ofSeconds(11)))));
assertThat(new TumblingWindowExpression(Optional.empty(), new WindowTimeClause(20, SECONDS), Optional.of(new WindowTimeClause(20, SECONDS)), Optional.of(new WindowTimeClause(10, SECONDS))).getWindowInfo(), is(WindowInfo.of(WindowType.TUMBLING, Optional.of(Duration.ofSeconds(20)))));
}
Aggregations