Skip to content

Nested coalesce #6074

Open
Open

Description

@crepererum

Is your feature request related to a problem or challenge?

coalsece currently does not support structs. If it would however, I think it should only consider top-level NULLs, so coalsece(NULL, {a: 1, b: NULL}, {a: 2, b: 3}) = {a: 1, b: NULL}. However sometimes it would be handy to fill in fields recursively. So coalsece_nested(NULL, {a: 1, b: NULL}, {a: 2, b: 3}) = {a: 1, b: 3}

Describe the solution you'd like

Have a coalesce variant that supports structs by traversing them recursively. So:

coalesce_nested(
  NULL,
  {
    a: 1,
    b: NULL,
    c: NULL,
    d: NULL,
  },
  {
    a: 2,
    b: NULL,
    c: {a: NULL},
    d: {a: 2, b: NULL},
  },
  {
    a: 3,
    b: NULL,
    c: NULL,
    d: {a: 3, b: 3},
  },
)

=

{
  a: 1,
  b: NULL,
  c: {a: NULL},
  d: {a: 2, b: 3},
}

Describe alternatives you've considered

-

Additional context

A user that fully knows the type could manually construct this using coalesce and named_struct (proposed in #5861).

Prior art:

Activity

  1. crepererum commented on Apr 20, 2023

    @crepererum
    ContributorAuthor

    If this is a desired feature to have in DataFusion, I can contribute it. I have this nearly ready because we probably need a (somewhat simpler version of it) in InfluxDB IOx anyways.

  2. alamb commented on Apr 24, 2023

    @alamb
    Contributor

    I personally think we should start in IOx -- I am not sure how widely useful this is to the DataFusion community as a whole -- maybe others can weigh in

  3. alamb commented on Apr 24, 2023

    @alamb
    Contributor

    Added to structured type tracking ticket: #2326

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions