Search in sources :

Example 11 with AstNode

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

the class DataSourceExtractorTest method shouldHandleAliasedDataSources.

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

Example 12 with AstNode

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

the class DataSourceExtractorTest method shouldExtractUnaliasedJoinDataSources.

@Test
public void shouldExtractUnaliasedJoinDataSources() {
    // Given:
    final AstNode stmt = givenQuery("SELECT * FROM TEST1 JOIN TEST2" + " ON test1.col1 = test2.col1;");
    // When:
    extractor.extractDataSources(stmt);
    // Then:
    assertContainsAlias(TEST1, TEST2);
}
Also used : AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 13 with AstNode

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

the class DataSourceExtractorTest method shouldDetectClashingColumnNames.

@Test
public void shouldDetectClashingColumnNames() {
    // Given:
    final AstNode stmt = givenQuery("SELECT * FROM TEST1 t1 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)

Example 14 with AstNode

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

the class DataSourceExtractorTest method shouldDetectNoneClashingColumnNames.

@Test
public void shouldDetectNoneClashingColumnNames() {
    // 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 not clash", !extractor.isClashingColumnName(ColumnName.of("ORDERTIME")));
}
Also used : AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 15 with AstNode

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

the class DataSourceExtractorTest method shouldThrowIfLeftJoinSourceDoesNotExist.

@Test
public void shouldThrowIfLeftJoinSourceDoesNotExist() {
    // Given:
    final AstNode stmt = givenQuery("SELECT * FROM UNKNOWN JOIN TEST2" + " ON UNKNOWN.col1 = test2.col1;");
    // 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)

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