use of org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator in project asterixdb by apache.
the class OperatorManipulationUtil method eliminateSingleSubplanOverEts.
public static ILogicalOperator eliminateSingleSubplanOverEts(SubplanOperator subplan) {
if (subplan.getNestedPlans().size() > 1) {
// not a single subplan
List<Mutable<ILogicalOperator>> subInpList = subplan.getInputs();
subInpList.clear();
subInpList.add(new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator()));
return subplan;
}
ILogicalPlan plan = subplan.getNestedPlans().get(0);
if (plan.getRoots().size() > 1) {
// not a single subplan
List<Mutable<ILogicalOperator>> subInpList = subplan.getInputs();
subInpList.clear();
subInpList.add(new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator()));
return subplan;
}
return plan.getRoots().get(0).getValue();
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator in project asterixdb by apache.
the class DisjunctivePredicateToJoinRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider();
if (metadataProvider.isBlockingOperatorDisabled()) {
return false;
}
SelectOperator select;
if ((select = asSelectOperator(opRef)) == null) {
return false;
}
AbstractFunctionCallExpression condEx;
if ((condEx = asFunctionCallExpression(select.getCondition(), AlgebricksBuiltinFunctions.OR)) == null) {
return false;
}
List<Mutable<ILogicalExpression>> args = condEx.getArguments();
VariableReferenceExpression varEx = null;
IAType valType = null;
HashSet<AsterixConstantValue> values = new HashSet<AsterixConstantValue>();
for (Mutable<ILogicalExpression> arg : args) {
AbstractFunctionCallExpression fctCall;
if ((fctCall = asFunctionCallExpression(arg, AlgebricksBuiltinFunctions.EQ)) == null) {
return false;
}
boolean haveConst = false;
boolean haveVar = false;
List<Mutable<ILogicalExpression>> fctArgs = fctCall.getArguments();
for (Mutable<ILogicalExpression> fctArg : fctArgs) {
final ILogicalExpression argExpr = fctArg.getValue();
switch(argExpr.getExpressionTag()) {
case CONSTANT:
haveConst = true;
AsterixConstantValue value = (AsterixConstantValue) ((ConstantExpression) argExpr).getValue();
if (valType == null) {
valType = value.getObject().getType();
} else if (!isCompatible(valType, value.getObject().getType())) {
return false;
}
values.add(value);
break;
case VARIABLE:
haveVar = true;
final VariableReferenceExpression varArg = (VariableReferenceExpression) argExpr;
if (varEx == null) {
varEx = varArg;
} else if (!varEx.getVariableReference().equals(varArg.getVariableReference())) {
return false;
}
break;
default:
return false;
}
}
if (!(haveVar && haveConst)) {
return false;
}
}
AOrderedList list = new AOrderedList(new AOrderedListType(valType, "orderedlist"));
for (AsterixConstantValue value : values) {
list.add(value.getObject());
}
EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator();
context.computeAndSetTypeEnvironmentForOperator(ets);
ILogicalExpression cExp = new ConstantExpression(new AsterixConstantValue(list));
Mutable<ILogicalExpression> mutCExp = new MutableObject<>(cExp);
IFunctionInfo scanFctInfo = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.SCAN_COLLECTION);
UnnestingFunctionCallExpression scanExp = new UnnestingFunctionCallExpression(scanFctInfo, mutCExp);
LogicalVariable scanVar = context.newVar();
UnnestOperator unn = new UnnestOperator(scanVar, new MutableObject<>(scanExp));
unn.getInputs().add(new MutableObject<>(ets));
context.computeAndSetTypeEnvironmentForOperator(unn);
IFunctionInfo eqFctInfo = BuiltinFunctions.getAsterixFunctionInfo(AlgebricksBuiltinFunctions.EQ);
AbstractFunctionCallExpression eqExp = new ScalarFunctionCallExpression(eqFctInfo);
eqExp.getArguments().add(new MutableObject<>(new VariableReferenceExpression(scanVar)));
eqExp.getArguments().add(new MutableObject<>(varEx.cloneExpression()));
eqExp.getAnnotations().put(IndexedNLJoinExpressionAnnotation.INSTANCE, IndexedNLJoinExpressionAnnotation.INSTANCE);
BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
// Broadcast the OR predicates branch.
bcast.setObject(BroadcastExpressionAnnotation.BroadcastSide.LEFT);
eqExp.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
InnerJoinOperator jOp = new InnerJoinOperator(new MutableObject<>(eqExp));
jOp.getInputs().add(new MutableObject<>(unn));
jOp.getInputs().add(select.getInputs().get(0));
opRef.setValue(jOp);
context.computeAndSetTypeEnvironmentForOperator(jOp);
return true;
}
Aggregations