use of io.confluent.ksql.parser.tree.AliasedRelation in project ksql by confluentinc.
the class KsqlParserTest method testSelectTumblingWindow.
@Test
public void testSelectTumblingWindow() throws Exception {
String queryStr = "select itemid, sum(orderunits) from orders window TUMBLING ( size 30 second) where orderunits > 5 group by itemid;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testSelectTumblingWindow failed.", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testSelectTumblingWindow failed.", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
Assert.assertTrue("testCreateTable failed.", querySpecification.getSelect().getSelectItems().size() == 2);
Assert.assertTrue("testSelectTumblingWindow failed.", querySpecification.getWhere().get().toString().equalsIgnoreCase("(ORDERS.ORDERUNITS > 5)"));
Assert.assertTrue("testSelectTumblingWindow failed.", ((AliasedRelation) querySpecification.getFrom()).getAlias().equalsIgnoreCase("ORDERS"));
Assert.assertTrue("testSelectTumblingWindow failed.", querySpecification.getWindowExpression().isPresent());
Assert.assertTrue("testSelectTumblingWindow failed.", querySpecification.getWindowExpression().get().toString().equalsIgnoreCase(" WINDOW STREAMWINDOW TUMBLING ( SIZE 30 SECONDS ) "));
}
use of io.confluent.ksql.parser.tree.AliasedRelation in project ksql by confluentinc.
the class DataSourceExtractor method visitJoinRelation.
@Override
public Node visitJoinRelation(final SqlBaseParser.JoinRelationContext context) {
this.isJoin = true;
AliasedRelation left = (AliasedRelation) visit(context.left);
AliasedRelation right;
if (context.CROSS() != null) {
right = (AliasedRelation) visit(context.right);
} else {
if (context.NATURAL() != null) {
right = (AliasedRelation) visit(context.right);
} else {
right = (AliasedRelation) visit(context.rightRelation);
}
}
this.leftAlias = left.getAlias();
StructuredDataSource leftDataSource = metaStore.getSource(((Table) left.getRelation()).getName().getSuffix());
if (leftDataSource == null) {
throw new KsqlException(((Table) left.getRelation()).getName().getSuffix() + " does not " + "exist.");
}
this.joinLeftSchema = leftDataSource.getSchema();
this.rightAlias = right.getAlias();
StructuredDataSource rightDataSource = metaStore.getSource(((Table) right.getRelation()).getName().getSuffix());
if (rightDataSource == null) {
throw new KsqlException(((Table) right.getRelation()).getName().getSuffix() + " does not " + "exist.");
}
this.joinRightSchema = rightDataSource.getSchema();
return null;
}
Aggregations