Search in sources :

Example 26 with AstNode

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

the class StatementRewriterTest method shouldUsePluginToRewrite.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
private void shouldUsePluginToRewrite(final AstNode original, final AstNode pluginResult) {
    // Given:
    when(mockPlugin.apply(any(), any())).thenReturn(Optional.of(pluginResult));
    // When:
    final AstNode rewritten = rewriter.rewrite(original, context);
    // Then:
    assertThat(rewritten, is(pluginResult));
    verify(mockPlugin).apply(same(original), contextCaptor.capture());
    final Context<Object> wrapped = contextCaptor.getValue();
    assertThat(wrapped.getContext(), is(this.context));
}
Also used : AstNode(io.confluent.ksql.parser.tree.AstNode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 27 with AstNode

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

the class StatementRewriterTest method shouldRewriteInsertIntoWithPartitionBy.

@Test
public void shouldRewriteInsertIntoWithPartitionBy() {
    // Given:
    final InsertInto ii = new InsertInto(location, sourceName, query, insertIntoProperties);
    when(mockRewriter.apply(query, context)).thenReturn(rewrittenQuery);
    when(expressionRewriter.apply(expression, context)).thenReturn(rewrittenExpression);
    // 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 28 with AstNode

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

the class StatementRewriterTest method shouldNotRewriteExplainWithId.

@Test
public void shouldNotRewriteExplainWithId() {
    // Given:
    final Explain explain = new Explain(location, Optional.of("id"), Optional.empty());
    // When:
    final AstNode rewritten = rewriter.rewrite(explain, context);
    // Then:
    assertThat(rewritten, is(sameInstance(explain)));
}
Also used : Explain(io.confluent.ksql.parser.tree.Explain) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 29 with AstNode

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

the class StatementRewriterTest method shouldRewriteExplainWithQuery.

@Test
public void shouldRewriteExplainWithQuery() {
    // Given:
    final Explain explain = new Explain(location, Optional.empty(), Optional.of(query));
    when(mockRewriter.apply(query, context)).thenReturn(rewrittenQuery);
    // When:
    final AstNode rewritten = rewriter.rewrite(explain, context);
    // Then:
    assertThat(rewritten, is(new Explain(location, Optional.empty(), Optional.of(rewrittenQuery))));
}
Also used : Explain(io.confluent.ksql.parser.tree.Explain) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 30 with AstNode

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

the class StatementRewriterTest method shouldRewriteWindowExpression.

@Test
public void shouldRewriteWindowExpression() {
    // Given:
    final KsqlWindowExpression ksqlWindowExpression = mock(KsqlWindowExpression.class);
    final WindowExpression windowExpression = new WindowExpression(location, "name", ksqlWindowExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(windowExpression, context);
    // Then:
    assertThat(rewritten, equalTo(new WindowExpression(location, "name", ksqlWindowExpression)));
}
Also used : WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) 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