switch(accessNodes.size()) {
case 0:
{
if (RelationalNodeUtil.isUpdate(accessNode.getCommand())) {
//should return a 0 update count
ProjectNode pnode = new ProjectNode(getID());
pnode.setElements(accessNode.getElements());
pnode.setSelectSymbols(Arrays.asList(new ExpressionSymbol("x", new Constant(0)))); //$NON-NLS-1$
return pnode;
}
// Replace existing access node with a NullNode
NullNode nullNode = new NullNode(getID());
nullNode.setElements(accessNode.getElements());
return nullNode;
}
case 1:
{
// Replace existing access node with new access node (simplified command)
AccessNode newNode = accessNodes.get(0);
return newNode;
}
default:
{
multiSource = true;
UnionAllNode unionNode = new UnionAllNode(getID());
unionNode.setElements(accessNode.getElements());
for (AccessNode newNode : accessNodes) {
unionNode.addChild(newNode);
}
RelationalNode parent = unionNode;
// More than 1 access node - replace with a union
if (RelationalNodeUtil.isUpdate(accessNode.getCommand())) {
update = true;
GroupingNode groupNode = new GroupingNode(getID());
AggregateSymbol sumCount = new AggregateSymbol("SumCount", NonReserved.SUM, false, (Expression)accessNode.getElements().get(0)); //$NON-NLS-1$
List<Expression> outputElements = new ArrayList<Expression>(1);
outputElements.add(sumCount);
groupNode.setElements(outputElements);
groupNode.addChild(unionNode);
ProjectNode projectNode = new ProjectNode(getID());
Expression intSum = ResolverUtil.getConversion(sumCount, DataTypeManager.getDataTypeName(sumCount.getType()), DataTypeManager.DefaultDataTypes.INTEGER, false, metadata.getFunctionLibrary());
Expression rowCount = new ExpressionSymbol("RowCount", intSum); //$NON-NLS-1$
outputElements = new ArrayList<Expression>(1);
outputElements.add(rowCount);
projectNode.setElements(outputElements);
projectNode.setSelectSymbols(outputElements);
projectNode.addChild(groupNode);
parent = projectNode;
}
return parent;
}