Search in sources :

Example 1 with WithinExpression

use of io.confluent.ksql.parser.tree.WithinExpression in project ksql by confluentinc.

the class JoinNodeTest method shouldNotPerformStreamToTableJoinIfJoinWindowIsSpecified.

@Test
public void shouldNotPerformStreamToTableJoinIfJoinWindowIsSpecified() {
    // Given:
    when(left.getNodeOutputType()).thenReturn(DataSourceType.KSTREAM);
    when(right.getNodeOutputType()).thenReturn(DataSourceType.KTABLE);
    final WithinExpression withinExpression = new WithinExpression(10, TimeUnit.SECONDS);
    final JoinNode joinNode = new JoinNode(nodeId, OUTER, joinKey, true, left, right, Optional.of(withinExpression), "KAFKA");
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> joinNode.buildStream(planBuildContext));
    // Then:
    assertThat(e.getMessage(), containsString("A window definition was provided for a Stream-Table join."));
}
Also used : WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 2 with WithinExpression

use of io.confluent.ksql.parser.tree.WithinExpression in project ksql by confluentinc.

the class SqlFormatterTest method shouldFormatInnerJoin.

@Test
public void shouldFormatInnerJoin() {
    final Join join = new Join(leftAlias, ImmutableList.of(new JoinedSource(Optional.empty(), rightAlias, JoinedSource.Type.INNER, criteria, Optional.of(new WithinExpression(10, TimeUnit.SECONDS)))));
    final String expected = "`left` L\nINNER JOIN `right` R WITHIN 10 SECONDS ON " + "(('left.col0' = 'right.col0'))";
    assertEquals(expected, SqlFormatter.formatSql(join));
}
Also used : JoinedSource(io.confluent.ksql.parser.tree.JoinedSource) Join(io.confluent.ksql.parser.tree.Join) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 3 with WithinExpression

use of io.confluent.ksql.parser.tree.WithinExpression in project ksql by confluentinc.

the class SqlFormatterTest method shouldFormatLeftJoinWithWithin.

@Test
public void shouldFormatLeftJoinWithWithin() {
    final Join join = new Join(leftAlias, ImmutableList.of(new JoinedSource(Optional.empty(), rightAlias, JoinedSource.Type.LEFT, criteria, Optional.of(new WithinExpression(10, TimeUnit.SECONDS)))));
    final String expected = "`left` L\nLEFT OUTER JOIN `right` R WITHIN 10 SECONDS ON " + "(('left.col0' = 'right.col0'))";
    assertEquals(expected, SqlFormatter.formatSql(join));
}
Also used : JoinedSource(io.confluent.ksql.parser.tree.JoinedSource) Join(io.confluent.ksql.parser.tree.Join) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 4 with WithinExpression

use of io.confluent.ksql.parser.tree.WithinExpression in project ksql by confluentinc.

the class KsqlParserTest method shouldSetWithinExpressionWithSingleWithin.

@Test
public void shouldSetWithinExpressionWithSingleWithin() {
    final String statementString = "CREATE STREAM foobar as SELECT * from TEST1 JOIN ORDERS WITHIN " + "10 SECONDS 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(10L));
    assertThat(withinExpression.getBeforeTimeUnit(), is(TimeUnit.SECONDS));
    assertThat(withinExpression.getGrace(), is(Optional.empty()));
    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) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) Test(org.junit.Test)

Example 5 with WithinExpression

use of io.confluent.ksql.parser.tree.WithinExpression in project ksql by confluentinc.

the class KsqlParserTest method shouldSetWithinExpressionWithBeforeAndAfter.

@Test
public void shouldSetWithinExpressionWithBeforeAndAfter() {
    final String statementString = "CREATE STREAM foobar as SELECT * from TEST1 JOIN ORDERS " + "WITHIN (10 seconds, 20 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.empty()));
    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) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) Test(org.junit.Test)

Aggregations

WithinExpression (io.confluent.ksql.parser.tree.WithinExpression)13 Test (org.junit.Test)13 Join (io.confluent.ksql.parser.tree.Join)10 JoinedSource (io.confluent.ksql.parser.tree.JoinedSource)10 StringContains.containsString (org.hamcrest.core.StringContains.containsString)5 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)4 CreateStreamAsSelect (io.confluent.ksql.parser.tree.CreateStreamAsSelect)4 Query (io.confluent.ksql.parser.tree.Query)4 Statement (io.confluent.ksql.parser.tree.Statement)4 TerminateQuery (io.confluent.ksql.parser.tree.TerminateQuery)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 WindowTimeClause (io.confluent.ksql.execution.windows.WindowTimeClause)3 KsqlException (io.confluent.ksql.util.KsqlException)2 JoinType (io.confluent.ksql.execution.plan.JoinType)1 AstNode (io.confluent.ksql.parser.tree.AstNode)1 Pair (io.confluent.ksql.util.Pair)1 JoinWindows (org.apache.kafka.streams.kstream.JoinWindows)1