use of org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass in project asterixdb by apache.
the class FDsAndEquivClassesVisitor method visitNestedTupleSourceOperator.
@Override
public Void visitNestedTupleSourceOperator(NestedTupleSourceOperator op, IOptimizationContext ctx) throws AlgebricksException {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) op.getDataSourceReference().getValue();
ILogicalOperator inp1 = op1.getInputs().get(0).getValue();
Map<LogicalVariable, EquivalenceClass> eqClasses = getOrComputeEqClasses(inp1, ctx);
ctx.putEquivalenceClassMap(op, eqClasses);
List<FunctionalDependency> fds = new ArrayList<FunctionalDependency>(getOrComputeFDs(inp1, ctx));
if (op1.getOperatorTag() == LogicalOperatorTag.GROUP) {
GroupByOperator gby = (GroupByOperator) op1;
LinkedList<LogicalVariable> tail = new LinkedList<LogicalVariable>();
for (LogicalVariable v : gby.getGbyVarList()) {
tail.add(v);
// all values for gby vars. are the same
}
FunctionalDependency gbyfd = new FunctionalDependency(new LinkedList<LogicalVariable>(), tail);
fds.add(gbyfd);
}
ctx.putFDList(op, fds);
return null;
}
use of org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass in project asterixdb by apache.
the class FDsAndEquivClassesVisitor method visitSelectOperator.
@Override
public Void visitSelectOperator(SelectOperator op, IOptimizationContext ctx) throws AlgebricksException {
ILogicalOperator childOp = op.getInputs().get(0).getValue();
Map<LogicalVariable, EquivalenceClass> equivalenceClasses = getOrComputeEqClasses(childOp, ctx);
ctx.putEquivalenceClassMap(op, equivalenceClasses);
List<FunctionalDependency> functionalDependencies = new ArrayList<FunctionalDependency>();
ctx.putFDList(op, functionalDependencies);
functionalDependencies.addAll(getOrComputeFDs(childOp, ctx));
equivalenceClasses.putAll(getOrComputeEqClasses(childOp, ctx));
ILogicalExpression expr = op.getCondition().getValue();
expr.getConstraintsAndEquivClasses(functionalDependencies, equivalenceClasses);
return null;
}
use of org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass in project asterixdb by apache.
the class FDsAndEquivClassesVisitor method propagateFDsAndEquivClasses.
private void propagateFDsAndEquivClasses(ILogicalOperator op, IOptimizationContext ctx) throws AlgebricksException {
ILogicalOperator inp1 = op.getInputs().get(0).getValue();
Map<LogicalVariable, EquivalenceClass> eqClasses = getOrComputeEqClasses(inp1, ctx);
ctx.putEquivalenceClassMap(op, eqClasses);
List<FunctionalDependency> fds = getOrComputeFDs(inp1, ctx);
ctx.putFDList(op, fds);
}
use of org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass in project asterixdb by apache.
the class FDsAndEquivClassesVisitor method fdsEqClassesForAbstractUnnestOperator.
private void fdsEqClassesForAbstractUnnestOperator(AbstractUnnestOperator op, IOptimizationContext ctx) throws AlgebricksException {
ILogicalOperator inp1 = op.getInputs().get(0).getValue();
Map<LogicalVariable, EquivalenceClass> eqClasses = getOrCreateEqClasses(op, ctx);
Map<LogicalVariable, EquivalenceClass> propagatedEqClasses = getOrComputeEqClasses(inp1, ctx);
/**
* The original eq classes of unnest-map are only for produced
* variables, therefore eqClasses and propagatedEqClasses do not have
* overlaps.
*/
eqClasses.putAll(propagatedEqClasses);
ctx.putEquivalenceClassMap(op, eqClasses);
List<FunctionalDependency> fds = getOrComputeFDs(inp1, ctx);
ctx.putFDList(op, fds);
ILogicalExpression expr = op.getExpressionRef().getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
AbstractFunctionCallExpression afe = (AbstractFunctionCallExpression) expr;
if (afe.getKind() == FunctionKind.UNNEST && ((UnnestingFunctionCallExpression) afe).returnsUniqueValues()) {
List<LogicalVariable> vars = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(op, vars);
ArrayList<LogicalVariable> h = new ArrayList<LogicalVariable>();
h.addAll(op.getVariables());
FunctionalDependency fd = new FunctionalDependency(h, vars);
fds.add(fd);
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass in project asterixdb by apache.
the class LocalOrderProperty method normalizeOrderingColumns.
// Gets normalized ordering columns, where each column variable is a representative variable of its equivalence
// class, therefore, the matching of properties will can consider equivalence classes.
private List<OrderColumn> normalizeOrderingColumns(List<OrderColumn> inputOrderColumns, Map<LogicalVariable, EquivalenceClass> equivalenceClasses) {
List<OrderColumn> newOrderColumns = new ArrayList<>();
if (equivalenceClasses == null || equivalenceClasses.isEmpty()) {
newOrderColumns.addAll(inputOrderColumns);
return newOrderColumns;
}
for (OrderColumn oc : inputOrderColumns) {
LogicalVariable v = oc.getColumn();
EquivalenceClass ec = equivalenceClasses.get(v);
if (ec == null) {
newOrderColumns.add(new OrderColumn(v, oc.getOrder()));
} else {
if (ec.representativeIsConst()) {
// trivially satisfied, so the var. can be removed
} else {
newOrderColumns.add(new OrderColumn(ec.getVariableRepresentative(), oc.getOrder()));
}
}
}
return newOrderColumns;
}
Aggregations