@Nullable public static KafkaInputSplit intersectRange(KafkaInputSplit split1,
      KafkaInputSplit split2) {
    assert (split1.topic.equals(split2.topic));
    assert (split1.partition == split2.partition);
    final long startOffset = Math.max(split1.getStartOffset(), split2.getStartOffset());
    final long endOffset = Math.min(split1.getEndOffset(), split2.getEndOffset());
    if (startOffset > endOffset) {
      // there is no overlapping
      return null;
    }
    return new KafkaInputSplit(split1.topic, split1.partition, startOffset, endOffset, split1.getPath());
  }
Compute the intersection of 2 splits. Splits must share the same topic and partition number.

@param split1 left split
@param split2 right split

@return new split that represents range intersection or null if it is not overlapping
kafka-handler/src/java/org/apache/hadoop/hive/kafka/KafkaInputSplit.java