Skip to content

Nested coalesce #6074

Open
Open
@crepererum

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:

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