private int findNextDifferentRowIndex() {
    int totalRows = currentTsBlock.getPositionCount();

    // check if all rows have the same partition values
    SortKey compareKey = new SortKey(currentTsBlock, totalRows - 1);
    if (partitionComparator.compare(currentPartitionKey, compareKey) == 0) {
      return totalRows;
    }

    // check the first row
    compareKey.rowIndex = currentIndex;
    if (partitionComparator.compare(currentPartitionKey, compareKey) != 0) {
      currentPartitionKey = compareKey;
      return currentIndex;
    }

    // binary search to find the next different partition values
    int low = currentIndex;
    int high = totalRows - 1;
    int firstDiff = totalRows;
    while (low <= high) {
      compareKey.rowIndex = low + (high - low) / 2;
      int cmp = partitionComparator.compare(currentPartitionKey, compareKey);
      if (cmp == 0) {
        low = compareKey.rowIndex + 1;
      } else {
        // try to find earlier different row
        firstDiff = compareKey.rowIndex;
        high = compareKey.rowIndex - 1;
      }
    }
    compareKey.rowIndex = firstDiff;
    currentPartitionKey = compareKey;
    return firstDiff;
  }
Find next row index whose partition values are different from the current partition values. If
all rows have the same partition values, return the position count of the current TsBlock.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/function/PartitionRecognizer.java