Search in sources :

Example 31 with AstNode

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

the class StatementRewriterTest method shouldRewriteStatements.

@Test
public void shouldRewriteStatements() {
    // Given:
    final Statement statement1 = mock(Statement.class);
    final Statement statement2 = mock(Statement.class);
    final Statement rewritten1 = mock(Statement.class);
    final Statement rewritten2 = mock(Statement.class);
    final Statements statements = new Statements(location, ImmutableList.of(statement1, statement2));
    when(mockRewriter.apply(statement1, context)).thenReturn(rewritten1);
    when(mockRewriter.apply(statement2, context)).thenReturn(rewritten2);
    // When:
    final AstNode rewritten = rewriter.rewrite(statements, context);
    // Then:
    assertThat(rewritten, equalTo(new Statements(location, ImmutableList.of(rewritten1, rewritten2))));
}
Also used : Statement(io.confluent.ksql.parser.tree.Statement) Statements(io.confluent.ksql.parser.tree.Statements) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 32 with AstNode

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

the class StatementRewriterTest method shouldRewriteCTAS.

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

Example 33 with AstNode

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

the class StatementRewriterTest method shouldRewriteInsertInto.

@Test
public void shouldRewriteInsertInto() {
    // Given:
    final InsertInto ii = new InsertInto(location, sourceName, query, insertIntoProperties);
    when(mockRewriter.apply(query, context)).thenReturn(rewrittenQuery);
    // When:
    final AstNode rewritten = rewriter.rewrite(ii, context);
    // Then:
    assertThat(rewritten, equalTo(new InsertInto(location, sourceName, rewrittenQuery, insertIntoProperties)));
}
Also used : InsertInto(io.confluent.ksql.parser.tree.InsertInto) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 34 with AstNode

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

the class StatementRewriterTest method shouldRewriteAliasedRelation.

@Test
public void shouldRewriteAliasedRelation() {
    // Given:
    final AliasedRelation aliasedRelation = new AliasedRelation(location, relation, SourceName.of("alias"));
    when(mockRewriter.apply(relation, context)).thenReturn(rewrittenRelation);
    // When:
    final AstNode rewritten = rewriter.rewrite(aliasedRelation, context);
    // Then:
    assertThat(rewritten, equalTo(new AliasedRelation(location, rewrittenRelation, SourceName.of("alias"))));
}
Also used : AstNode(io.confluent.ksql.parser.tree.AstNode) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation) Test(org.junit.Test)

Example 35 with AstNode

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

the class StatementRewriterTest method shouldRewriteSingleColumn.

@Test
public void shouldRewriteSingleColumn() {
    // Given:
    final SingleColumn singleColumn = new SingleColumn(location, expression, Optional.of(ColumnName.of("foo")));
    when(expressionRewriter.apply(expression, context)).thenReturn(rewrittenExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(singleColumn, context);
    // Then:
    assertThat(rewritten, equalTo(new SingleColumn(location, rewrittenExpression, Optional.of(ColumnName.of("foo")))));
}
Also used : SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) 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