use of org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency 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.properties.FunctionalDependency 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.properties.FunctionalDependency in project asterixdb by apache.
the class LogicalOperatorDeepCopyWithNewVariablesVisitor method updatePrimaryKeys.
public void updatePrimaryKeys(IOptimizationContext context) {
for (Map.Entry<LogicalVariable, LogicalVariable> entry : inputVarToOutputVarMapping.entrySet()) {
List<LogicalVariable> primaryKey = context.findPrimaryKey(entry.getKey());
if (primaryKey != null) {
List<LogicalVariable> head = new ArrayList<LogicalVariable>();
for (LogicalVariable variable : primaryKey) {
head.add(inputVarToOutputVarMapping.get(variable));
}
List<LogicalVariable> tail = new ArrayList<LogicalVariable>(1);
tail.add(entry.getValue());
context.addPrimaryKey(new FunctionalDependency(head, tail));
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency in project asterixdb by apache.
the class IntroduceGroupByForSubplanRule method computeGbyVars.
protected Set<LogicalVariable> computeGbyVars(AbstractLogicalOperator op, Set<LogicalVariable> freeVars, IOptimizationContext context) throws AlgebricksException {
PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(op, context);
List<FunctionalDependency> fdList = context.getFDList(op);
if (fdList == null) {
return null;
}
// check if any of the FDs is a key
List<LogicalVariable> all = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(op, all);
all.retainAll(freeVars);
for (FunctionalDependency fd : fdList) {
if (fd.getTail().containsAll(all)) {
return new HashSet<LogicalVariable>(fd.getHead());
}
}
return null;
}
use of org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency in project asterixdb by apache.
the class InlineAllNtsInSubplanVisitor method addPrimaryKeys.
private void addPrimaryKeys(Map<LogicalVariable, LogicalVariable> varMap) {
for (Entry<LogicalVariable, LogicalVariable> entry : varMap.entrySet()) {
List<LogicalVariable> dependencyVars = context.findPrimaryKey(entry.getKey());
if (dependencyVars == null) {
// No key dependencies
continue;
}
List<LogicalVariable> newDependencies = new ArrayList<>();
for (LogicalVariable dependencyVar : dependencyVars) {
LogicalVariable newDependencyVar = varMap.get(dependencyVar);
if (newDependencyVar == null) {
continue;
}
newDependencies.add(newDependencyVar);
}
context.addPrimaryKey(new FunctionalDependency(newDependencies, Collections.singletonList(entry.getValue())));
}
}
Aggregations