Search in sources :

Example 11 with AliasedRelation

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 ) "));
}
Also used : QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) Query(io.confluent.ksql.parser.tree.Query) Statement(io.confluent.ksql.parser.tree.Statement) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation) Test(org.junit.Test)

Example 12 with AliasedRelation

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;
}
Also used : StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) Table(io.confluent.ksql.parser.tree.Table) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation)

Aggregations

AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)12 QuerySpecification (io.confluent.ksql.parser.tree.QuerySpecification)7 Statement (io.confluent.ksql.parser.tree.Statement)7 Test (org.junit.Test)7 Query (io.confluent.ksql.parser.tree.Query)6 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)4 Join (io.confluent.ksql.parser.tree.Join)4 Table (io.confluent.ksql.parser.tree.Table)4 CreateTable (io.confluent.ksql.parser.tree.CreateTable)2 DropTable (io.confluent.ksql.parser.tree.DropTable)2 AllColumns (io.confluent.ksql.parser.tree.AllColumns)1 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)1 CreateStreamAsSelect (io.confluent.ksql.parser.tree.CreateStreamAsSelect)1 JoinOn (io.confluent.ksql.parser.tree.JoinOn)1 NaturalJoin (io.confluent.ksql.parser.tree.NaturalJoin)1 QualifiedNameReference (io.confluent.ksql.parser.tree.QualifiedNameReference)1 Relation (io.confluent.ksql.parser.tree.Relation)1 SelectItem (io.confluent.ksql.parser.tree.SelectItem)1 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)1 JoinNode (io.confluent.ksql.planner.plan.JoinNode)1