// Get the DocumentOrder from propagation.
switch (op.getOperatorTag()) {
case AGGREGATE:
AggregateOperator aggregate = (AggregateOperator) op;
for (int index = 0; index < aggregate.getExpressions().size(); index++) {
ILogicalExpression aggregateLogicalExpression = (ILogicalExpression) aggregate.getExpressions()
.get(index).getValue();
variableId = aggregate.getVariables().get(index).getId();
documentOrder = propagateDocumentOrder(aggregateLogicalExpression,
documentOrderVariablesForOperator);
uniqueNodes = propagateUniqueNodes(aggregateLogicalExpression, uniqueNodesVariablesForOperator);
documentOrderVariables.put(variableId, documentOrder);
uniqueNodesVariables.put(variableId, uniqueNodes);
}
break;
case ASSIGN:
AssignOperator assign = (AssignOperator) op;
for (int index = 0; index < assign.getExpressions().size(); index++) {
ILogicalExpression assignLogicalExpression = (ILogicalExpression) assign.getExpressions()
.get(index).getValue();
variableId = assign.getVariables().get(index).getId();
documentOrder = propagateDocumentOrder(assignLogicalExpression, documentOrderVariablesForOperator);
uniqueNodes = propagateUniqueNodes(assignLogicalExpression, uniqueNodesVariablesForOperator);
documentOrderVariables.put(variableId, documentOrder);
uniqueNodesVariables.put(variableId, uniqueNodes);
}
break;
case INNERJOIN:
case LEFTOUTERJOIN:
resetDocumentOrderVariables(documentOrderVariables, DocumentOrder.NO);
resetUniqueNodesVariables(uniqueNodesVariables, UniqueNodes.NO);
break;
case ORDER:
// Get order variable id that is altered.
OrderOperator order = (OrderOperator) op;
for (int index = 0; index < order.getOrderExpressions().size(); index++) {
ILogicalExpression orderLogicalExpression = order.getOrderExpressions().get(index).second
.getValue();
if (orderLogicalExpression.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
throw new RuntimeException("Operator (" + op.getOperatorTag()
+ ") has received unexpected input in rewrite rule.");
}
VariableReferenceExpression variableExpression = (VariableReferenceExpression) orderLogicalExpression;
variableId = variableExpression.getVariableReference().getId();
// Remove document order from variable used in order operator.
documentOrderVariables.put(variableId, DocumentOrder.NO);
}
break;
case SUBPLAN:
// Find the last operator to set a variable and call this function again.
SubplanOperator subplan = (SubplanOperator) op;
for (int index = 0; index < subplan.getNestedPlans().size(); index++) {
AbstractLogicalOperator lastOperator = (AbstractLogicalOperator) subplan.getNestedPlans().get(index)
.getRoots().get(0).getValue();
updateVariableMap(lastOperator, cardinalityVariable, documentOrderVariables, uniqueNodesVariables,
vxqueryContext);
}
break;
case UNNEST:
// Get unnest item property.
UnnestOperator unnest = (UnnestOperator) op;
ILogicalExpression unnestLogicalExpression = (ILogicalExpression) unnest.getExpressionRef().getValue();
variableId = unnest.getVariables().get(0).getId();
Cardinality inputCardinality = vxqueryContext.getCardinalityOperatorMap(op.getInputs().get(0)
.getValue());
documentOrder = propagateDocumentOrder(unnestLogicalExpression, documentOrderVariablesForOperator);
uniqueNodes = propagateUniqueNodes(unnestLogicalExpression, uniqueNodesVariablesForOperator);