use of io.confluent.ksql.parser.tree.JoinedSource 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.parser.tree.JoinedSource in project ksql by confluentinc.
the class KsqlParserTest method shouldHaveOuterJoinTypeWhenOuterKeywordIsSpecified.
@Test
public void shouldHaveOuterJoinTypeWhenOuterKeywordIsSpecified() {
final String statementString = "CREATE STREAM foobar as SELECT * from TEST1 FULL 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.OUTER));
}
use of io.confluent.ksql.parser.tree.JoinedSource in project ksql by confluentinc.
the class StatementRewriterTest method shouldRewriteJoin.
@Test
public void shouldRewriteJoin() {
// Given:
final Join join = givenJoin(Optional.empty());
// 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.empty())))));
}
use of io.confluent.ksql.parser.tree.JoinedSource in project ksql by confluentinc.
the class SqlFormatterTest method shouldFormatMultipleJoinsWithDifferentTypes.
@Test
public void shouldFormatMultipleJoinsWithDifferentTypes() {
final List<JoinedSource> rights = ImmutableList.of(new JoinedSource(Optional.empty(), rightAlias, JoinedSource.Type.LEFT, criteria, Optional.of(new WithinExpression(10, TimeUnit.SECONDS))), new JoinedSource(Optional.empty(), right2Alias, JoinedSource.Type.INNER, criteria2, Optional.of(new WithinExpression(10, TimeUnit.SECONDS))));
final Join join = new Join(leftAlias, rights);
final String expected = "`left` L" + "\nLEFT OUTER JOIN `right` R WITHIN 10 SECONDS ON (('left.col0' = 'right.col0'))" + "\nINNER JOIN `right2` R2 WITHIN 10 SECONDS ON (('left.col0' = 'right2.col0'))";
assertEquals(expected, SqlFormatter.formatSql(join));
}
use of io.confluent.ksql.parser.tree.JoinedSource in project ksql by confluentinc.
the class SqlFormatterTest method shouldFormatMultipleLeftJoinWithoutWindow.
@Test
public void shouldFormatMultipleLeftJoinWithoutWindow() {
final List<JoinedSource> rights = ImmutableList.of(new JoinedSource(Optional.empty(), rightAlias, JoinedSource.Type.LEFT, criteria, Optional.empty()), new JoinedSource(Optional.empty(), right2Alias, JoinedSource.Type.LEFT, criteria2, Optional.empty()));
final Join join = new Join(leftAlias, rights);
final String expected = "`left` L" + "\nLEFT OUTER JOIN `right` R ON (('left.col0' = 'right.col0'))" + "\nLEFT OUTER JOIN `right2` R2 ON (('left.col0' = 'right2.col0'))";
assertEquals(expected, SqlFormatter.formatSql(join));
}
Aggregations