Search in sources :

Example 16 with AstNode

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."));
}
Also used : AstNode(io.confluent.ksql.parser.tree.AstNode) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 17 with AstNode

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)));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 18 with AstNode

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)));
}
Also used : GroupBy(io.confluent.ksql.parser.tree.GroupBy) Query(io.confluent.ksql.parser.tree.Query) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 19 with AstNode

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)));
}
Also used : CreateStream(io.confluent.ksql.parser.tree.CreateStream) TableElement(io.confluent.ksql.parser.tree.TableElement) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 20 with AstNode

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);
}
Also used : AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Aggregations

AstNode (io.confluent.ksql.parser.tree.AstNode)35 Test (org.junit.Test)34 Query (io.confluent.ksql.parser.tree.Query)6 KsqlWindowExpression (io.confluent.ksql.execution.windows.KsqlWindowExpression)3 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)3 KsqlException (io.confluent.ksql.util.KsqlException)3 CreateStreamAsSelect (io.confluent.ksql.parser.tree.CreateStreamAsSelect)2 Explain (io.confluent.ksql.parser.tree.Explain)2 GroupBy (io.confluent.ksql.parser.tree.GroupBy)2 InsertInto (io.confluent.ksql.parser.tree.InsertInto)2 Join (io.confluent.ksql.parser.tree.Join)2 JoinedSource (io.confluent.ksql.parser.tree.JoinedSource)2 PartitionBy (io.confluent.ksql.parser.tree.PartitionBy)2 TableElement (io.confluent.ksql.parser.tree.TableElement)2 WithinExpression (io.confluent.ksql.parser.tree.WithinExpression)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)1 CreateStream (io.confluent.ksql.parser.tree.CreateStream)1 CreateTable (io.confluent.ksql.parser.tree.CreateTable)1