Search in sources :

Example 21 with AstNode

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

the class DataSourceExtractorTest method shouldThrowIfSourceDoesNotExist.

@Test
public void shouldThrowIfSourceDoesNotExist() {
    // Given:
    final AstNode stmt = givenQuery("SELECT * FROM UNKNOWN;");
    // 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 22 with AstNode

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

the class DataSourceExtractorTest method shouldExtractUnaliasedDataSources.

@Test
public void shouldExtractUnaliasedDataSources() {
    // Given:
    final AstNode stmt = givenQuery("SELECT * FROM TEST1;");
    // When:
    extractor.extractDataSources(stmt);
    // Then:
    assertContainsAlias(TEST1);
}
Also used : AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 23 with AstNode

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

the class DataSourceExtractorTest method shouldIncludePseudoColumnsInClashingNames.

@Test
public void shouldIncludePseudoColumnsInClashingNames() {
    // Given:
    final AstNode stmt = givenQuery("SELECT * FROM TEST1 t1 JOIN TEST2 t2" + " ON test1.col1 = test2.col1;");
    // When:
    extractor.extractDataSources(stmt);
    // Then:
    SystemColumns.pseudoColumnNames(ROWPARTITION_ROWOFFSET_ENABLED).forEach(pseudoCol -> assertThat(pseudoCol + " should clash", extractor.isClashingColumnName(pseudoCol)));
}
Also used : AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 24 with AstNode

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

the class StatementRewriterTest method shouldRewriteQueryWithFilter.

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

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

the class StatementRewriterTest method shouldRewriteJoin.

@Test
public void shouldRewriteJoin() {
    // Given:
    final Join join = givenJoin(Optional.empty());
    // 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.empty())))));
}
Also used : JoinedSource(io.confluent.ksql.parser.tree.JoinedSource) Join(io.confluent.ksql.parser.tree.Join) 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