arrow icon indicating copy to clipboard operation
arrow copied to clipboard

[C++][Compute] Fix null sorting of multiple sort keys

Open Light-City opened this issue 3 years ago • 14 comments

Describe the bug, including details regarding any error messages, version, and platform.

Currently, NullPlacement is a global control, and this parameter is used for all sortkeys. However, for databases like pg, it should be one for each sortkey, for example:

order by i nulls first, j, k nulls first;

code is

  /// Column key(s) to order by and how to order by these sort keys.
  std::vector<SortKey> sort_keys;
  /// Whether nulls and NaNs are placed at the start or at the end
  NullPlacement null_placement;

Component(s)

C++

Light-City avatar Nov 02 '23 07:11 Light-City

So the NullPlacement should support being std::vector<NullPlacement> ?

mapleFU avatar Nov 02 '23 07:11 mapleFU

How about moving NullPlacement to SortKey?

kou avatar Nov 02 '23 07:11 kou

So the NullPlacement should support being std::vector<NullPlacement> ?

yes.

Light-City avatar Nov 02 '23 08:11 Light-City

How about moving NullPlacement to SortKey? In this case, it's better

Light-City avatar Nov 02 '23 08:11 Light-City

If no one does it, I can try to implement it

Light-City avatar Nov 02 '23 08:11 Light-City

Also cc @bkietz @ianmcook for some info here

mapleFU avatar Nov 02 '23 08:11 mapleFU

https://github.com/apache/arrow-rs/blob/829708d4911bc0798ca2a388cd7df20478a4cc08/arrow-schema/src/lib.rs#L37

Seems that maybe this is better. But waiting for others idea for compability

mapleFU avatar Nov 02 '23 14:11 mapleFU

when sorting multiple columns, rust also allows per-column null placement https://github.com/apache/arrow-rs/blob/1807abace4153cbfd287ee830f86ebaeeae50234/arrow-ord/src/sort.rs#L611

Seems reasonable to support in c++

bkietz avatar Nov 02 '23 15:11 bkietz

It has been implemented, I will send a PR later, haha

Light-City avatar Nov 03 '23 10:11 Light-City

I saw a comment about difficulties with sorting for multiple batches (ChunkedArray, Table), but it looks like you've solved it. lol

I'm interested in this issue because I'm interested in sorting for DictionaryType in multiple batches.

llama90 avatar Nov 03 '23 10:11 llama90

I found that the NullPlacement in the selectk scenario is all hard-coded AtEnd. It should also be modified correctly. Take this opportunity to apply it to each SortKey.

Light-City avatar Nov 06 '23 07:11 Light-City

Issue resolved by pull request 46926 https://github.com/apache/arrow/pull/46926

pitrou avatar Jun 22 '26 11:06 pitrou

Great! Thanks @pitrou!

taepper avatar Jun 22 '26 12:06 taepper