Commit d06d086
[SPARK-55983][SQL] New single-pass analyzer functionality and bugfixes
### What changes were proposed in this pull request?
This PR implements core single-pass resolver infrastructure and bugfixes. The single-pass resolver is an alternative to the traditional fixed-point (iterative) analyzer that resolves SQL plans in a single bottom-up traversal.
Key changes:
**New infrastructure:**
- `OperatorResolutionContext` and `OperatorResolutionContextStack` for tracking operator-level state
during resolution (HAVING tracking, subquery aggregate push-down, grouping analytics)
- `NameResolutionParameters` for bundling name resolution flags (LCA access, hidden output, view
resolution, extract value keys, etc.)
- `ResolverGuardResult` structured result type replacing boolean return from `ResolverGuard`
- `NonDeterministicExpressionCheck` as a single-pass-only resolution check
- `RetainsOriginalJoinOutput` trait for preserving join output when metadata columns change child
projections
- `AliasKind` enum for distinguishing alias types during resolution
- `TryExtractOrdinal` utility for ordinal extraction from expressions
**Core improvements:**
- Extended `ExpressionResolutionContext` with window expression tracking (nestedness level, window
function/spec flags, parent context)
- Enriched `NameScope` with variable resolution, extract value extraction keys, aggregate expression
alias lookup, and hidden output improvements
- Improved `HavingResolver` to handle aggregate expressions extracted from subqueries and window +
HAVING interaction patterns
- Extended `ExpressionIdAssigner` with subquery expression ID remapping and outer reference mapping
- Expanded `ResolverGuard` to support lambda functions, star-with-target, regex columns, COALESCE with
star, and multi-part TVF names
- Moved plan rewrite rules (`CleanupAliases`, `PullOutNondeterministic`, `PruneMetadataColumns`) from
`ResolverRunner` to `Resolver.lookupMetadataAndResolve` for correct per-view config handling
- Improved `HybridAnalyzer` tentative mode with comprehensive fallback handling
- Various improvements to aggregate resolution, sort resolution, join resolution, set operation
resolution, and subquery expression resolution
### Why are the changes needed?
To bring the Apache Spark single-pass analyzer closer to feature parity with the fixed-point analyzer implementation, enabling:
1. Correct resolution of window expressions, HAVING clauses with windows, and complex aggregate
patterns
2. Proper operator-level context tracking during resolution
3. Better name resolution with variable support, extract value keys, and hidden output handling
4. Structured guard results for cleaner tentative mode fallback logic
5. Foundation for future features like nested correlated subquery support
### Does this PR introduce _any_ user-facing change?
No. The single-pass analyzer is behind feature flags (`spark.sql.analyzer.singlePassResolver.enabled`
and `spark.sql.analyzer.singlePassResolver.enabled.tentatively`) and is not the default code path.
### How was this patch tested?
- Extended `HybridAnalyzerSuite` with `testDualRun` framework covering dual-run, tentative, and
single-pass modes
- New `DataFrameAnalyzerTestGapsSuite` for alias resolution edge cases (implicit aliases, nested alias
collapsing, autogenerated alias names)
- New `SinglePassAnalyzerTestUtils` test utility trait
- Updated `ResolverGuardSuite` with structured result assertions and new feature tests
(star-with-target, regex columns, COALESCE with star, multi-part TVF names)
- Updated `ExplicitlyUnsupportedResolverFeatureSuite` with generator edge case tests
- Updated `ExpressionIdAssignerSuite` for new attribute reference mapping semantics and subquery
remapping
- Updated `NameScopeSuite` with variable resolution and extract value key tests
- Updated `AggregateResolverSuite`, `AliasResolverSuite`, `MetadataResolverSuite`, `ViewResolverSuite`
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #54729 from mihailotim-db/resolver-pr1-core.
Authored-by: Mihailo Timotic <[email protected]>
Signed-off-by: Daniel Tenedorio <[email protected]>1 parent 5acd8e6 commit d06d086
File tree
77 files changed
+4992
-1747
lines changed- common/utils/src/main/resources/error
- sql
- catalyst/src
- main/scala/org/apache/spark/sql
- catalyst/analysis/resolver
- errors
- test/scala/org/apache/spark/sql/catalyst/analysis/resolver
- core/src/test/scala/org/apache/spark/sql/analysis/resolver
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
77 files changed
+4992
-1747
lines changedLines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2476 | 2476 | | |
2477 | 2477 | | |
2478 | 2478 | | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
2479 | 2486 | | |
2480 | 2487 | | |
2481 | 2488 | | |
| |||
Lines changed: 120 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
| |||
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
42 | | - | |
43 | | - | |
44 | | - | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
51 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
52 | 63 | | |
53 | 64 | | |
54 | 65 | | |
| |||
76 | 87 | | |
77 | 88 | | |
78 | 89 | | |
79 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
80 | 129 | | |
81 | | - | |
| 130 | + | |
| 131 | + | |
82 | 132 | | |
83 | 133 | | |
84 | 134 | | |
85 | | - | |
86 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
87 | 159 | | |
88 | | - | |
| 160 | + | |
89 | 161 | | |
90 | 162 | | |
91 | 163 | | |
92 | 164 | | |
93 | 165 | | |
94 | 166 | | |
95 | 167 | | |
96 | | - | |
97 | | - | |
98 | 168 | | |
99 | 169 | | |
100 | 170 | | |
| |||
108 | 178 | | |
109 | 179 | | |
110 | 180 | | |
111 | | - | |
| 181 | + | |
112 | 182 | | |
113 | 183 | | |
114 | 184 | | |
115 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
116 | 192 | | |
117 | 193 | | |
118 | 194 | | |
119 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
120 | 199 | | |
121 | 200 | | |
122 | 201 | | |
123 | 202 | | |
124 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
125 | 206 | | |
126 | 207 | | |
127 | 208 | | |
| |||
145 | 226 | | |
146 | 227 | | |
147 | 228 | | |
148 | | - | |
149 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
150 | 232 | | |
151 | 233 | | |
152 | 234 | | |
| |||
202 | 284 | | |
203 | 285 | | |
204 | 286 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
214 | 292 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
219 | 308 | | |
220 | 309 | | |
221 | 310 | | |
| |||
236 | 325 | | |
237 | 326 | | |
238 | 327 | | |
| 328 | + | |
239 | 329 | | |
0 commit comments