@Override
    public Object processRemove(Object data, AggregatorState state) {
        Set newSet = (Set) data;
        for (Object o : newSet) {
            if (state.counter != null) {
                Integer currentCount = state.counter.get(o);
                if (currentCount == null) {
                    //means o does not exist in the counter map or in the set hence doing nothing
                } else if (currentCount == 0) {
                    throw new IllegalStateException("Error occurred when removing element from " +
                            "union-set for element: " + o.toString());
                } else if (currentCount == 1) {
                    state.set.remove(o);
                } else {
                    state.counter.put(o, currentCount - 1);
                }
            } else {
                state.set.remove(o);
            }
        }
        Set returnSet = new HashSet();
        returnSet.addAll(state.set);
        return returnSet;
    }
The initialization method for FunctionExecutor

@param attributeExpressionExecutors are the executors of each attributes in the function
@param processingMode               query processing mode
@param outputExpectsExpiredEvents   is expired events sent as output
@param configReader                 this hold the {@link CountAttributeAggregatorExecutor} configuration reader.
@param siddhiQueryContext           Siddhi query runtime context
modules/siddhi-core/src/main/java/io/siddhi/core/query/selector/attribute/aggregator/UnionSetAttributeAggregatorExecutor.java