use of io.confluent.ksql.execution.windows.WindowTimeClause in project ksql by confluentinc.
the class SchemaKStreamTest method shouldBuildStepForStreamStreamJoin.
@Test
// can be fixed after GRACE clause is made mandatory
@SuppressWarnings({ "rawtypes", "deprecation" })
public void shouldBuildStepForStreamStreamJoin() {
// Given:
final SchemaKStream initialSchemaKStream = buildSchemaKStreamForJoin(ksqlStream);
final List<Pair<JoinType, StreamStreamJoin>> cases = ImmutableList.of(Pair.of(JoinType.OUTER, initialSchemaKStream::outerJoin), Pair.of(JoinType.LEFT, initialSchemaKStream::leftJoin), Pair.of(JoinType.INNER, initialSchemaKStream::innerJoin));
final JoinWindows joinWindows = JoinWindows.of(Duration.ofSeconds(1));
final WindowTimeClause grace = new WindowTimeClause(5, TimeUnit.SECONDS);
final WithinExpression withinExpression = new WithinExpression(1, TimeUnit.SECONDS, grace);
for (final Pair<JoinType, StreamStreamJoin> testcase : cases) {
final SchemaKStream joinedKStream = testcase.right.join(schemaKStream, KEY, withinExpression, valueFormat.getFormatInfo(), valueFormat.getFormatInfo(), childContextStacker);
// Then:
assertThat(joinedKStream.getSourceStep(), equalTo(ExecutionStepFactory.streamStreamJoin(childContextStacker, testcase.left, KEY, InternalFormats.of(keyFormat, valueFormat.getFormatInfo()), InternalFormats.of(keyFormat, valueFormat.getFormatInfo()), initialSchemaKStream.getSourceStep(), schemaKStream.getSourceStep(), joinWindows, Optional.of(grace))));
}
}
use of io.confluent.ksql.execution.windows.WindowTimeClause 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.WindowTimeClause in project ksql by confluentinc.
the class KsqlParserTest method shouldSetWithinExpressionWithBeforeAndAfterAndGracePeriod.
@Test
public void shouldSetWithinExpressionWithBeforeAndAfterAndGracePeriod() {
final String statementString = "CREATE STREAM foobar as SELECT * from TEST1 JOIN ORDERS " + "WITHIN (10 seconds, 20 minutes) GRACE PERIOD 10 minutes " + "ON TEST1.col1 = ORDERS.ORDERID ;";
final Statement statement = KsqlParserTestUtil.buildSingleAst(statementString, metaStore).getStatement();
assertThat(statement, instanceOf(CreateStreamAsSelect.class));
final CreateStreamAsSelect createStreamAsSelect = (CreateStreamAsSelect) statement;
final Query query = createStreamAsSelect.getQuery();
assertThat(query.getFrom(), instanceOf(Join.class));
final JoinedSource join = Iterables.getOnlyElement(((Join) query.getFrom()).getRights());
assertTrue(join.getWithinExpression().isPresent());
final WithinExpression withinExpression = join.getWithinExpression().get();
assertThat(withinExpression.getBefore(), is(10L));
assertThat(withinExpression.getAfter(), is(20L));
assertThat(withinExpression.getBeforeTimeUnit(), is(TimeUnit.SECONDS));
assertThat(withinExpression.getAfterTimeUnit(), is(TimeUnit.MINUTES));
assertThat(withinExpression.getGrace(), is(Optional.of(new WindowTimeClause(10, TimeUnit.MINUTES))));
assertThat(join.getType(), is(JoinedSource.Type.INNER));
}
use of io.confluent.ksql.execution.windows.WindowTimeClause 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)))));
}
use of io.confluent.ksql.execution.windows.WindowTimeClause in project ksql by confluentinc.
the class WithinExpressionTest method shouldDisplayCorrectStringWithBeforeAndAfterWithGracePeriod.
@Test
public void shouldDisplayCorrectStringWithBeforeAndAfterWithGracePeriod() {
final WindowTimeClause gracePeriod = new WindowTimeClause(5, TimeUnit.SECONDS);
final WithinExpression expression = new WithinExpression(30, 40, TimeUnit.MINUTES, TimeUnit.HOURS, gracePeriod);
assertEquals(" WITHIN (30 MINUTES, 40 HOURS) GRACE PERIOD 5 SECONDS", expression.toString());
assertEquals(JoinWindows.of(Duration.ofMinutes(30)).after(Duration.ofHours(40)).grace(Duration.ofSeconds(5)), expression.joinWindow());
}
Aggregations