Search in sources :

Example 6 with WindowTimeClause

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))));
    }
}
Also used : JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) JoinType(io.confluent.ksql.execution.plan.JoinType) WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) Pair(io.confluent.ksql.util.Pair) Test(org.junit.Test)

Example 7 with WindowTimeClause

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())));
}
Also used : KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) TumblingWindowExpression(io.confluent.ksql.execution.windows.TumblingWindowExpression) Test(org.junit.Test)

Example 8 with WindowTimeClause

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));
}
Also used : JoinedSource(io.confluent.ksql.parser.tree.JoinedSource) Query(io.confluent.ksql.parser.tree.Query) TerminateQuery(io.confluent.ksql.parser.tree.TerminateQuery) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) Join(io.confluent.ksql.parser.tree.Join) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) Test(org.junit.Test)

Example 9 with WindowTimeClause

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)))));
}
Also used : WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) TumblingWindowExpression(io.confluent.ksql.execution.windows.TumblingWindowExpression) Test(org.junit.Test)

Example 10 with WindowTimeClause

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());
}
Also used : WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) Test(org.junit.Test)

Aggregations

WindowTimeClause (io.confluent.ksql.execution.windows.WindowTimeClause)14 Test (org.junit.Test)10 TumblingWindowExpression (io.confluent.ksql.execution.windows.TumblingWindowExpression)7 StreamWindowedAggregate (io.confluent.ksql.execution.plan.StreamWindowedAggregate)4 ExecutionStepPropertiesV1 (io.confluent.ksql.execution.plan.ExecutionStepPropertiesV1)3 KsqlWindowExpression (io.confluent.ksql.execution.windows.KsqlWindowExpression)3 WithinExpression (io.confluent.ksql.parser.tree.WithinExpression)3 HoppingWindowExpression (io.confluent.ksql.execution.windows.HoppingWindowExpression)2 SessionWindowExpression (io.confluent.ksql.execution.windows.SessionWindowExpression)2 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)2 CreateStreamAsSelect (io.confluent.ksql.parser.tree.CreateStreamAsSelect)2 Join (io.confluent.ksql.parser.tree.Join)2 JoinedSource (io.confluent.ksql.parser.tree.JoinedSource)2 Query (io.confluent.ksql.parser.tree.Query)2 Statement (io.confluent.ksql.parser.tree.Statement)2 TerminateQuery (io.confluent.ksql.parser.tree.TerminateQuery)2 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 GenericKey (io.confluent.ksql.GenericKey)1 JoinType (io.confluent.ksql.execution.plan.JoinType)1