use of org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator in project asterixdb by apache.
the class IntroJoinInsideSubplanRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue();
if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
return false;
}
SubplanOperator subplan = (SubplanOperator) op0;
Mutable<ILogicalOperator> leftRef = subplan.getInputs().get(0);
if (((AbstractLogicalOperator) leftRef.getValue()).getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
return false;
}
ListIterator<ILogicalPlan> plansIter = subplan.getNestedPlans().listIterator();
ILogicalPlan p = null;
while (plansIter.hasNext()) {
p = plansIter.next();
}
if (p == null) {
return false;
}
if (p.getRoots().size() != 1) {
return false;
}
Mutable<ILogicalOperator> opRef1 = p.getRoots().get(0);
while (true) {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef1.getValue();
if (op1.getInputs().size() != 1) {
return false;
}
if (op1.getOperatorTag() == LogicalOperatorTag.SELECT) {
Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();
if (op2.getOperatorTag() != LogicalOperatorTag.SELECT && descOrSelfIsScanOrJoin(op2)) {
Set<LogicalVariable> free2 = new HashSet<LogicalVariable>();
OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op2, free2);
if (free2.isEmpty()) {
Set<LogicalVariable> free1 = new HashSet<LogicalVariable>();
OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op1, free1);
if (!free1.isEmpty()) {
OperatorManipulationUtil.ntsToEts(op2Ref, context);
NestedTupleSourceOperator nts = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(subplan));
Mutable<ILogicalOperator> ntsRef = new MutableObject<ILogicalOperator>(nts);
Mutable<ILogicalOperator> innerRef = new MutableObject<ILogicalOperator>(op2);
InnerJoinOperator join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(ConstantExpression.TRUE), ntsRef, innerRef);
op2Ref.setValue(join);
context.computeAndSetTypeEnvironmentForOperator(nts);
context.computeAndSetTypeEnvironmentForOperator(join);
return true;
}
}
}
}
opRef1 = op1.getInputs().get(0);
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator in project asterixdb by apache.
the class NestedTupleSourcePOperator method computeDeliveredProperties.
@Override
public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) {
Mutable<ILogicalOperator> dataSource = ((NestedTupleSourceOperator) op).getDataSourceReference();
AbstractLogicalOperator op2 = (AbstractLogicalOperator) dataSource.getValue().getInputs().get(0).getValue();
IPhysicalPropertiesVector inheritedProps = op2.getDeliveredPhysicalProperties();
AbstractLogicalOperator parent = (AbstractLogicalOperator) dataSource.getValue();
if (parent.getOperatorTag() != LogicalOperatorTag.GROUP) {
deliveredProperties = inheritedProps.clone();
return;
}
GroupByOperator gby = (GroupByOperator) parent;
List<ILocalStructuralProperty> originalLocalProperties = inheritedProps.getLocalProperties();
List<ILocalStructuralProperty> newLocalProperties = null;
if (originalLocalProperties != null) {
newLocalProperties = new ArrayList<>();
for (ILocalStructuralProperty lsp : originalLocalProperties) {
ILocalStructuralProperty groupLocalLsp = lsp.regardToGroup(gby.getGbyVarList());
if (groupLocalLsp != null) {
// Adds the property that is satisfied in the context of a particular group.
newLocalProperties.add(groupLocalLsp);
}
}
// Adds the original local properties as they are still maintained.
// The optimizer should be able to process multiple delivered local order/grouping properties.
newLocalProperties.addAll(originalLocalProperties);
}
deliveredProperties = new StructuralPropertiesVector(inheritedProps.getPartitioningProperty(), newLocalProperties);
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator in project asterixdb by apache.
the class PhysicalOptimizationsUtil method computeFDsAndEqClassesWithVisitorRec.
private static <R> void computeFDsAndEqClassesWithVisitorRec(ILogicalOperator op, IOptimizationContext ctx, ILogicalOperatorVisitor<R, IOptimizationContext> visitor, Set<ILogicalOperator> visitSet) throws AlgebricksException {
visitSet.add(op);
for (Mutable<ILogicalOperator> i : op.getInputs()) {
computeFDsAndEqClassesWithVisitorRec((AbstractLogicalOperator) i.getValue(), ctx, visitor, visitSet);
}
AbstractLogicalOperator aop = (AbstractLogicalOperator) op;
if (aop.hasNestedPlans()) {
for (ILogicalPlan p : ((AbstractOperatorWithNestedPlans) op).getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
AbstractLogicalOperator rootOp = (AbstractLogicalOperator) r.getValue();
computeFDsAndEqClassesWithVisitorRec(rootOp, ctx, visitor, visitSet);
}
}
}
if (op.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
NestedTupleSourceOperator nts = (NestedTupleSourceOperator) op;
ILogicalOperator source = nts.getDataSourceReference().getValue().getInputs().get(0).getValue();
if (!visitSet.contains(source)) {
computeFDsAndEqClassesWithVisitorRec((AbstractLogicalOperator) source, ctx, visitor, visitSet);
}
}
op.accept(visitor, ctx);
}
Aggregations