Search in sources :

Example 1 with QueryFilterNode

use of io.confluent.ksql.planner.plan.QueryFilterNode in project ksql by confluentinc.

the class LogicalPlanner method buildQueryLogicalPlan.

public OutputNode buildQueryLogicalPlan(final QueryPlannerOptions queryPlannerOptions, final boolean isScalablePush) {
    final boolean isWindowed = analysis.getFrom().getDataSource().getKsqlTopic().getKeyFormat().isWindowed();
    PlanNode currentNode = buildSourceNode(isWindowed);
    if (analysis.getWhereExpression().isPresent()) {
        final Expression whereExpression = analysis.getWhereExpression().get();
        final FilterTypeValidator validator = new FilterTypeValidator(currentNode.getSchema(), metaStore, FilterType.WHERE);
        validator.validateFilterExpression(whereExpression);
        currentNode = new QueryFilterNode(new PlanNodeId("WhereFilter"), currentNode, whereExpression, metaStore, ksqlConfig, isWindowed, queryPlannerOptions);
    } else {
        if (!queryPlannerOptions.getTableScansEnabled()) {
            throw QueryFilterNode.invalidWhereClauseException("Missing WHERE clause", isWindowed);
        }
    }
    if (!isScalablePush && analysis.getLimitClause().isPresent()) {
        currentNode = buildLimitNode(currentNode, analysis.getLimitClause().getAsInt());
    }
    currentNode = new QueryProjectNode(new PlanNodeId("Project"), currentNode, analysis.getSelectItems(), metaStore, ksqlConfig, analysis, isWindowed, queryPlannerOptions, isScalablePush);
    return buildOutputNode(currentNode);
}
Also used : PlanNodeId(io.confluent.ksql.planner.plan.PlanNodeId) QueryProjectNode(io.confluent.ksql.planner.plan.QueryProjectNode) SingleSourcePlanNode(io.confluent.ksql.planner.plan.SingleSourcePlanNode) PlanNode(io.confluent.ksql.planner.plan.PlanNode) Expression(io.confluent.ksql.execution.expression.tree.Expression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) FilterTypeValidator(io.confluent.ksql.analyzer.FilterTypeValidator) QueryFilterNode(io.confluent.ksql.planner.plan.QueryFilterNode)

Example 2 with QueryFilterNode

use of io.confluent.ksql.planner.plan.QueryFilterNode in project ksql by confluentinc.

the class PullPhysicalPlanBuilder method buildPullPhysicalPlan.

/**
 * Visits the logical plan top-down to build the physical plan.
 * @param logicalPlanNode the logical plan root node
 * @return the root node of the tree of physical operators
 */
