Skip to content

Split EmptyExec into OneRowExec #8355

Closed

Description

@crepererum

Is your feature request related to a problem or challenge?

Currently EmptyExec has a parameter that says "return one row":

https://github.com/apache/arrow-datafusion/blob/19bdcdc4140f0b36023626195d84bfbf970b752d/datafusion/physical-plan/src/empty.rs#L35-L44

In that case, it's not really empty. This is confusing and a source of bugs because optimization passes now have to check if that flag is set or not (e.g. to prune sub-trees).

I would also argue that the use case of "produce row" is different: while EmptyExec can totally occur during production (e.g. when data / sub-trees are pruned based on statistics) the "one row" case is very likely for testing.

Describe the solution you'd like

Split that exec node into two types:

  1. EmptyExec: really produces nothing
  2. OneRowExec: takes over the one row use case

Describe alternatives you've considered

Not doing anything.

Additional context

No response

Activity

  1. alamb commented on Nov 29, 2023

    @alamb
    Contributor

    I think this is a reasonable first (maybe more like second) issue -- it is fairly mechanical but will require figuring out some of how ExecutionPlan works and updating a bunch of tests

  2. changed the title [-]Split `EmptyExec`[/-] [+]Split `EmptyExec` into `OneRowExec`[/+] on Nov 29, 2023
  3. tustvold commented on Nov 29, 2023

    @tustvold
    Contributor

    FWIW unless the single-row aspect of OneRowExec is important, it could possibly just use MemoryExec - https://docs.rs/datafusion/latest/datafusion/physical_plan/memory/struct.MemoryExec.html

  4. alamb commented on Nov 29, 2023

    @alamb
    Contributor

    single_row is used for queries like select now()

    ❯ select now();
    +-----------------------------+
    | now()                       |
    +-----------------------------+
    | 2023-11-29T15:46:02.712512Z |
    +-----------------------------+
    1 row in set. Query took 0.030 seconds.

    I think we can now make a batch now with no columns but 1 row via https://docs.rs/arrow/latest/arrow/array/struct.RecordBatch.html#method.try_new_with_options which was not always the case . Using MemoryExec might work just fine.

  5. razeghi71 commented on Dec 6, 2023

    @razeghi71
    Contributor

    I have tried to move the produce_one_row to MemoryExec in #8412, but it wasn't straight forward as there are no try_into_physical_plan and try_from_physical_plan implemented for MemoryExec.

    Anyway I have tried to implement the physical plan, but since MemoryExec contains dyn Array for storing it's partitions it's a little bit tricky to serialize it to proto, the best way coming to my mind is to json serialize it as a string field in proto.

    I can do that, but before I wanted to get feedback here and make sure if that's a good path to go? @alamb @tustvold @crepererum

  6. alamb commented on Dec 6, 2023

    @alamb
    Contributor

    I have tried to move the produce_one_row to MemoryExec in #8412, but it wasn't straight forward as there are no try_into_physical_plan and try_from_physical_plan implemented for MemoryExec.

    Anyway I have tried to implement the physical plan, but since MemoryExec contains dyn Array for storing it's partitions it's a little bit tricky to serialize it to proto, the best way coming to my mind is to json serialize it as a string field in proto.

    I can do that, but before I wanted to get feedback here and make sure if that's a good path to go? @alamb @tustvold @crepererum

    The serialization is a good point

    What about perhaps making a new OneRowExec instead of reusing MemoryExec ? I think the code would be fairly straightforward.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions