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));
}
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));
}
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))))));
}
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));
}
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));
}
Aggregations