// CHECKSTYLE_RULES.OFF: CyclomaticComplexity
public PullPhysicalPlan buildPullPhysicalPlan(final LogicalPlanNode logicalPlanNode) {
    // CHECKSTYLE_RULES.ON: CyclomaticComplexity
    DataSourceOperator dataSourceOperator = null;
    final OutputNode outputNode = logicalPlanNode.getNode().orElseThrow(() -> new IllegalArgumentException("Need an output node to build a plan"));
    if (!(outputNode instanceof KsqlBareOutputNode)) {
        throw new KsqlException("Pull queries expect the root of the logical plan to be a " + "KsqlBareOutputNode.");
    }
    // We skip KsqlBareOutputNode in the translation since it only applies the LIMIT
    PlanNode currentLogicalNode = outputNode.getSource();
    AbstractPhysicalOperator prevPhysicalOp = null;
    AbstractPhysicalOperator rootPhysicalOp = null;
    while (true) {
        AbstractPhysicalOperator currentPhysicalOp = null;
        if (currentLogicalNode instanceof QueryProjectNode) {
            currentPhysicalOp = translateProjectNode((QueryProjectNode) currentLogicalNode);
        } else if (currentLogicalNode instanceof QueryFilterNode) {
            currentPhysicalOp = translateFilterNode((QueryFilterNode) currentLogicalNode);
            seenSelectOperator = true;
        } else if (currentLogicalNode instanceof QueryLimitNode) {
            currentPhysicalOp = new LimitOperator((QueryLimitNode) currentLogicalNode);
        } else if (currentLogicalNode instanceof DataSourceNode) {
            currentPhysicalOp = translateDataSourceNode((DataSourceNode) currentLogicalNode);
            dataSourceOperator = (DataSourceOperator) currentPhysicalOp;
        } else {
            throw new KsqlException(String.format("Error in translating logical to physical plan for pull queries: unrecognized logical" + " node %s.", currentLogicalNode));
        }
        if (prevPhysicalOp == null) {
            rootPhysicalOp = currentPhysicalOp;
        } else {
            prevPhysicalOp.addChild(currentPhysicalOp);
        }
        prevPhysicalOp = currentPhysicalOp;
        // Exit the loop when a leaf node is reached
        if (currentLogicalNode.getSources().isEmpty()) {
            break;
        }
        if (currentLogicalNode.getSources().size() > 1) {
            throw new KsqlException("Pull queries do not support joins or nested sub-queries yet.");
        }
        currentLogicalNode = currentLogicalNode.getSources().get(0);
    }
    if (dataSourceOperator == null) {
        throw new IllegalStateException("DataSourceOperator cannot be null in Pull physical plan");
    }
    return new PullPhysicalPlan(rootPhysicalOp, (rootPhysicalOp).getLogicalNode().getSchema(), queryId, lookupConstraints, pullPhysicalPlanType, querySourceType, mat, dataSourceOperator);
}
Also used : KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) OutputNode(io.confluent.ksql.planner.plan.OutputNode) DataSourceNode(io.confluent.ksql.planner.plan.DataSourceNode) AbstractPhysicalOperator(io.confluent.ksql.physical.common.operators.AbstractPhysicalOperator) KsqlException(io.confluent.ksql.util.KsqlException) DataSourceOperator(io.confluent.ksql.physical.pull.operators.DataSourceOperator) QueryFilterNode(io.confluent.ksql.planner.plan.QueryFilterNode) QueryLimitNode(io.confluent.ksql.planner.plan.QueryLimitNode) QueryProjectNode(io.confluent.ksql.planner.plan.QueryProjectNode) KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) PlanNode(io.confluent.ksql.planner.plan.PlanNode) LogicalPlanNode(io.confluent.ksql.planner.LogicalPlanNode) LimitOperator(io.confluent.ksql.physical.pull.operators.LimitOperator)

Example 3 with QueryFilterNode

use of io.confluent.ksql.planner.plan.QueryFilterNode in project ksql by confluentinc.

the class PushPhysicalPlanBuilder method buildPushPhysicalPlan.

/**
 * Visits the logical plan top-down to build the physical plan.
 * @param logicalPlanNode the logical plan root node
 * @return the root node of the tree of physical operators
 */
