use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class IndexBulkloadPOperator method contributeRuntimeOperator.
@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
IndexInsertDeleteUpsertOperator indexInsertDeleteOp = (IndexInsertDeleteUpsertOperator) op;
assert indexInsertDeleteOp.getOperation() == Kind.INSERT;
assert indexInsertDeleteOp.isBulkload();
IMetadataProvider mp = context.getMetadataProvider();
IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(op);
JobSpecification spec = builder.getJobSpec();
RecordDescriptor inputDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas[0], context);
Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> runtimeAndConstraints = mp.getIndexInsertRuntime(dataSourceIndex, propagatedSchema, inputSchemas, typeEnv, primaryKeys, secondaryKeys, additionalFilteringKeys, filterExpr, inputDesc, context, spec, true);
builder.contributeHyracksOperator(indexInsertDeleteOp, runtimeAndConstraints.first);
builder.contributeAlgebricksPartitionConstraint(runtimeAndConstraints.first, runtimeAndConstraints.second);
ILogicalOperator src = indexInsertDeleteOp.getInputs().get(0).getValue();
builder.contributeGraphEdge(src, 0, indexInsertDeleteOp, 0);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class AbstractPropagatePropertiesForUsedVariablesPOperator method computeDeliveredPropertiesForUsedVariables.
public void computeDeliveredPropertiesForUsedVariables(ILogicalOperator op, List<LogicalVariable> usedVariables) {
ILogicalOperator op2 = op.getInputs().get(0).getValue();
IPartitioningProperty pp = op2.getDeliveredPhysicalProperties().getPartitioningProperty();
List<ILocalStructuralProperty> downPropsLocal = op2.getDeliveredPhysicalProperties().getLocalProperties();
List<ILocalStructuralProperty> propsLocal = new ArrayList<ILocalStructuralProperty>();
if (downPropsLocal != null) {
for (ILocalStructuralProperty lsp : downPropsLocal) {
LinkedList<LogicalVariable> cols = new LinkedList<LogicalVariable>();
lsp.getColumns(cols);
ILocalStructuralProperty propagatedProp = lsp.retainVariables(usedVariables);
if (propagatedProp != null) {
propsLocal.add(propagatedProp);
}
}
}
deliveredProperties = new StructuralPropertiesVector(pp, propsLocal);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class InjectTypeCastForUnionRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator op = opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
return false;
}
UnionAllOperator unionAllOperator = (UnionAllOperator) op;
// Injects casts to the first and second input branch of the UnionAllOperator.
return injectCast(unionAllOperator, 0, context) || injectCast(unionAllOperator, 1, context);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class InjectTypeCastForUnionRule method injectCast.
// Injects a type cast function on one input (indicated by childIndex) of the union all operator if necessary.
private boolean injectCast(UnionAllOperator op, int childIndex, IOptimizationContext context) throws AlgebricksException {
// Gets the type environments for the union all operator and its child operator with the right child index.
IVariableTypeEnvironment env = context.getOutputTypeEnvironment(op);
Mutable<ILogicalOperator> branchOpRef = op.getInputs().get(childIndex);
IVariableTypeEnvironment childEnv = context.getOutputTypeEnvironment(branchOpRef.getValue());
// The two lists are used for the assign operator that calls cast functions.
List<LogicalVariable> varsToCast = new ArrayList<>();
List<Mutable<ILogicalExpression>> castFunctionsForLeft = new ArrayList<>();
// Iterate through all triples.
List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> triples = op.getVariableMappings();
for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple : triples) {
LogicalVariable producedVar = triple.third;
IAType producedType = (IAType) env.getVarType(producedVar);
LogicalVariable varToCast = childIndex == 0 ? triple.first : triple.second;
IAType inputType = (IAType) childEnv.getVarType(varToCast);
if (!TypeResolverUtil.needsCast(producedType, inputType)) {
// Continues to the next triple if no cast is neeeded.
continue;
}
LogicalVariable castedVar = context.newVar();
// Resets triple variables to new variables that bind to the results of type casting.
triple.first = childIndex == 0 ? castedVar : triple.first;
triple.second = childIndex > 0 ? castedVar : triple.second;
ScalarFunctionCallExpression castFunc = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE), new ArrayList<>(Collections.singletonList(new MutableObject<>(new VariableReferenceExpression(varToCast)))));
TypeCastUtils.setRequiredAndInputTypes(castFunc, producedType, inputType);
// Adds the variable and function expression into lists, for the assign operator.
varsToCast.add(castedVar);
castFunctionsForLeft.add(new MutableObject<>(castFunc));
}
if (castFunctionsForLeft.isEmpty()) {
return false;
}
// Injects an assign operator to perform type casts.
AssignOperator assignOp = new AssignOperator(varsToCast, castFunctionsForLeft);
assignOp.getInputs().add(new MutableObject<>(branchOpRef.getValue()));
branchOpRef.setValue(assignOp);
context.computeAndSetTypeEnvironmentForOperator(assignOp);
// Returns true to indicate that rewriting happens.
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class FeedScanCollectionToUnnest method findVarOriginExpression.
private ILogicalExpression findVarOriginExpression(LogicalVariable v, ILogicalOperator op) throws AlgebricksException {
boolean searchInputs = false;
if (!(op instanceof AbstractAssignOperator)) {
searchInputs = true;
} else {
AbstractAssignOperator aao = (AbstractAssignOperator) op;
List<LogicalVariable> producedVars = new ArrayList<>();
VariableUtilities.getProducedVariables(op, producedVars);
int exprIndex = producedVars.indexOf(v);
if (exprIndex == -1) {
searchInputs = true;
} else {
ILogicalExpression originalCandidate = aao.getExpressions().get(exprIndex).getValue();
if (originalCandidate.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
searchInputs = true;
} else {
return originalCandidate;
}
}
}
if (searchInputs) {
for (Mutable<ILogicalOperator> childOp : op.getInputs()) {
ILogicalExpression ret = findVarOriginExpression(v, childOp.getValue());
if (ret != null) {
return ret;
}
}
}
throw new IllegalStateException("Unable to find the original expression that produced variable " + v);
}
Aggregations