|| op.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
return false;
}
// Initialization.
VXQueryOptimizationContext vxqueryContext = (VXQueryOptimizationContext) context;
// Find the available variables.
Cardinality cardinalityVariable = CardinalityRuleToolbox.getProducerCardinality(opRef.getValue(),
vxqueryContext);
HashMap<Integer, DocumentOrder> documentOrderVariables = getProducerDocumentOrderVariableMap(opRef.getValue(),
vxqueryContext);
HashMap<Integer, UniqueNodes> uniqueNodesVariables = getProducerUniqueNodesVariableMap(opRef.getValue(),
vxqueryContext);
// Update sort operator if found.
int variableId = getOperatorSortDistinctNodesAscOrAtomicsArgumentVariableId(opRef);
if (variableId > 0) {
// Find the function expression.
// All the checks for these variable assigns and casting were done in the
// getOperatorSortDistinctNodesAscOrAtomicsArgumentVariableId function.
AssignOperator assign = (AssignOperator) op;
ILogicalExpression logicalExpression = (ILogicalExpression) assign.getExpressions().get(0).getValue();
AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) logicalExpression;
if (uniqueNodesVariables.get(variableId) == UniqueNodes.YES) {
// Only unique nodes.
if (documentOrderVariables.get(variableId) == DocumentOrder.YES) {
// Do not need to sort or remove duplicates from the result.
assign.getExpressions().get(0).setValue(functionCall.getArguments().get(0).getValue());
operatorChanged = true;
} else {
// Unique nodes but needs to be sorted.
functionCall.setFunctionInfo(BuiltinOperators.SORT_NODES_ASC);
operatorChanged = true;
}
} else {
// Duplicates possible in the result.
if (documentOrderVariables.get(variableId) == DocumentOrder.YES) {
// Do not need to sort the result.
functionCall.setFunctionInfo(BuiltinOperators.DISTINCT_NODES_OR_ATOMICS);
operatorChanged = true;
} else {
// No change.
}
}
}
// Now with the new operator, update the variable mappings.
cardinalityVariable = CardinalityRuleToolbox.updateCardinalityVariable(op, cardinalityVariable, vxqueryContext);
updateVariableMap(op, cardinalityVariable, documentOrderVariables, uniqueNodesVariables, vxqueryContext);
// Save propagated value.
vxqueryContext.putCardinalityOperatorMap(opRef.getValue(), cardinalityVariable);
vxqueryContext.putDocumentOrderOperatorVariableMap(opRef.getValue(), documentOrderVariables);
vxqueryContext.putUniqueNodesOperatorVariableMap(opRef.getValue(), uniqueNodesVariables);
return operatorChanged;
}