alamb commented on issue #970: URL: https://github.com/apache/arrow-datafusion/issues/970#issuecomment-947566506
@houqp, the idea of using an optimizer pass is a great one. We might even be
able to do it without any changes to the TableProvider as of now.
For example, if the input plan was like this:
```
┌──────────────────┐
│ Limit │
└──────────────────┘
▲
│
┌──────────────────┐
│ Aggregate │
└──────────────────┘
▲
│
┌──────────────────┐
│ Join │
└──────────────────┘
▲
┌──────────┴───────────┐
│ │
┌──────────────────┐ ┌──────────────────┐
│ Scan A │ │ Join │
└──────────────────┘ └──────────────────┘
▲
┌──────────┴───────────┐
│ │
┌──────────────────┐ ┌──────────────────┐
│ Scan B │ │ Scan C │
└──────────────────┘ └──────────────────┘
```
I could imagine a custom optimizer pass that recoginzed that `B` and `C`
were available in some external database and could rewrite the plan as you
suggest:
```
┌──────────────────┐
│ Limit │
└──────────────────┘
▲
│
┌──────────────────┐
│ Aggregate │
└──────────────────┘
▲
│
┌──────────────────┐ Optimizer pass
│ Join │ recognizes B and C
└──────────────────┘ are available in
▲ external database
┌────────────────────┴───────────┐
│ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
┌──────────────────┐ ┌──────────────────┐ │
│ Scan A │ │ │ Join │
└──────────────────┘ └──────────────────┘ │
│ ▲
┌──────────┴───────────┐ │
│ │ │
┌──────────────────┐ ┌──────────────────┐ │
││ Scan B │ │ Scan C │
└──────────────────┘ └──────────────────┘ │
│
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘
```
```
┌──────────────────┐
│ Limit │
└──────────────────┘
▲
│
┌──────────────────┐
│ Aggregate │
└──────────────────┘
▲
│
┌──────────────────┐
│ Join │ Rewritten Plan
└──────────────────┘
▲
┌───────────┴───────────┐
│ │
┌──────────────────┐ ┏━━━━━━━━━━━━━━━━━━┓
│ Scan A │ ┃ Scan B+C ┃
└──────────────────┘ ┃ (TableProvider ┃
┃ that runs a SQL ┃
┃ query in an ┃
┃external database)┃
┗━━━━━━━━━━━━━━━━━━┛
```
The specifics of what types of subplans could be converted is probably
specific to the database being pushed to, so it isn't clear that logic belongs
in the main datafusion crate.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
