We can write a custom comparator by extending RawComparator class and overriding compare() method based on the field on which we need the output to be sorted. And the custom comparator class needs to be mentioned in the Job’s configuration.
Job.setSortComparatorClass(CustomComparator.class);