Search in sources :

Example 6 with JoinedSource

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

the class KsqlParserTest method shouldSetWithinExpressionWithSingleWithinAndGracePeriod.

@Test
public void shouldSetWithinExpressionWithSingleWithinAndGracePeriod() {
    final String statementString = "CREATE STREAM foobar as SELECT * from TEST1 JOIN ORDERS WITHIN " + "10 SECONDS GRACE PERIOD 5 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.of(new WindowTimeClause(5, TimeUnit.SECONDS))));
    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 7 with JoinedSource

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

the class KsqlParserTest method shouldHaveInnerJoinTypeWithExplicitInnerKeyword.

@Test
public void shouldHaveInnerJoinTypeWithExplicitInnerKeyword() {
    final String statementString = "CREATE STREAM foobar as SELECT * from TEST1 INNER JOIN TEST2 " + "ON TEST1.col1 = TEST2.col1;";
    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());
    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) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) Test(org.junit.Test)

Example 8 with JoinedSource

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

the class StatementRewriterTest method shouldRewriteJoinWithWindowExpression.

@Test
public void shouldRewriteJoinWithWindowExpression() {
    // Given:
    final WithinExpression withinExpression = mock(WithinExpression.class);
    final WithinExpression rewrittenWithinExpression = mock(WithinExpression.class);
    final Join join = givenJoin(Optional.of(withinExpression));
    when(mockRewriter.apply(withinExpression, context)).thenReturn(rewrittenWithinExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(join, context);
    // Then:
    assertThat(rewritten, equalTo(new Join(location, rewrittenRelation, ImmutableList.of(new JoinedSource(Optional.empty(), rewrittenRightRelation, Type.LEFT, joinCriteria, Optional.of(rewrittenWithinExpression))))));
}
Also used : JoinedSource(io.confluent.ksql.parser.tree.JoinedSource) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) Join(io.confluent.ksql.parser.tree.Join) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 9 with JoinedSource

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

the class KsqlParserTest method shouldHaveLeftJoinTypeWhenOuterIsSpecified.

@Test
public void shouldHaveLeftJoinTypeWhenOuterIsSpecified() {
    final String statementString = "CREATE STREAM foobar as SELECT * from TEST1 LEFT OUTER JOIN " + "TEST2 ON TEST1.col1 = TEST2.col1;";
    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());
    assertThat(join.getType(), is(JoinedSource.Type.LEFT));
}
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) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) Test(org.junit.Test)

Example 10 with JoinedSource

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

the class KsqlParserTest method shouldHaveOuterJoinType.

@Test
public void shouldHaveOuterJoinType() {
    final String statementString = "CREATE STREAM foobar as SELECT * from TEST1 FULL JOIN " + "TEST2 ON TEST1.col1 = TEST2.col1;";
    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());
    assertThat(join.getType(), is(JoinedSource.Type.OUTER));
}
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) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) Test(org.junit.Test)

Aggregations

Join (io.confluent.ksql.parser.tree.Join)20 JoinedSource (io.confluent.ksql.parser.tree.JoinedSource)20 Test (org.junit.Test)20 WithinExpression (io.confluent.ksql.parser.tree.WithinExpression)10 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)9 CreateStreamAsSelect (io.confluent.ksql.parser.tree.CreateStreamAsSelect)9 Query (io.confluent.ksql.parser.tree.Query)9 Statement (io.confluent.ksql.parser.tree.Statement)9 TerminateQuery (io.confluent.ksql.parser.tree.TerminateQuery)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 StringContains.containsString (org.hamcrest.core.StringContains.containsString)9 WindowTimeClause (io.confluent.ksql.execution.windows.WindowTimeClause)2 AstNode (io.confluent.ksql.parser.tree.AstNode)2