Search in sources :

Example 1 with MaterializePOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.physical.MaterializePOperator in project asterixdb by apache.

the class IntroduceMaterializationForInsertWithSelfScanRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.INSERT_DELETE_UPSERT) {
        return false;
    }
    InsertDeleteUpsertOperator insertOp = (InsertDeleteUpsertOperator) op;
    boolean sameDataset = checkIfInsertAndScanDatasetsSame(op, ((DatasetDataSource) insertOp.getDataSource()).getDataset().getDatasetName());
    if (sameDataset) {
        MaterializeOperator materializeOperator = new MaterializeOperator();
        MaterializePOperator materializePOperator = new MaterializePOperator(true);
        materializeOperator.setPhysicalOperator(materializePOperator);
        materializeOperator.getInputs().add(new MutableObject<ILogicalOperator>(insertOp.getInputs().get(0).getValue()));
        context.computeAndSetTypeEnvironmentForOperator(materializeOperator);
        insertOp.getInputs().clear();
        insertOp.getInputs().add(new MutableObject<ILogicalOperator>(materializeOperator));
        context.computeAndSetTypeEnvironmentForOperator(insertOp);
        return true;
    } else {
        return false;
    }
}
Also used : MaterializeOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.MaterializeOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) InsertDeleteUpsertOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteUpsertOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) DatasetDataSource(org.apache.asterix.metadata.declared.DatasetDataSource) MaterializePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.MaterializePOperator)

Aggregations

DatasetDataSource (org.apache.asterix.metadata.declared.DatasetDataSource)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)1 InsertDeleteUpsertOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteUpsertOperator)1 MaterializeOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.MaterializeOperator)1 MaterializePOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.MaterializePOperator)1