use of org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator in project asterixdb by apache.
the class SwitchInnerJoinBranchRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator op = opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
return false;
}
InnerJoinOperator joinOperator = (InnerJoinOperator) op;
Mutable<ILogicalOperator> leftRef = joinOperator.getInputs().get(0);
Mutable<ILogicalOperator> rightRef = joinOperator.getInputs().get(1);
ILogicalOperator left = leftRef.getValue();
ILogicalOperator right = rightRef.getValue();
boolean leftCardinalityOne = OperatorPropertiesUtil.isCardinalityZeroOrOne(left);
boolean rightCardinalityOne = OperatorPropertiesUtil.isCardinalityZeroOrOne(right);
if (!leftCardinalityOne || rightCardinalityOne) {
return false;
}
// The cardinality of the left branch is one and the cardinality of the right branch is not one.
leftRef.setValue(right);
rightRef.setValue(left);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator in project asterixdb by apache.
the class EliminateSubplanRule method elimSubplanOverEts.
private void elimSubplanOverEts(Mutable<ILogicalOperator> opRef, IOptimizationContext ctx) throws AlgebricksException {
SubplanOperator subplan = (SubplanOperator) opRef.getValue();
for (ILogicalPlan p : subplan.getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
OperatorManipulationUtil.ntsToEts(r, ctx);
}
}
LinkedList<Mutable<ILogicalOperator>> allRoots = subplan.allRootsInReverseOrder();
if (allRoots.size() == 1) {
opRef.setValue(allRoots.get(0).getValue());
} else {
ILogicalOperator topOp = null;
for (Mutable<ILogicalOperator> r : allRoots) {
if (topOp == null) {
topOp = r.getValue();
} else {
InnerJoinOperator j = new InnerJoinOperator(new MutableObject<ILogicalExpression>(ConstantExpression.TRUE));
j.getInputs().add(new MutableObject<ILogicalOperator>(topOp));
j.getInputs().add(r);
ctx.setOutputTypeEnvironment(j, j.computeOutputTypeEnvironment(ctx));
topOp = j;
}
}
opRef.setValue(topOp);
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator in project asterixdb by apache.
the class PushGroupByThroughProduct method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) {
return false;
}
Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
return false;
}
InnerJoinOperator join = (InnerJoinOperator) op2;
if (!OperatorPropertiesUtil.isAlwaysTrueCond(join.getCondition().getValue())) {
// not a product
return false;
}
GroupByOperator gby = (GroupByOperator) op1;
List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorToPush = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorNotToPush = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
Mutable<ILogicalOperator> opLeftRef = join.getInputs().get(0);
ILogicalOperator opLeft = opLeftRef.getValue();
switch(canPushThrough(gby, opLeft, decorToPush, decorNotToPush)) {
case REPEATED_DECORS:
{
return false;
}
case TRUE:
{
push(opRef, opRef2, 0, decorToPush, decorNotToPush, context);
return true;
}
case FALSE:
{
decorToPush.clear();
Mutable<ILogicalOperator> opRightRef = join.getInputs().get(1);
ILogicalOperator opRight = opRightRef.getValue();
if (canPushThrough(gby, opRight, decorToPush, decorNotToPush) == PushTestResult.TRUE) {
push(opRef, opRef2, 1, decorToPush, decorNotToPush, context);
return true;
} else {
return false;
}
}
default:
{
throw new IllegalStateException();
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator in project asterixdb by apache.
the class PushProperJoinThroughProduct method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
LogicalOperatorTag tag1 = op.getOperatorTag();
if (tag1 != LogicalOperatorTag.INNERJOIN && tag1 != LogicalOperatorTag.LEFTOUTERJOIN) {
return false;
}
AbstractBinaryJoinOperator join1 = (AbstractBinaryJoinOperator) op;
ILogicalExpression cond1 = join1.getCondition().getValue();
// don't try to push a product down
if (OperatorPropertiesUtil.isAlwaysTrueCond(cond1)) {
return false;
}
Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
while (op2.isMap()) {
opRef2 = op2.getInputs().get(0);
op2 = (AbstractLogicalOperator) opRef2.getValue();
}
if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
return false;
}
InnerJoinOperator product = (InnerJoinOperator) op2;
if (!OperatorPropertiesUtil.isAlwaysTrueCond(product.getCondition().getValue())) {
return false;
}
usedInCond1AndMaps.clear();
cond1.getUsedVariables(usedInCond1AndMaps);
Mutable<ILogicalOperator> opIterRef = op.getInputs().get(0);
ILogicalOperator opIter = opIterRef.getValue();
do {
VariableUtilities.getUsedVariables(opIter, usedInCond1AndMaps);
opIterRef = opIter.getInputs().get(0);
opIter = opIterRef.getValue();
} while (opIter.isMap());
productLeftBranchVars.clear();
ILogicalOperator opLeft = op2.getInputs().get(0).getValue();
VariableUtilities.getLiveVariables(opLeft, productLeftBranchVars);
if (!OperatorPropertiesUtil.disjoint(usedInCond1AndMaps, productLeftBranchVars)) {
return false;
}
// now push the operators from in between joins, too
opIterRef = op.getInputs().get(0);
opIter = opIterRef.getValue();
Mutable<ILogicalOperator> op3Ref = product.getInputs().get(1);
ILogicalOperator op3 = op3Ref.getValue();
opRef2.setValue(op3);
op3Ref.setValue(join1);
opRef.setValue(product);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator in project asterixdb by apache.
the class AqlPlusExpressionToPlanTranslator method visitJoinClause.
@Override
public Pair<ILogicalOperator, LogicalVariable> visitJoinClause(JoinClause jc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
Mutable<ILogicalOperator> opRef = tupSource;
Pair<ILogicalOperator, LogicalVariable> leftSide = null;
for (Clause c : jc.getLeftClauses()) {
leftSide = c.accept(this, opRef);
opRef = new MutableObject<ILogicalOperator>(leftSide.first);
}
opRef = tupSource;
Pair<ILogicalOperator, LogicalVariable> rightSide = null;
for (Clause c : jc.getRightClauses()) {
rightSide = c.accept(this, opRef);
opRef = new MutableObject<ILogicalOperator>(rightSide.first);
}
Pair<ILogicalExpression, Mutable<ILogicalOperator>> whereCond = langExprToAlgExpression(jc.getWhereExpr(), tupSource);
AbstractBinaryJoinOperator join;
switch(jc.getKind()) {
case INNER:
join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
break;
case LEFT_OUTER:
join = new LeftOuterJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_AQLPLUS_NO_SUCH_JOIN_TYPE);
}
join.getInputs().add(new MutableObject<ILogicalOperator>(leftSide.first));
join.getInputs().add(new MutableObject<ILogicalOperator>(rightSide.first));
return new Pair<ILogicalOperator, LogicalVariable>(join, null);
}
Aggregations