hablapps / doric

Type safety for spark columns
https://www.hablapps.com/doric/
Apache License 2.0
77 stars 11 forks source link

[Feature request]: Custom array_sort function for structs #337

Closed eruizalo closed 1 year ago

eruizalo commented 1 year ago

Feature suggestion

It would be nice to have a function to sort arrays of structs by column names

Current behaviour

Currently and until array_sort function with lambda is released, we have to create our own spark function or use an expression:

expr("array_sort(value, (l, r) -> case " +
  // name ASC
  "when l.name < r.name then -1 " +
  "when l.name > r.name then 1 " +
  "else ( case" +
  // age DESC
  "  when l.age > r.age then -1 " +
  "  when l.age < r.age then 1 " +
  "  else 0 end " +
  ") end)"
)