nextOperatorRef = new MutableObject<ILogicalOperator>(ntsOperator);
// Get variable that is being used for sort and distinct operators.
VariableReferenceExpression inputVariableRef = (VariableReferenceExpression) functionCall.getArguments().get(0)
.getValue();
LogicalVariable inputVariable = inputVariableRef.getVariableReference();
// Unnest.
LogicalVariable unnestVariable = context.newVar();
UnnestOperator unnestOperator = getUnnestOperator(inputVariable, unnestVariable);
unnestOperator.getInputs().add(nextOperatorRef);
nextOperatorRef = new MutableObject<ILogicalOperator>(unnestOperator);
// Assign Node ID key.
LogicalVariable nodeIdKeyVariable = context.newVar();
AssignOperator nodeIdAssignOp = getAssignOperator(unnestVariable, nodeIdKeyVariable,
BuiltinOperators.ID_FROM_NODE);
nodeIdAssignOp.getInputs().add(nextOperatorRef);
nextOperatorRef = new MutableObject<ILogicalOperator>(nodeIdAssignOp);
// Prepare for Order and Distinct.
Mutable<ILogicalExpression> nodeIdKeyVariableRef = new MutableObject<ILogicalExpression>(
new VariableReferenceExpression(nodeIdKeyVariable));
// Distinct.
if (functionCall.getFunctionIdentifier().equals(
BuiltinOperators.SORT_DISTINCT_NODES_ASC_OR_ATOMICS.getFunctionIdentifier())
|| functionCall.getFunctionIdentifier().equals(
BuiltinOperators.DISTINCT_NODES_OR_ATOMICS.getFunctionIdentifier())) {
LogicalVariable groupByVariable = context.newVar();
ILogicalExpression nodeIdKeyVre = new VariableReferenceExpression(nodeIdKeyVariable);
GroupByOperator groupByOperator = getGroupByOperator(groupByVariable, nodeIdKeyVre);
groupByOperator.getInputs().add(nextOperatorRef);
nextOperatorRef = new MutableObject<ILogicalOperator>(groupByOperator);
}
// // Order.
// if (functionCall.getFunctionIdentifier().equals(
// BuiltinOperators.SORT_DISTINCT_NODES_ASC_OR_ATOMICS.getFunctionIdentifier())
// || functionCall.getFunctionIdentifier().equals(
// BuiltinOperators.SORT_NODES_ASC_OR_ATOMICS.getFunctionIdentifier())) {
// OrderOperator orderOperator = getOrderOperator(nodeIdKeyVariableRef);
// orderOperator.getInputs().add(nextOperatorRef);
// nextOperatorRef = new MutableObject<ILogicalOperator>(orderOperator);
// }
//
// Aggregate.
LogicalVariable aggregateVariable = assign.getVariables().get(0);
AggregateOperator aggregateOperator = getAggregateOperator(unnestVariable, aggregateVariable);
aggregateOperator.getInputs().add(nextOperatorRef);
nextOperatorRef = new MutableObject<ILogicalOperator>(aggregateOperator);
// Subplan.