Currently, our sortByKey should be using Java's native Timsort implementation, which is an adaptive sort. That should also mean sorting is very fast for almost-sorted data. The overhead you're seeing might be caused by reshuffling everything during the range partitioning step before the sort, which has to serialize all your data.Nathan's solution might then work out nicely for you, as it will avoid shuffling the data.On Fri, Oct 25, 2013 at 9:18 AM, Josh Rosen <firstname.lastname@example.org> wrote:
Adaptive sorting algorithms (https://en.wikipedia.org/wiki/Adaptive_sort) can benefit from presortedness in their inputs, so that might be a helpful search term for researching this problem.
On Fri, Oct 25, 2013 at 7:23 AM, Nathan Kronenfeld <email@example.com> wrote:
I suspect from his description the difference is negligible for his case. However, there are ways around that anyway.Assuming a fixed data set (as opposed to something like a streaming example, where there is no last element), one can take 3 passes to:
- get the last element of each partition
- take elements from each partition that fall before the last element of the previous partition, separate them from the rest of their partition
- and add them to the previous (whichever previous is appropriate, in really degenerate cases, which it sounds like he doesn't have) in the right locationOn Fri, Oct 25, 2013 at 10:17 AM, Sebastian Schelter <firstname.lastname@example.org> wrote:
Using a local sort per partition only gives a correct result if the data
is already range partitioned.
>> I am trying to process some logs and the data is sorted(*almost*) by
On 25.10.2013 16:11, Nathan Kronenfeld wrote:
> Since no one else has answered...
> I assume:
> would work, but I also suspect there's a better way.
> On Fri, Oct 25, 2013 at 5:01 AM, Arun Kumar <email@example.com> wrote:
>> If I do a full sort it takes a lot of time. Is there some way to sort more
>> efficiently (like restricting sort to per partition).
>> Thanks in advance