use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator 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.AbstractBinaryJoinOperator in project asterixdb by apache.
the class RemoveUnusedOneToOneEquiJoinRule method removeUnusedJoin.
private boolean removeUnusedJoin(Mutable<ILogicalOperator> opRef) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
boolean modified = false;
usedVars.clear();
VariableUtilities.getUsedVariables(op, usedVars);
// Propagate used variables from parents downwards.
parentsUsedVars.addAll(usedVars);
int numInputs = op.getInputs().size();
for (int i = 0; i < numInputs; i++) {
Mutable<ILogicalOperator> childOpRef = op.getInputs().get(i);
int unusedJoinBranchIndex = removeJoinFromInputBranch(childOpRef);
if (unusedJoinBranchIndex >= 0) {
int usedBranchIndex = (unusedJoinBranchIndex == 0) ? 1 : 0;
// Remove join at input index i, by hooking up op's input i with
// the join's branch at unusedJoinBranchIndex.
AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) childOpRef.getValue();
op.getInputs().set(i, joinOp.getInputs().get(usedBranchIndex));
modified = true;
}
// Descend into children.
if (removeUnusedJoin(childOpRef)) {
modified = true;
}
}
return modified;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator in project asterixdb by apache.
the class NestedLoopJoinPOperator method contributeRuntimeOperator.
@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op;
RecordDescriptor recDescriptor = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), propagatedSchema, context);
IOperatorSchema[] conditionInputSchemas = new IOperatorSchema[1];
conditionInputSchemas[0] = propagatedSchema;
IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider();
IScalarEvaluatorFactory cond = expressionRuntimeProvider.createEvaluatorFactory(join.getCondition().getValue(), context.getTypeEnvironment(op), conditionInputSchemas, context);
ITuplePairComparatorFactory comparatorFactory = new TuplePairEvaluatorFactory(cond, context.getBinaryBooleanInspectorFactory());
IOperatorDescriptorRegistry spec = builder.getJobSpec();
IOperatorDescriptor opDesc = null;
switch(kind) {
case INNER:
{
opDesc = new NestedLoopJoinOperatorDescriptor(spec, comparatorFactory, recDescriptor, memSize, false, null);
break;
}
case LEFT_OUTER:
{
IMissingWriterFactory[] nonMatchWriterFactories = new IMissingWriterFactory[inputSchemas[1].getSize()];
for (int j = 0; j < nonMatchWriterFactories.length; j++) {
nonMatchWriterFactories[j] = context.getMissingWriterFactory();
}
opDesc = new NestedLoopJoinOperatorDescriptor(spec, comparatorFactory, recDescriptor, memSize, true, nonMatchWriterFactories);
break;
}
default:
{
throw new NotImplementedException();
}
}
contributeOpDesc(builder, (AbstractLogicalOperator) op, opDesc);
ILogicalOperator src1 = op.getInputs().get(0).getValue();
builder.contributeGraphEdge(src1, 0, op, 0);
ILogicalOperator src2 = op.getInputs().get(1).getValue();
builder.contributeGraphEdge(src2, 0, op, 1);
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator in project asterixdb by apache.
the class PushAggFuncIntoStandaloneAggregateRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
// Pattern to match: assign <-- aggregate <-- !(group-by)
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
return false;
}
AssignOperator assignOp = (AssignOperator) op;
Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
if (op2.getOperatorTag() == LogicalOperatorTag.AGGREGATE) {
AggregateOperator aggOp = (AggregateOperator) op2;
// Make sure the agg expr is a listify.
return pushAggregateFunction(aggOp, assignOp, context);
} else if (op2.getOperatorTag() == LogicalOperatorTag.INNERJOIN || op2.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN) {
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op2;
// Tries to push aggregates through the join.
if (containsAggregate(assignOp.getExpressions()) && pushableThroughJoin(join)) {
pushAggregateFunctionThroughJoin(join, assignOp, context);
return true;
}
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator in project asterixdb by apache.
the class ExtractFunctionsFromJoinConditionRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN && op.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
return false;
}
AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) op;
ILogicalExpression expr = joinOp.getCondition().getValue();
return assignFunctionExpressions(joinOp, expr, context);
}
Aggregations