Commit 90aa47e
authored
## Which issue does this PR close?
* Closes #16271.
## Rationale for this change
This change resolves a long‑standing gap in DataFusion’s Substrait
round‑trip implementation where `EmptyRelation` with
`produce_one_row=true` could not be encoded or decoded. This limitation
caused ~1800 sqllogictest cases to fail, particularly those involving
queries without a FROM clause (e.g., `SELECT 1`).
By adding full support for recognizing and producing the Substrait
VirtualTable pattern representing a “phantom row,” DataFusion can now
faithfully round‑trip logical plans that use empty relations to provide
scalar evaluation contexts. This unblocks broader Substrait
compatibility and improves consistency across logical plan conversions.
## What changes are included in this PR?
* Implement detection of the Substrait VirtualTable patterns
representing `produce_one_row` and map them to
`LogicalPlan::EmptyRelation`.
* Add `from_empty_relation` encoding logic that emits a properly
structured VirtualTable, including default literal values when
`produce_one_row=true`.
* Refactor literal row conversion into a helper (`convert_literal_rows`)
for clarity and reuse.
* Improve field‑count validation for expression‑based VirtualTables.
* Add comprehensive round‑trip test coverage:
* SELECT without FROM
* Mixed‑type EmptyRelation with phantom row
* EmptyRelation with zero rows
* Subqueries involving EmptyRelation
## Are these changes tested?
Yes. New integration tests exercise all permutations of EmptyRelation
encoding and decoding, including edge cases related to schema handling
and subqueries. These tests ensure round‑trip correctness and prevent
regressions.
## Are there any user-facing changes?
No user‑facing API changes. This PR improves Substrait interoperability
internally.
## LLM-generated code disclosure
This PR includes LLM‑generated code and comments. All generated content
has been manually reviewed and tested.
1 parent 434a23b commit 90aa47e
File tree
3 files changed
+160
-47
lines changed- datafusion/substrait
- src/logical_plan
- consumer/rel
- producer/rel
- tests/cases
3 files changed
+160
-47
lines changedLines changed: 71 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
124 | 148 | | |
125 | 149 | | |
126 | 150 | | |
127 | | - | |
128 | 151 | | |
129 | 152 | | |
130 | | - | |
131 | 153 | | |
132 | | - | |
| 154 | + | |
133 | 155 | | |
134 | 156 | | |
135 | 157 | | |
136 | | - | |
| 158 | + | |
| 159 | + | |
137 | 160 | | |
138 | | - | |
139 | | - | |
140 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
141 | 164 | | |
142 | 165 | | |
143 | 166 | | |
144 | 167 | | |
145 | 168 | | |
146 | 169 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 170 | + | |
175 | 171 | | |
176 | 172 | | |
177 | 173 | | |
| |||
226 | 222 | | |
227 | 223 | | |
228 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
229 | 265 | | |
230 | 266 | | |
231 | 267 | | |
| |||
Lines changed: 47 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
149 | 159 | | |
150 | 160 | | |
151 | 161 | | |
152 | 162 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
157 | 196 | | |
158 | 197 | | |
159 | 198 | | |
160 | | - | |
| 199 | + | |
161 | 200 | | |
162 | 201 | | |
163 | 202 | | |
164 | 203 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
| 204 | + | |
169 | 205 | | |
170 | 206 | | |
171 | 207 | | |
| |||
203 | 239 | | |
204 | 240 | | |
205 | 241 | | |
| 242 | + | |
206 | 243 | | |
207 | 244 | | |
208 | 245 | | |
| |||
Lines changed: 42 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
191 | 231 | | |
192 | 232 | | |
193 | 233 | | |
| |||
0 commit comments