use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.
the class LocalGroupingProperty method retainVariables.
@Override
public ILocalStructuralProperty retainVariables(Collection<LogicalVariable> vars) {
Set<LogicalVariable> newVars = new ListSet<>();
newVars.addAll(vars);
newVars.retainAll(columnSet);
if (columnSet.equals(newVars)) {
return new LocalGroupingProperty(columnSet, preferredOrderEnforcer);
}
// Column set for the retained grouping property
Set<LogicalVariable> newColumns = new ListSet<>();
// Matches the prefix of the original column set.
for (LogicalVariable v : columnSet) {
if (newVars.contains(v)) {
newColumns.add(v);
} else {
break;
}
}
return createNewLocalGroupingProperty(newColumns);
}
use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.
the class PropertiesUtil method closureUnderFDs.
public Set<LogicalVariable> closureUnderFDs(Collection<LogicalVariable> vars, List<FunctionalDependency> fdList) {
Set<LogicalVariable> k = new ListSet<>(vars);
boolean change;
do {
change = false;
for (FunctionalDependency fd : fdList) {
List<LogicalVariable> h = fd.getHead();
if (!k.containsAll(h)) {
continue;
}
List<LogicalVariable> t = fd.getTail();
for (LogicalVariable v : t) {
if (!(k.contains(v))) {
k.add(v);
change = true;
}
}
}
} while (change);
return k;
}
use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.
the class EliminateSubplanWithInputCardinalityOneRule method rewritePre.
@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
if (!invoked) {
rootRef = opRef;
invoked = true;
}
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getInputs().size() <= 0) {
return false;
}
boolean changed = false;
for (Mutable<ILogicalOperator> subplanRef : op.getInputs()) {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) subplanRef.getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
continue;
}
SubplanOperator subplan = (SubplanOperator) op1;
Set<LogicalVariable> usedVarsUp = new ListSet<LogicalVariable>();
OperatorPropertiesUtil.getFreeVariablesInPath(rootRef.getValue(), subplan, usedVarsUp);
// TODO(buyingyi): figure out the rewriting for subplan operators with multiple subplans.
if (subplan.getNestedPlans().size() != 1) {
continue;
}
ILogicalOperator subplanInputOperator = subplan.getInputs().get(0).getValue();
Set<LogicalVariable> subplanInputVars = new ListSet<LogicalVariable>();
VariableUtilities.getLiveVariables(subplanInputOperator, subplanInputVars);
int subplanInputVarSize = subplanInputVars.size();
subplanInputVars.removeAll(usedVarsUp);
// Makes sure the free variables are only used in the subplan.
if (subplanInputVars.size() < subplanInputVarSize) {
continue;
}
Set<LogicalVariable> freeVars = new ListSet<LogicalVariable>();
OperatorPropertiesUtil.getFreeVariablesInSubplans(subplan, freeVars);
boolean cardinalityOne = isCardinalityOne(subplan.getInputs().get(0), freeVars);
if (cardinalityOne) {
/** If the cardinality of freeVars in the subplan is one, the subplan can be removed. */
ILogicalPlan plan = subplan.getNestedPlans().get(0);
List<Mutable<ILogicalOperator>> rootRefs = plan.getRoots();
// TODO(buyingyi): investigate the case of multi-root plans.
if (rootRefs.size() != 1) {
continue;
}
// Replaces all Nts' in the nested plan with the Subplan input operator or its deep copy.
ILogicalOperator topOperator = rootRefs.get(0).getValue();
ReplaceNtsWithSubplanInputOperatorVisitor visitor = new ReplaceNtsWithSubplanInputOperatorVisitor(context, subplan);
ILogicalOperator newTopOperator = topOperator.accept(visitor, null);
subplanRef.setValue(newTopOperator);
OperatorManipulationUtil.computeTypeEnvironmentBottomUp(newTopOperator, context);
changed = true;
} else {
continue;
}
}
return changed;
}
use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.
the class DataSourcePartitioningProvider method getFeedPartitioningProperty.
public static IPartitioningProperty getFeedPartitioningProperty(DataSource ds, INodeDomain domain, List<LogicalVariable> scanVariables) {
IPartitioningProperty pp;
if (scanVariables.size() < 2) {
pp = new RandomPartitioningProperty(domain);
} else {
Set<LogicalVariable> pvars = new ListSet<>();
pvars.addAll(ds.getPrimaryKeyVariables(scanVariables));
pp = new UnorderedPartitionedProperty(pvars, domain);
}
return pp;
}
use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.
the class JoinMultiComparator method deliveredLocalProperties.
@Override
protected List<ILocalStructuralProperty> deliveredLocalProperties(ILogicalOperator op, IOptimizationContext context) throws AlgebricksException {
List<ILocalStructuralProperty> deliveredLocalProperties = new ArrayList<>();
// Inner join can kick off the "role reversal" optimization, which can kill data properties for the probe side.
if (kind != JoinKind.LEFT_OUTER) {
return deliveredLocalProperties;
}
AbstractLogicalOperator probeOp = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
IPhysicalPropertiesVector probeSideProperties = probeOp.getPhysicalOperator().getDeliveredProperties();
List<ILocalStructuralProperty> probeSideLocalProperties = probeSideProperties.getLocalProperties();
if (probeSideLocalProperties != null) {
// is destroyed.
for (ILocalStructuralProperty property : probeSideLocalProperties) {
Set<LogicalVariable> groupingVars = new ListSet<>();
Set<LogicalVariable> leftBranchVars = new ListSet<>();
property.getVariables(groupingVars);
leftBranchVars.addAll(getKeysLeftBranch());
if (groupingVars.containsAll(leftBranchVars)) {
deliveredLocalProperties.add(new LocalGroupingProperty(groupingVars));
}
}
}
return deliveredLocalProperties;
}
Aggregations