class PartitionComparator implements Callable<PartitionStats> {

    public PartitionStats call() {
        PartitionStats partitionStats = new PartitionStats();

        if (source == null || target == null) {
            logger.error("Skipping partition because one result was null (timeout despite retries)");
            partitionStats.skipped = true;
            return partitionStats;
        }

        while (hasNextRow(Type.SOURCE) && hasNextRow(Type.TARGET)) {

            Row sourceRow = getNextRow(Type.SOURCE);
            Row targetRow = getNextRow(Type.TARGET);

            // if primary keys don't match don't proceed any further, just mark the
            // partition as mismatched and be done
            if (!clusteringsEqual(sourceRow, targetRow)) {
                partitionStats.allClusteringsMatch = false;
                return partitionStats;
            }

            partitionStats.matchedRows++;

            // if the rows match, but there are mismatching values in the regular columns
            // we can continue processing the partition, so just flag it as mismatched and continue
            checkRegularColumnEquality(partitionStats, sourceRow, targetRow);
        }

        // if one of the iterators isn't exhausted, then there's a mismatch at the partition level
        if (hasNextRow(Type.SOURCE) || hasNextRow(Type.TARGET))
            partitionStats.allClusteringsMatch = false;

        return partitionStats;
    }

}

class PartitionComparatorTest {

    @Test
    public void sourceContainsExtraRowsAtEnd() {

        TableSpec t = spec("table1", names("c1", "c2"), names("v1", "v2"));
        PartitionComparator comparator = comparator(t,
                                                    rows(row(t, 0, 1, 2, 3),
                                                         row(t, 10, 11, 12, 13)),
                                                    rows(row(t, 0, 1, 2, 3)));
        PartitionStats stats = comparator.call();
        // The fact that the first row & all its v1 & v2 values match should be reflected in the stats
        assertStats(stats, false, false, 1, 2, 0);
    }

}