use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class CancelUnnestWithNestedListifyRule method applyRuleDown.
private boolean applyRuleDown(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> varSet, IOptimizationContext context) throws AlgebricksException {
boolean changed = applies(opRef, varSet, context);
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
VariableUtilities.getUsedVariables(op, varSet);
if (op.hasNestedPlans()) {
AbstractOperatorWithNestedPlans aonp = (AbstractOperatorWithNestedPlans) op;
for (ILogicalPlan p : aonp.getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
if (applyRuleDown(r, varSet, context)) {
changed = true;
}
context.addToDontApplySet(this, r.getValue());
}
}
}
for (Mutable<ILogicalOperator> i : op.getInputs()) {
if (applyRuleDown(i, varSet, context)) {
changed = true;
}
context.addToDontApplySet(this, i.getValue());
}
return changed;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class CountVarToCountOneRule method rewritePost.
// It is only for a group-by having just one aggregate which is a count.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) {
return false;
}
GroupByOperator g = (GroupByOperator) op1;
if (g.getNestedPlans().size() != 1) {
return false;
}
ILogicalPlan p = g.getNestedPlans().get(0);
if (p.getRoots().size() != 1) {
return false;
}
AbstractLogicalOperator op2 = (AbstractLogicalOperator) p.getRoots().get(0).getValue();
if (op2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
return false;
}
AggregateOperator agg = (AggregateOperator) op2;
if (agg.getExpressions().size() != 1) {
return false;
}
ILogicalExpression exp2 = agg.getExpressions().get(0).getValue();
if (exp2.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression fun = (AbstractFunctionCallExpression) exp2;
if (fun.getFunctionIdentifier() != BuiltinFunctions.COUNT) {
return false;
}
ILogicalExpression exp3 = fun.getArguments().get(0).getValue();
if (exp3.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
return false;
}
if (((AbstractLogicalOperator) agg.getInputs().get(0).getValue()).getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {
return false;
}
fun.getArguments().get(0).setValue(new ConstantExpression(new AsterixConstantValue(new AInt64(1L))));
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class FuzzyEqRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
// current operator is INNERJOIN or LEFTOUTERJOIN or SELECT
Mutable<ILogicalExpression> expRef;
if (op.getOperatorTag() == LogicalOperatorTag.INNERJOIN || op.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN) {
AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) op;
expRef = joinOp.getCondition();
} else if (op.getOperatorTag() == LogicalOperatorTag.SELECT) {
SelectOperator selectOp = (SelectOperator) op;
expRef = selectOp.getCondition();
} else {
return false;
}
MetadataProvider metadataProvider = ((MetadataProvider) context.getMetadataProvider());
IVariableTypeEnvironment env = context.getOutputTypeEnvironment(op);
if (expandFuzzyEq(expRef, context, env, metadataProvider)) {
context.computeAndSetTypeEnvironmentForOperator(op);
return true;
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class OperatorPropertiesUtil method collectUsedAndProducedVariablesInPath.
/**
* @param op
* , the start operator.
* @param dest
* , the destination operator (a direct/indirect input operator).
* @param usedVars
* , the collection of used variables.
* @param producedVars
* , the collection of produced variables.
* @return if the current operator is on the path from the original start operator to the destination operator.
* @throws AlgebricksException
*/
private static boolean collectUsedAndProducedVariablesInPath(ILogicalOperator op, ILogicalOperator dest, Set<LogicalVariable> usedVars, Set<LogicalVariable> producedVars) throws AlgebricksException {
if (op == dest) {
return true;
}
if (((AbstractLogicalOperator) op).hasNestedPlans()) {
AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
for (ILogicalPlan p : a.getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
if (collectUsedAndProducedVariablesInPath(r.getValue(), dest, usedVars, producedVars)) {
VariableUtilities.getUsedVariables(r.getValue(), usedVars);
VariableUtilities.getProducedVariables(r.getValue(), producedVars);
return true;
}
}
}
}
for (Mutable<ILogicalOperator> childRef : op.getInputs()) {
if (collectUsedAndProducedVariablesInPath(childRef.getValue(), dest, usedVars, producedVars)) {
VariableUtilities.getUsedVariables(op, usedVars);
VariableUtilities.getProducedVariables(op, producedVars);
return true;
}
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class JobBuilder method contributeMicroOperator.
@Override
public void contributeMicroOperator(ILogicalOperator op, IPushRuntimeFactory runtime, RecordDescriptor recDesc, AlgebricksPartitionConstraint pc) {
microOps.put(op, new Pair<IPushRuntimeFactory, RecordDescriptor>(runtime, recDesc));
revMicroOpMap.put(runtime, op);
if (pc != null) {
pcForMicroOps.put(op, pc);
}
AbstractLogicalOperator logicalOp = (AbstractLogicalOperator) op;
if (logicalOp.getExecutionMode() == ExecutionMode.UNPARTITIONED && pc == null) {
AlgebricksPartitionConstraint apc = countOneLocation;
pcForMicroOps.put(logicalOp, apc);
}
}
Aggregations