use of io.confluent.ksql.parser.tree.AstNode in project ksql by confluentinc.
the class DataSourceExtractorTest method shouldThrowIfRightJoinSourceDoesNotExist.
@Test
public void shouldThrowIfRightJoinSourceDoesNotExist() {
// Given:
final AstNode stmt = givenQuery("SELECT * FROM TEST1 JOIN UNKNOWN" + " ON test1.col1 = UNKNOWN.col1;");
// When:
final Exception e = assertThrows(KsqlException.class, () -> extractor.extractDataSources(stmt));
// Then:
assertThat(e.getMessage(), containsString("UNKNOWN does not exist."));
}
use of io.confluent.ksql.parser.tree.AstNode in project ksql by confluentinc.
the class StatementRewriterTest method shouldRewriteQueryWithWindow.
@Test
public void shouldRewriteQueryWithWindow() {
// Given:
final WindowExpression window = mock(WindowExpression.class);
final WindowExpression rewrittenWindow = mock(WindowExpression.class);
final Query query = givenQuery(Optional.of(window), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
when(mockRewriter.apply(window, context)).thenReturn(rewrittenWindow);
// When:
final AstNode rewritten = rewriter.rewrite(query, context);
// Then:
assertThat(rewritten, equalTo(new Query(location, rewrittenSelect, rewrittenRelation, Optional.of(rewrittenWindow), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(refinementInfo), false, optionalInt)));
}
use of io.confluent.ksql.parser.tree.AstNode in project ksql by confluentinc.
the class StatementRewriterTest method shouldRewriteQueryWithGroupBy.
@Test
public void shouldRewriteQueryWithGroupBy() {
// Given:
final GroupBy groupBy = mock(GroupBy.class);
final GroupBy rewrittenGroupBy = mock(GroupBy.class);
final Query query = givenQuery(Optional.empty(), Optional.empty(), Optional.of(groupBy), Optional.empty(), Optional.empty());
when(mockRewriter.apply(groupBy, context)).thenReturn(rewrittenGroupBy);
// When:
final AstNode rewritten = rewriter.rewrite(query, context);
// Then:
assertThat(rewritten, equalTo(new Query(location, rewrittenSelect, rewrittenRelation, Optional.empty(), Optional.empty(), Optional.of(rewrittenGroupBy), Optional.empty(), Optional.empty(), Optional.of(refinementInfo), false, optionalInt)));
}
use of io.confluent.ksql.parser.tree.AstNode in project ksql by confluentinc.
the class StatementRewriterTest method shouldRewriteCreateStream.
@Test
public void shouldRewriteCreateStream() {
// Given:
final TableElement tableElement1 = givenTableElement("foo");
final TableElement tableElement2 = givenTableElement("bar");
final TableElement rewrittenTableElement1 = givenTableElement("baz");
final TableElement rewrittenTableElement2 = givenTableElement("boz");
final CreateStream cs = new CreateStream(location, sourceName, TableElements.of(tableElement1, tableElement2), false, false, sourceProperties, false);
when(mockRewriter.apply(tableElement1, context)).thenReturn(rewrittenTableElement1);
when(mockRewriter.apply(tableElement2, context)).thenReturn(rewrittenTableElement2);
// When:
final AstNode rewritten = rewriter.rewrite(cs, context);
// Then:
assertThat(rewritten, equalTo(new CreateStream(location, sourceName, TableElements.of(rewrittenTableElement1, rewrittenTableElement2), false, false, sourceProperties, false)));
}
use of io.confluent.ksql.parser.tree.AstNode in project ksql by confluentinc.
the class DataSourceExtractorTest method shouldHandleAliasedJoinDataSources.
@Test
public void shouldHandleAliasedJoinDataSources() {
// Given:
final AstNode stmt = givenQuery("SELECT * FROM TEST1 t1 JOIN TEST2 t2" + " ON test1.col1 = test2.col1;");
// When:
extractor.extractDataSources(stmt);
// Then:
assertContainsAlias(T1, T2);
}
Aggregations