use of io.confluent.ksql.physical.pull.operators.LimitOperator 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);
}
Aggregations