public PushPhysicalPlan buildPushPhysicalPlan(final LogicalPlanNode logicalPlanNode, final Context context, final Optional<PushOffsetRange> offsetRange, final Optional<String> catchupConsumerGroup) {
    final String catchupConsumerGroupId = getConsumerGroupId(catchupConsumerGroup);
    PushDataSourceOperator dataSourceOperator = null;
    final OutputNode outputNode = logicalPlanNode.getNode().orElseThrow(() -> new IllegalArgumentException("Need an output node to build a plan"));
    if (!(outputNode instanceof KsqlBareOutputNode)) {
        throw new KsqlException("Push queries expect the root of the logical plan to be a " + "KsqlBareOutputNode.");
    }
    // We skip KsqlBareOutputNode in the translation since it only applies the LIMIT
    PlanNode currentLogicalNode = outputNode.getSource();
    AbstractPhysicalOperator prevPhysicalOp = null;
    AbstractPhysicalOperator rootPhysicalOp = null;
    while (true) {
        AbstractPhysicalOperator currentPhysicalOp = null;
        if (currentLogicalNode instanceof QueryProjectNode) {
            currentPhysicalOp = translateProjectNode((QueryProjectNode) currentLogicalNode);
        } else if (currentLogicalNode instanceof QueryFilterNode) {
            currentPhysicalOp = translateFilterNode((QueryFilterNode) currentLogicalNode);
        } else if (currentLogicalNode instanceof DataSourceNode) {
            currentPhysicalOp = translateDataSourceNode((DataSourceNode) currentLogicalNode, offsetRange, catchupConsumerGroupId);
            dataSourceOperator = (PushDataSourceOperator) currentPhysicalOp;
        } else {
            throw new KsqlException(String.format("Error in translating logical to physical plan for scalable push queries:" + " unrecognized logical node %s.", currentLogicalNode));
        }
        if (prevPhysicalOp == null) {
            rootPhysicalOp = currentPhysicalOp;
        } else {
            prevPhysicalOp.addChild(currentPhysicalOp);
        }
        prevPhysicalOp = currentPhysicalOp;
        // Exit the loop when a leaf node is reached
        if (currentLogicalNode.getSources().isEmpty()) {
            break;
        }
        if (currentLogicalNode.getSources().size() > 1) {
            throw new KsqlException("Push queries do not support joins or nested sub-queries yet.");
        }
        currentLogicalNode = currentLogicalNode.getSources().get(0);
    }
    if (dataSourceOperator == null) {
        throw new IllegalStateException("DataSourceOperator cannot be null in Push physical plan");
    }
    return new PushPhysicalPlan(rootPhysicalOp, (rootPhysicalOp).getLogicalNode().getSchema(), queryId, catchupConsumerGroupId, dataSourceOperator.getScalablePushRegistry(), dataSourceOperator, context, querySourceType);
}
Also used : PushDataSourceOperator(io.confluent.ksql.physical.scalablepush.operators.PushDataSourceOperator) KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) OutputNode(io.confluent.ksql.planner.plan.OutputNode) DataSourceNode(io.confluent.ksql.planner.plan.DataSourceNode) AbstractPhysicalOperator(io.confluent.ksql.physical.common.operators.AbstractPhysicalOperator) KsqlException(io.confluent.ksql.util.KsqlException) QueryFilterNode(io.confluent.ksql.planner.plan.QueryFilterNode) QueryProjectNode(io.confluent.ksql.planner.plan.QueryProjectNode) KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) PlanNode(io.confluent.ksql.planner.plan.PlanNode) LogicalPlanNode(io.confluent.ksql.planner.LogicalPlanNode)

Aggregations

PlanNode (io.confluent.ksql.planner.plan.PlanNode)3 QueryFilterNode (io.confluent.ksql.planner.plan.QueryFilterNode)3 QueryProjectNode (io.confluent.ksql.planner.plan.QueryProjectNode)3 AbstractPhysicalOperator (io.confluent.ksql.physical.common.operators.AbstractPhysicalOperator)2 LogicalPlanNode (io.confluent.ksql.planner.LogicalPlanNode)2 DataSourceNode (io.confluent.ksql.planner.plan.DataSourceNode)2 KsqlBareOutputNode (io.confluent.ksql.planner.plan.KsqlBareOutputNode)2 OutputNode (io.confluent.ksql.planner.plan.OutputNode)2 KsqlException (io.confluent.ksql.util.KsqlException)2 FilterTypeValidator (io.confluent.ksql.analyzer.FilterTypeValidator)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)1 KsqlWindowExpression (io.confluent.ksql.execution.windows.KsqlWindowExpression)1 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)1 DataSourceOperator (io.confluent.ksql.physical.pull.operators.DataSourceOperator)1 LimitOperator (io.confluent.ksql.physical.pull.operators.LimitOperator)1 PushDataSourceOperator (io.confluent.ksql.physical.scalablepush.operators.PushDataSourceOperator)1 PlanNodeId (io.confluent.ksql.planner.plan.PlanNodeId)1 QueryLimitNode (io.confluent.ksql.planner.plan.QueryLimitNode)1 SingleSourcePlanNode (io.confluent.ksql.planner.plan.SingleSourcePlanNode)1