Maybe we can refactor the part of handleDuplicates for partitioned or replicated table to one function?