Skip to content

[Go][Table] Implement sort function #66

Closed

Description

@yevgenypats

Describe the enhancement requested

Seems the python library has a sort functionality for table - https://arrow.apache.org/cookbook/py/data.html#sort-a-table

Will it make sense to implement the same for the Go library (unless it is already implemented and I missed it)?

Component(s)

Go

Activity

  1. added
    Type: enhancement
    on Mar 22, 2023
  2. zeroshade commented on Mar 22, 2023

    @zeroshade
    Member

    It definitely makes sense to implement the same functionality for Go and it's on my list of stuff I intend to get to, but if you wanna try your hand at it, that would be awesome. 😄

    We already have a Take kernel in the Go compute that works with Tables (and Records, ChunkedArrays and Arrays) so you'd just need to first implement a sort_indices vector-kernel which would output the list of indexes for ordering things (like the Acero C++ sort_indices kernel). After that is implemented and able to take a Table, it's a fairly simple combination of operations => Take(table, sort_indices(table)) == sorted table

  3. hermanschaaf commented on Mar 23, 2023

    @hermanschaaf
    Contributor

    I'd like to take a look at this. It'll be my first contribution to Arrow and I might need some pointers, but I'll give it a shot. 😄

  4. zeroshade commented on Mar 23, 2023

    @zeroshade
    Member

    @hermanschaaf Sounds great! Feel free to file a draft PR and tag me to ask for help if you need or if you have any questions.

    Just make sure that when you file the PR (draft or otherwise) the title should start with GH-34690: [Go] .... so that it auto links it to this issue. Thanks!

  5. transferred this issue fromapache/arrowon Aug 30, 2024
  6. ostafen-m2d commented on Sep 10, 2025

    @ostafen-m2d

    @zeroshade What is the state of this feature? I'm willing to contribute to the development of this.

  7. zeroshade commented on Sep 10, 2025

    @zeroshade
    Member

    The current state is stalled, we'd be happy to get a contribution to the development of this! File a PR and I'll make sure it gets reviewed. Thanks!!

  8. hamilton-earthscope commented on Dec 11, 2025

    @hamilton-earthscope
    Contributor

    Hi @zeroshade I like your guidance above: Take(table, sort_indices(table)) == sorted table. That overarching design makes sense to me.

    I'm interested in your thoughts on the public interface and the implementation of the kernel.

    What I'm thinking for the kernel is:

    • a single actual sort implementation that handles multi-column sorting (for records, tables) that also handles chunked arrays.
    • run all sort requests through that single implementation:
      • input: array -> calls sortindices with (single chunk, single column) -> output: array of indices
      • input: chunked array -> calls sortindices with (multi chunks, single column) -> output: array of indices
      • input: record -> calls sortindices with (single chunk, multi column) -> output: array of indices
      • input: table -> calls sortindices with (multi chunk, multi column) -> output: array of indices

    For the public interface, I'm trying to mimic the Take* public methods. Here's what I'm thinking (pseudocode):

    • SortIndices(Datum) -> Array (the indices)
      • this method just maps the varius datum shapes into the sort kernel as described above.
    • Sort(Datum) -> Datum (the sorted result)
      • this is where the Take(table, sort_indices(table)) == sorted table occurs

    which are registered with FunctionRegistry.AddFunction() with names sort_indices and sort, respectively.

    Do we also want public methods like the following?

    • SortIndices*:
      • SortIndicesArray(Array) -> Array of indices
      • SortIndicesChunk(Chunked) -> Array of indices
      • SortIndicesRecord(Record) -> Array of indices
      • SortIndicesTable(Table) -> Array of indices
    • Sort*:
      • SortArray(Array) -> sorted Array
      • SortChunked(Chunked) -> sorted Chunked
      • SortRecord(Record) -> sorted Record
      • SortTable(Table) -> sorted Table
  9. zeroshade commented on Apr 3, 2026

    @zeroshade
    Member

    What I'm thinking for the kernel is:

    Agree completely with everything you have here! One recommendation is to look at the c++ arrow sort_indices implementation for inspiration as the compute package here is based on the C++ compute package.

    Do we also want public methods like the following?

    Don't forget SortIndices(Datum) and Sort(Datum) which would just dispatch to CallFunction appropriately.

  10. added a commit that references this issue on Apr 13, 2026
    e78b931
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions