Search in sources :

Example 6 with AstNode

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

the class StatementRewriterTest method shouldRewriteQuery.

@Test
public void shouldRewriteQuery() {
    // Given:
    final Query query = givenQuery(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    // 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.empty(), 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 7 with AstNode

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

the class StatementRewriterTest method shouldRewritePartitionBy.

@Test
public void shouldRewritePartitionBy() {
    // Given:
    final PartitionBy partitionBy = new PartitionBy(location, ImmutableList.of(expression));
    when(expressionRewriter.apply(expression, context)).thenReturn(rewrittenExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(partitionBy, context);
    // Then:
    assertThat(rewritten, equalTo(new PartitionBy(location, ImmutableList.of(rewrittenExpression))));
}
Also used : PartitionBy(io.confluent.ksql.parser.tree.PartitionBy) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 8 with AstNode

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

the class StatementRewriterTest method shouldRewriteGroupBy.

@Test
public void shouldRewriteGroupBy() {
    // Given:
    final Expression exp1 = mock(Expression.class);
    final Expression exp2 = mock(Expression.class);
    final Expression rewrittenExp1 = mock(Expression.class);
    final Expression rewrittenExp2 = mock(Expression.class);
    final GroupBy groupBy = new GroupBy(location, ImmutableList.of(exp1, exp2));
    when(expressionRewriter.apply(exp1, context)).thenReturn(rewrittenExp1);
    when(expressionRewriter.apply(exp2, context)).thenReturn(rewrittenExp2);
    // When:
    final AstNode rewritten = rewriter.rewrite(groupBy, context);
    // Then:
    assertThat(rewritten, equalTo(new GroupBy(location, ImmutableList.of(rewrittenExp1, rewrittenExp2))));
}
Also used : GroupBy(io.confluent.ksql.parser.tree.GroupBy) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) 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 9 with AstNode

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

the class StatementRewriterTest method shouldRewriteJoinWithWindowExpression.

@Test
public void shouldRewriteJoinWithWindowExpression() {
    // Given:
    final WithinExpression withinExpression = mock(WithinExpression.class);
    final WithinExpression rewrittenWithinExpression = mock(WithinExpression.class);
    final Join join = givenJoin(Optional.of(withinExpression));
    when(mockRewriter.apply(withinExpression, context)).thenReturn(rewrittenWithinExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(join, context);
    // Then:
    assertThat(rewritten, equalTo(new Join(location, rewrittenRelation, ImmutableList.of(new JoinedSource(Optional.empty(), rewrittenRightRelation, Type.LEFT, joinCriteria, Optional.of(rewrittenWithinExpression))))));
}
Also used : JoinedSource(io.confluent.ksql.parser.tree.JoinedSource) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) Join(io.confluent.ksql.parser.tree.Join) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 10 with AstNode

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

the class DataSourceExtractorTest method shouldDetectClashingColumnNamesEvenIfOneJoinSourceHasNoClash.

@Test
public void shouldDetectClashingColumnNamesEvenIfOneJoinSourceHasNoClash() {
    // Given:
    final AstNode stmt = givenQuery("SELECT * FROM ORDERS " + "JOIN TEST1 t1 ON ORDERS.ITEMID = T1.COL1 " + "JOIN TEST2 t2 ON test1.col1 = test2.col1;");
    // When:
    extractor.extractDataSources(stmt);
    // Then:
    assertThat("should clash", extractor.isClashingColumnName(COL0));
}
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