Search in sources :

Example 1 with AstNode

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

the class StatementRewriterTest method shouldRewriteQueryWithHaving.

@Test
public void shouldRewriteQueryWithHaving() {
    // Given:
    final Query query = givenQuery(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(expression));
    when(expressionRewriter.apply(expression, context)).thenReturn(rewrittenExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(query, context);
    // Then:
    assertThat(rewritten, equalTo(new Query(location, rewrittenSelect, rewrittenRelation, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(rewrittenExpression), Optional.of(refinementInfo), false, optionalInt)));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 2 with AstNode

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

the class StatementRewriterTest method shouldRewriteQueryWithPartitionBy.

@Test
public void shouldRewriteQueryWithPartitionBy() {
    // Given:
    final PartitionBy partitionBy = mock(PartitionBy.class);
    final PartitionBy rewrittenPartitionBy = mock(PartitionBy.class);
    final Query query = givenQuery(Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(partitionBy), Optional.empty());
    when(mockRewriter.apply(partitionBy, context)).thenReturn(rewrittenPartitionBy);
    // When:
    final AstNode rewritten = rewriter.rewrite(query, context);
    // Then:
    assertThat(rewritten, equalTo(new Query(location, rewrittenSelect, rewrittenRelation, Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(rewrittenPartitionBy), Optional.empty(), Optional.of(refinementInfo), false, optionalInt)));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) PartitionBy(io.confluent.ksql.parser.tree.PartitionBy) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 3 with AstNode

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

the class StatementRewriterTest method shouldRewriteCreateTable.

@Test
public void shouldRewriteCreateTable() {
    // Given:
    final TableElement tableElement1 = givenTableElement("foo");
    final TableElement tableElement2 = givenTableElement("bar");
    final TableElement rewrittenTableElement1 = givenTableElement("baz");
    final TableElement rewrittenTableElement2 = givenTableElement("boz");
    final CreateTable ct = new CreateTable(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(ct, context);
    // Then:
    assertThat(rewritten, equalTo(new CreateTable(location, sourceName, TableElements.of(rewrittenTableElement1, rewrittenTableElement2), false, false, sourceProperties, false)));
}
Also used : CreateTable(io.confluent.ksql.parser.tree.CreateTable) TableElement(io.confluent.ksql.parser.tree.TableElement) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 4 with AstNode

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

the class StatementRewriterTest method shouldRewriteCSAS.

@Test
public void shouldRewriteCSAS() {
    final CreateStreamAsSelect csas = new CreateStreamAsSelect(location, sourceName, query, false, false, csasProperties);
    when(mockRewriter.apply(query, context)).thenReturn(rewrittenQuery);
    final AstNode rewritten = rewriter.rewrite(csas, context);
    assertThat(rewritten, equalTo(new CreateStreamAsSelect(location, sourceName, rewrittenQuery, false, false, csasProperties)));
}
Also used : CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 5 with AstNode

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

the class StatementRewriterTest method shouldRewriteCSASWithPartitionBy.

@Test
public void shouldRewriteCSASWithPartitionBy() {
    final CreateStreamAsSelect csas = new CreateStreamAsSelect(location, sourceName, query, false, false, csasProperties);
    when(mockRewriter.apply(query, context)).thenReturn(rewrittenQuery);
    when(expressionRewriter.apply(expression, context)).thenReturn(rewrittenExpression);
    final AstNode rewritten = rewriter.rewrite(csas, context);
    assertThat(rewritten, equalTo(new CreateStreamAsSelect(location, sourceName, rewrittenQuery, false, false, csasProperties)));
}
Also used : CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) 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