use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.
the class AstBuilderTest method shouldExtractAsAliasedDataSources.
@Test
public void shouldExtractAsAliasedDataSources() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT * FROM TEST1 AS t;");
// When:
final Query result = (Query) builder.buildStatement(stmt);
// Then:
assertThat(result.getFrom(), is(new AliasedRelation(TEST1, SourceName.of("T"))));
}
use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.
the class AstBuilderTest method shouldHandleAliasedJoinDataSources.
@Test
public void shouldHandleAliasedJoinDataSources() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT * FROM TEST1 t1 JOIN TEST2 t2" + " ON test1.col1 = test2.col1;");
// When:
final Query result = (Query) builder.buildStatement(stmt);
// Then:
assertThat(result.getFrom(), is(instanceOf(Join.class)));
assertThat((Join) result.getFrom(), hasLeft(new AliasedRelation(TEST1, SourceName.of("T1"))));
assertThat((Join) result.getFrom(), hasRights(new AliasedRelation(TEST2, SourceName.of("T2"))));
}
use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.
the class AstBuilderTest method shouldThrowOnUnknownStarAlias.
@Test
public void shouldThrowOnUnknownStarAlias() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT unknown.* FROM TEST1;");
// When:
final Exception e = assertThrows(KsqlException.class, () -> builder.buildStatement(stmt));
// Then:
assertThat(e.getMessage(), containsString("'UNKNOWN' is not a valid stream/table name or alias."));
}
use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.
the class AstBuilderTest method shouldIncludeSelectAliasIfPresent.
@Test
public void shouldIncludeSelectAliasIfPresent() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT COL0 AS FOO FROM TEST1;");
// When:
final Query result = (Query) builder.buildStatement(stmt);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(column("COL0"), Optional.of(ColumnName.of("FOO")))))));
}
use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.
the class AstBuilderTest method shouldHandleAliasQualifiedSelectStar.
@Test
public void shouldHandleAliasQualifiedSelectStar() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT T.* FROM TEST1 T;");
// When:
final Query result = (Query) builder.buildStatement(stmt);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new AllColumns(Optional.of(SourceName.of("T")))))));
}
Aggregations