use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class LogicalOperatorDeepCopyWithNewVariablesVisitor method visitIntersectOperator.
@Override
public ILogicalOperator visitIntersectOperator(IntersectOperator op, ILogicalOperator arg) throws AlgebricksException {
List<List<LogicalVariable>> liveVarsInInputs = getLiveVarsInInputs(op);
List<LogicalVariable> outputCopy = new ArrayList<>();
for (LogicalVariable var : op.getOutputVars()) {
outputCopy.add(deepCopyVariable(var));
}
IntersectOperator opCopy = new IntersectOperator(outputCopy, liveVarsInInputs);
deepCopyInputsAnnotationsAndExecutionMode(op, arg, opCopy);
return opCopy;
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class IsomorphismVariableMappingVisitor method mapVariables.
private void mapVariables(List<LogicalVariable> variablesLeft, List<LogicalVariable> variablesRight) {
if (variablesLeft.size() != variablesRight.size()) {
return;
}
int size = variablesLeft.size();
for (int i = 0; i < size; i++) {
LogicalVariable left = variablesLeft.get(i);
LogicalVariable right = variablesRight.get(i);
variableMapping.put(right, left);
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class IsomorphismVariableMappingVisitor method mapVariablesForAbstractAssign.
private void mapVariablesForAbstractAssign(List<LogicalVariable> variablesLeft, List<Mutable<ILogicalExpression>> exprsLeft, List<LogicalVariable> variablesRight, List<Mutable<ILogicalExpression>> exprsRight) {
if (variablesLeft.size() != variablesRight.size()) {
return;
}
int size = variablesLeft.size();
// Keeps track of already matched right side variables.
Set<LogicalVariable> matchedRightVars = new HashSet<>();
for (int i = 0; i < size; i++) {
ILogicalExpression exprLeft = exprsLeft.get(i).getValue();
LogicalVariable left = variablesLeft.get(i);
for (int j = 0; j < size; j++) {
ILogicalExpression exprRight = copyExpressionAndSubtituteVars(exprsRight.get(j)).getValue();
LogicalVariable right = variablesRight.get(j);
if (exprLeft.equals(exprRight) && !matchedRightVars.contains(right)) {
variableMapping.put(right, left);
// The added variable will not be considered in next rounds.
matchedRightVars.add(right);
break;
}
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class IsomorphismVariableMappingVisitor method mapVarExprPairList.
private void mapVarExprPairList(List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> leftPairs, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> rightPairs) {
if (leftPairs.size() != rightPairs.size()) {
return;
}
for (int i = 0; i < leftPairs.size(); i++) {
ILogicalExpression exprLeft = leftPairs.get(i).second.getValue();
LogicalVariable leftVar = leftPairs.get(i).first;
for (int j = 0; j < leftPairs.size(); j++) {
ILogicalExpression exprRight = copyExpressionAndSubtituteVars(rightPairs.get(j).second).getValue();
if (exprLeft.equals(exprRight)) {
LogicalVariable rightVar = rightPairs.get(j).first;
if (rightVar != null && leftVar != null) {
variableMapping.put(rightVar, leftVar);
}
break;
}
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class LangExpressionToPlanTranslator method translate.
public ILogicalPlan translate(Query expr, String outputDatasetName, ICompiledDmlStatement stmt, ILogicalOperator baseOp) throws AlgebricksException {
MutableObject<ILogicalOperator> base = new MutableObject<>(new EmptyTupleSourceOperator());
if (baseOp != null) {
base = new MutableObject<>(baseOp);
}
Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, base);
ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<>();
ILogicalOperator topOp = p.first;
List<LogicalVariable> liveVars = new ArrayList<>();
VariableUtilities.getLiveVariables(topOp, liveVars);
LogicalVariable unnestVar = liveVars.get(0);
LogicalVariable resVar = unnestVar;
if (outputDatasetName == null) {
FileSplit outputFileSplit = metadataProvider.getOutputFile();
if (outputFileSplit == null) {
outputFileSplit = getDefaultOutputFileLocation(metadataProvider.getApplicationContext());
}
metadataProvider.setOutputFile(outputFileSplit);
List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<>(1);
writeExprList.add(new MutableObject<>(new VariableReferenceExpression(resVar)));
ResultSetSinkId rssId = new ResultSetSinkId(metadataProvider.getResultSetId());
ResultSetDataSink sink = new ResultSetDataSink(rssId, null);
DistributeResultOperator newTop = new DistributeResultOperator(writeExprList, sink);
newTop.getInputs().add(new MutableObject<>(topOp));
topOp = newTop;
// Retrieve the Output RecordType (if any) and store it on
// the DistributeResultOperator
IAType outputRecordType = metadataProvider.findOutputRecordType();
if (outputRecordType != null) {
topOp.getAnnotations().put("output-record-type", outputRecordType);
}
} else {
/**
* add the collection-to-sequence right before the project,
* because dataset only accept non-collection records
*/
LogicalVariable seqVar = context.newVar();
/**
* This assign adds a marker function collection-to-sequence: if the input is a singleton collection, unnest
* it; otherwise do nothing.
*/
AssignOperator assignCollectionToSequence = new AssignOperator(seqVar, new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.COLLECTION_TO_SEQUENCE), new MutableObject<>(new VariableReferenceExpression(resVar)))));
assignCollectionToSequence.getInputs().add(new MutableObject<>(topOp.getInputs().get(0).getValue()));
topOp.getInputs().get(0).setValue(assignCollectionToSequence);
ProjectOperator projectOperator = (ProjectOperator) topOp;
projectOperator.getVariables().set(0, seqVar);
resVar = seqVar;
DatasetDataSource targetDatasource = validateDatasetInfo(metadataProvider, stmt.getDataverseName(), stmt.getDatasetName());
List<Integer> keySourceIndicator = ((InternalDatasetDetails) targetDatasource.getDataset().getDatasetDetails()).getKeySourceIndicator();
ArrayList<LogicalVariable> vars = new ArrayList<>();
ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<>();
List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<>();
List<List<String>> partitionKeys = targetDatasource.getDataset().getPrimaryKeys();
int numOfPrimaryKeys = partitionKeys.size();
for (int i = 0; i < numOfPrimaryKeys; i++) {
if (keySourceIndicator == null || keySourceIndicator.get(i).intValue() == 0) {
// record part
PlanTranslationUtil.prepareVarAndExpression(partitionKeys.get(i), resVar, vars, exprs, varRefsForLoading, context);
} else {
// meta part
PlanTranslationUtil.prepareMetaKeyAccessExpression(partitionKeys.get(i), unnestVar, exprs, vars, varRefsForLoading, context);
}
}
AssignOperator assign = new AssignOperator(vars, exprs);
List<String> additionalFilteringField = DatasetUtil.getFilterField(targetDatasource.getDataset());
List<LogicalVariable> additionalFilteringVars;
List<Mutable<ILogicalExpression>> additionalFilteringAssignExpressions;
List<Mutable<ILogicalExpression>> additionalFilteringExpressions = null;
AssignOperator additionalFilteringAssign = null;
if (additionalFilteringField != null) {
additionalFilteringVars = new ArrayList<>();
additionalFilteringAssignExpressions = new ArrayList<>();
additionalFilteringExpressions = new ArrayList<>();
PlanTranslationUtil.prepareVarAndExpression(additionalFilteringField, resVar, additionalFilteringVars, additionalFilteringAssignExpressions, additionalFilteringExpressions, context);
additionalFilteringAssign = new AssignOperator(additionalFilteringVars, additionalFilteringAssignExpressions);
additionalFilteringAssign.getInputs().add(new MutableObject<>(topOp));
assign.getInputs().add(new MutableObject<>(additionalFilteringAssign));
} else {
assign.getInputs().add(new MutableObject<>(topOp));
}
Mutable<ILogicalExpression> varRef = new MutableObject<>(new VariableReferenceExpression(resVar));
ILogicalOperator leafOperator;
switch(stmt.getKind()) {
case Statement.Kind.INSERT:
leafOperator = translateInsert(targetDatasource, varRef, varRefsForLoading, additionalFilteringExpressions, assign, stmt);
break;
case Statement.Kind.UPSERT:
leafOperator = translateUpsert(targetDatasource, varRef, varRefsForLoading, additionalFilteringExpressions, assign, additionalFilteringField, unnestVar, topOp, exprs, resVar, additionalFilteringAssign, stmt);
break;
case Statement.Kind.DELETE:
leafOperator = translateDelete(targetDatasource, varRef, varRefsForLoading, additionalFilteringExpressions, assign);
break;
case Statement.Kind.CONNECT_FEED:
leafOperator = translateConnectFeed(targetDatasource, varRef, varRefsForLoading, additionalFilteringExpressions, assign);
break;
case Statement.Kind.SUBSCRIBE_FEED:
leafOperator = translateSubscribeFeed((CompiledSubscribeFeedStatement) stmt, targetDatasource, unnestVar, topOp, exprs, resVar, varRefsForLoading, varRef, assign, additionalFilteringField, additionalFilteringAssign, additionalFilteringExpressions);
break;
default:
throw new AlgebricksException("Unsupported statement kind " + stmt.getKind());
}
topOp = leafOperator;
}
globalPlanRoots.add(new MutableObject<>(topOp));
ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
eliminateSharedOperatorReferenceForPlan(plan);
return plan;
}
Aggregations