use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode in project asterixdb by apache.
the class IntroduceRandomPartitioningFeedComputationRule method rewritePre.
@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator op = opRef.getValue();
if (!op.getOperatorTag().equals(LogicalOperatorTag.ASSIGN)) {
return false;
}
ILogicalOperator opChild = op.getInputs().get(0).getValue();
if (!opChild.getOperatorTag().equals(LogicalOperatorTag.DATASOURCESCAN)) {
return false;
}
DataSourceScanOperator scanOp = (DataSourceScanOperator) opChild;
DataSource dataSource = (DataSource) scanOp.getDataSource();
if (dataSource.getDatasourceType() != DataSource.Type.FEED) {
return false;
}
final FeedDataSource feedDataSource = (FeedDataSource) dataSource;
FeedConnection feedConnection = feedDataSource.getFeedConnection();
if (feedConnection.getAppliedFunctions() == null || feedConnection.getAppliedFunctions().size() == 0) {
return false;
}
ExchangeOperator exchangeOp = new ExchangeOperator();
INodeDomain domain = new INodeDomain() {
@Override
public boolean sameAs(INodeDomain domain) {
return domain == this;
}
@Override
public Integer cardinality() {
return feedDataSource.getComputeCardinality();
}
};
exchangeOp.setPhysicalOperator(new RandomPartitionExchangePOperator(domain));
op.getInputs().get(0).setValue(exchangeOp);
exchangeOp.getInputs().add(new MutableObject<ILogicalOperator>(scanOp));
ExecutionMode em = ((AbstractLogicalOperator) scanOp).getExecutionMode();
exchangeOp.setExecutionMode(em);
exchangeOp.computeDeliveredPhysicalProperties(context);
context.computeAndSetTypeEnvironmentForOperator(exchangeOp);
AssignOperator assignOp = (AssignOperator) opRef.getValue();
AssignPOperator assignPhyOp = (AssignPOperator) assignOp.getPhysicalOperator();
assignPhyOp.setCardinalityConstraint(domain.cardinality());
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode in project asterixdb by apache.
the class AbstractIntroduceGroupByCombinerRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (context.checkIfInDontApplySet(this, op)) {
return false;
}
if (op.getOperatorTag() != LogicalOperatorTag.GROUP) {
return false;
}
GroupByOperator gbyOp = (GroupByOperator) op;
ExecutionMode executionMode = gbyOp.getExecutionMode();
if (executionMode != ExecutionMode.PARTITIONED && !(executionMode == ExecutionMode.UNPARTITIONED && gbyOp.isGroupAll())) {
return false;
}
BookkeepingInfo bi = new BookkeepingInfo();
GroupByOperator newGbyOp = opToPush(gbyOp, bi, context);
if (newGbyOp == null) {
return false;
}
Set<LogicalVariable> newGbyLiveVars = new ListSet<LogicalVariable>();
VariableUtilities.getLiveVariables(newGbyOp, newGbyLiveVars);
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gbyOp.getDecorList()) {
List<LogicalVariable> usedDecorVars = new ArrayList<LogicalVariable>();
// p.second.getValue() should always return a VariableReferenceExpression, hence
// usedDecorVars should always contain only one variable.
p.second.getValue().getUsedVariables(usedDecorVars);
if (!newGbyLiveVars.contains(usedDecorVars.get(0))) {
// Let the left-hand side of gbyOp's decoration expressions populated through the combiner group-by without
// any intermediate assignment.
newGbyOp.addDecorExpression(null, p.second.getValue());
}
}
newGbyOp.setExecutionMode(ExecutionMode.LOCAL);
Object v = gbyOp.getAnnotations().get(OperatorAnnotations.USE_HASH_GROUP_BY);
newGbyOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, v);
Object v2 = gbyOp.getAnnotations().get(OperatorAnnotations.USE_EXTERNAL_GROUP_BY);
newGbyOp.getAnnotations().put(OperatorAnnotations.USE_EXTERNAL_GROUP_BY, v2);
List<LogicalVariable> propagatedVars = new LinkedList<LogicalVariable>();
VariableUtilities.getProducedVariables(newGbyOp, propagatedVars);
Set<LogicalVariable> freeVars = new HashSet<LogicalVariable>();
OperatorPropertiesUtil.getFreeVariablesInSubplans(gbyOp, freeVars);
for (LogicalVariable var : freeVars) {
if (!propagatedVars.contains(var)) {
LogicalVariable newDecorVar = context.newVar();
newGbyOp.addDecorExpression(newDecorVar, new VariableReferenceExpression(var));
VariableUtilities.substituteVariables(gbyOp.getNestedPlans().get(0).getRoots().get(0).getValue(), var, newDecorVar, context);
}
}
Mutable<ILogicalOperator> opRef3 = gbyOp.getInputs().get(0);
opRef3.setValue(newGbyOp);
typeGby(newGbyOp, context);
typeGby(gbyOp, context);
context.addToDontApplySet(this, op);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode in project asterixdb by apache.
the class IsolateHyracksOperatorsRule method insertOneToOneExchange.
private static final void insertOneToOneExchange(Mutable<ILogicalOperator> i, IOptimizationContext context) throws AlgebricksException {
ExchangeOperator e = new ExchangeOperator();
e.setPhysicalOperator(new OneToOneExchangePOperator());
ILogicalOperator inOp = i.getValue();
e.getInputs().add(new MutableObject<ILogicalOperator>(inOp));
i.setValue(e);
// e.recomputeSchema();
OperatorPropertiesUtil.computeSchemaAndPropertiesRecIfNull(e, context);
ExecutionMode em = ((AbstractLogicalOperator) inOp).getExecutionMode();
e.setExecutionMode(em);
e.computeDeliveredPhysicalProperties(context);
context.computeAndSetTypeEnvironmentForOperator(e);
}
Aggregations