Commit 4184b07
authored
refactor: pass SubqueryContext explicitly through planner traits (apache#23649)
## Which issue does this PR close?
- Alternative to apache#22340
## Rationale for this change
When we turn logical plans into physical plans, we have a work around to
get the context for scalar subqueries. Specifically we clone the session
and mutate the `execution_props` where the subquery context currently
sits. This is even called out in the code with comments:
```rust
// Ideally, the subquery state would live in a dedicated planning
// context rather than in `ExecutionProps`. It's here because
// `create_physical_expr` only receives `&ExecutionProps`.
```
The real reason for this is that we want to expose the `QueryPlanner`
via FFI and currently it depends upon downcasts from `Session` to
`SessionState`. That does not work for the FFI crate where we have a
different `Session` implementation. Since we cannot do the downcast, we
cannot use the work around in the current code.
This PR is designed to plumb through the required context properly
rather than rely on manipulating the execution properties.
## What changes are included in this PR?
The major change here is to remove `subquery_indexes` and
`subquery_results` from `ExecutionProps` and put them into their own
struct `SubqueryContext`. Everything else is just refactoring and
plumbing to align around this split of the data.
## Are these changes tested?
- Existing unit tests all pass.
- Added additional unit test to cover user defined expressions.
## Are there any user-facing changes?
Yes, this adds a single parameter into `create_physical_expr`, the
subquery context. The migration guide demonstrates how to add a default
context in for users, if necessary.1 parent 3b1ce16 commit 4184b07
32 files changed
Lines changed: 993 additions & 309 deletions
File tree
- datafusion-examples/examples
- dataframe
- query_planning
- relation_planner
- datafusion
- catalog-listing/src
- catalog/src
- memory
- core
- src
- execution
- context
- test_util
- tests
- parquet
- user_defined
- datasource/src
- file_scan_config
- expr/src
- functions-nested/src
- optimizer/src
- simplify_expressions
- physical-expr/src
- physical-plan/src
- proto
- src/physical_plan
- tests/cases
- docs/source/library-user-guide/upgrading
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| 150 | + | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
541 | 542 | | |
542 | 543 | | |
543 | 544 | | |
544 | | - | |
545 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
546 | 551 | | |
547 | 552 | | |
548 | 553 | | |
| |||
566 | 571 | | |
567 | 572 | | |
568 | 573 | | |
| 574 | + | |
569 | 575 | | |
570 | 576 | | |
571 | 577 | | |
| |||
578 | 584 | | |
579 | 585 | | |
580 | 586 | | |
| 587 | + | |
581 | 588 | | |
582 | 589 | | |
583 | 590 | | |
| |||
606 | 613 | | |
607 | 614 | | |
608 | 615 | | |
| 616 | + | |
609 | 617 | | |
610 | 618 | | |
611 | 619 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
198 | 205 | | |
199 | 206 | | |
200 | 207 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| |||
587 | 588 | | |
588 | 589 | | |
589 | 590 | | |
| 591 | + | |
590 | 592 | | |
591 | 593 | | |
592 | 594 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
328 | 329 | | |
329 | 330 | | |
330 | 331 | | |
331 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
332 | 338 | | |
333 | 339 | | |
334 | 340 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
614 | 615 | | |
615 | 616 | | |
616 | 617 | | |
| 618 | + | |
617 | 619 | | |
618 | 620 | | |
619 | 621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
212 | | - | |
213 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
214 | 219 | | |
215 | 220 | | |
216 | 221 | | |
| |||
356 | 361 | | |
357 | 362 | | |
358 | 363 | | |
359 | | - | |
360 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
361 | 370 | | |
362 | 371 | | |
363 | 372 | | |
| |||
470 | 479 | | |
471 | 480 | | |
472 | 481 | | |
473 | | - | |
474 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
475 | 488 | | |
476 | 489 | | |
477 | 490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
135 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
136 | 141 | | |
137 | 142 | | |
138 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2383 | 2383 | | |
2384 | 2384 | | |
2385 | 2385 | | |
| 2386 | + | |
2386 | 2387 | | |
2387 | 2388 | | |
2388 | 2389 | | |
| |||
2851 | 2852 | | |
2852 | 2853 | | |
2853 | 2854 | | |
| 2855 | + | |
2854 | 2856 | | |
2855 | 2857 | | |
2856 | 2858 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
799 | 800 | | |
800 | 801 | | |
801 | 802 | | |
802 | | - | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
803 | 809 | | |
804 | 810 | | |
805 | 811 | | |
| |||
0 commit comments