use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.
the class ResolveVariableRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator op = opRef.getValue();
if (op.getInputs().isEmpty()) {
return false;
}
// Populates the latest type information, e.g., resolved path sugars.
context.computeAndSetTypeEnvironmentForOperator(op);
if (op.acceptExpressionTransform(exprRef -> rewriteExpressionReference(op, exprRef, new Triple<>(false, null, null), null, context))) {
// Generates the up-to-date type information.
context.computeAndSetTypeEnvironmentForOperator(op);
return true;
}
return false;
}
use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.
the class MetadataProvider method buildFeedIntakeRuntime.
public Triple<IOperatorDescriptor, AlgebricksPartitionConstraint, IAdapterFactory> buildFeedIntakeRuntime(JobSpecification jobSpec, Feed primaryFeed, FeedPolicyAccessor policyAccessor) throws Exception {
Triple<IAdapterFactory, RecordDescriptor, IDataSourceAdapter.AdapterType> factoryOutput;
factoryOutput = FeedMetadataUtil.getPrimaryFeedFactoryAndOutput(primaryFeed, policyAccessor, mdTxnCtx, getApplicationContext());
ARecordType recordType = FeedMetadataUtil.getOutputType(primaryFeed, primaryFeed.getAdapterConfiguration(), ExternalDataConstants.KEY_TYPE_NAME);
IAdapterFactory adapterFactory = factoryOutput.first;
FeedIntakeOperatorDescriptor feedIngestor = null;
switch(factoryOutput.third) {
case INTERNAL:
feedIngestor = new FeedIntakeOperatorDescriptor(jobSpec, primaryFeed, adapterFactory, recordType, policyAccessor, factoryOutput.second);
break;
case EXTERNAL:
String libraryName = primaryFeed.getAdapterName().trim().split(FeedConstants.NamingConstants.LIBRARY_NAME_SEPARATOR)[0];
feedIngestor = new FeedIntakeOperatorDescriptor(jobSpec, primaryFeed, libraryName, adapterFactory.getClass().getName(), recordType, policyAccessor, factoryOutput.second);
break;
default:
break;
}
AlgebricksPartitionConstraint partitionConstraint = adapterFactory.getPartitionConstraint();
return new Triple<>(feedIngestor, partitionConstraint, adapterFactory);
}
use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.
the class InsertProjectBeforeUnionRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
return false;
}
UnionAllOperator opUnion = (UnionAllOperator) op;
List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = opUnion.getVariableMappings();
ArrayList<LogicalVariable> usedVariablesFromOne = new ArrayList<>();
ArrayList<LogicalVariable> usedVariablesFromTwo = new ArrayList<>();
for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple : varMap) {
usedVariablesFromOne.add(triple.first);
usedVariablesFromTwo.add(triple.second);
}
ArrayList<LogicalVariable> inputSchemaOne = new ArrayList<>();
VariableUtilities.getLiveVariables(opUnion.getInputs().get(0).getValue(), inputSchemaOne);
ArrayList<LogicalVariable> inputSchemaTwo = new ArrayList<>();
VariableUtilities.getLiveVariables(opUnion.getInputs().get(1).getValue(), inputSchemaTwo);
boolean rewritten = false;
if (!isIdentical(usedVariablesFromOne, inputSchemaOne)) {
insertProjectOperator(opUnion, 0, usedVariablesFromOne, context);
rewritten = true;
}
if (!isIdentical(usedVariablesFromTwo, inputSchemaTwo)) {
insertProjectOperator(opUnion, 1, usedVariablesFromTwo, context);
rewritten = true;
}
return rewritten;
}
use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.
the class PushAssignBelowUnionAllRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (!op.hasInputs()) {
return false;
}
boolean modified = false;
for (int i = 0; i < op.getInputs().size(); i++) {
AbstractLogicalOperator childOp = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
if (childOp.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
continue;
}
AssignOperator assignOp = (AssignOperator) childOp;
for (Mutable<ILogicalExpression> expr : assignOp.getExpressions()) {
if (!expr.getValue().isFunctional()) {
return false;
}
}
AbstractLogicalOperator childOfChildOp = (AbstractLogicalOperator) assignOp.getInputs().get(0).getValue();
if (childOfChildOp.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
continue;
}
UnionAllOperator unionOp = (UnionAllOperator) childOfChildOp;
Set<LogicalVariable> assignUsedVars = new HashSet<LogicalVariable>();
VariableUtilities.getUsedVariables(assignOp, assignUsedVars);
List<LogicalVariable> assignVars = assignOp.getVariables();
AssignOperator[] newAssignOps = new AssignOperator[2];
for (int j = 0; j < unionOp.getInputs().size(); j++) {
newAssignOps[j] = createAssignBelowUnionAllBranch(unionOp, j, assignOp, assignUsedVars, context);
}
// Add original assign variables to the union variable mappings.
for (int j = 0; j < assignVars.size(); j++) {
LogicalVariable first = newAssignOps[0].getVariables().get(j);
LogicalVariable second = newAssignOps[1].getVariables().get(j);
Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(first, second, assignVars.get(j));
unionOp.getVariableMappings().add(varMapping);
}
context.computeAndSetTypeEnvironmentForOperator(unionOp);
// Remove original assign operator.
op.getInputs().set(i, assignOp.getInputs().get(0));
context.computeAndSetTypeEnvironmentForOperator(op);
modified = true;
}
return modified;
}
use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.
the class RemoveUnusedAssignAndAggregateRule method removeAssignVarFromConsideration.
/**
* Collect the information from the given operator and removes assigned
* variables if they are used afterwards.
*/
private Set<LogicalVariable> removeAssignVarFromConsideration(Mutable<ILogicalOperator> opRef) {
Set<LogicalVariable> assignVarsSetForThisOp = null;
Set<LogicalVariable> usedVarsSetForThisOp = null;
if (accumulatedUsedVarFromRootMap.containsKey(opRef)) {
usedVarsSetForThisOp = accumulatedUsedVarFromRootMap.get(opRef);
}
if (assignedVarMap.containsKey(opRef)) {
assignVarsSetForThisOp = assignedVarMap.get(opRef);
}
if (assignVarsSetForThisOp != null && !assignVarsSetForThisOp.isEmpty()) {
Iterator<LogicalVariable> varIter = assignVarsSetForThisOp.iterator();
while (varIter.hasNext()) {
LogicalVariable v = varIter.next();
if ((usedVarsSetForThisOp != null && usedVarsSetForThisOp.contains(v)) || survivedUnionSourceVarSet.contains(v)) {
varIter.remove();
}
}
}
// afterwards.
if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.UNIONALL) {
Iterator<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> iter = ((UnionAllOperator) opRef.getValue()).getVariableMappings().iterator();
while (iter.hasNext()) {
Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping = iter.next();
survivedUnionSourceVarSet.add(varMapping.first);
survivedUnionSourceVarSet.add(varMapping.second);
}
}
return assignVarsSetForThisOp;
}
Aggregations