Commit 2dbd9c7
authored
Support Non-Literal Expressions in Substrait VirtualTable Values and Improve Round-Trip Robustness (#18866)
## Which issue does this PR close?
* Closes #16276.
## Rationale for this change
This PR addresses failures in Substrait round‑trip mode where Virtual
Tables were limited to accepting only literals or aliased literals.
Several SQLLogicTests—especially those involving nested or scalar
functions such as `map()`—failed because expressions were rejected
prematurely.
Allowing expression-based rows when exporting Virtual Tables is
essential to making Substrait → DataFusion → Substrait round‑trips
stable and representative of real workloads. Fixing this improves test
coverage, unblocks Substrait integration efforts, and eliminates a major
source of round‑trip inconsistencies.
### Before
```
❯ cargo test --test sqllogictests -- --substrait-round-trip map.slt:388
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s
Running bin/sqllogictests.rs (target/debug/deps/sqllogictests-d29eafa7e841495b)
Completed 1 test files in 0 seconds External error: 2 errors in file /Users/kosiew/GitHub/datafusion/datafusion/sqllogictest/test_files/map.slt
1. query failed: DataFusion error: This feature is not implemented: Unsupported plan type: DescribeTable { schema: Schema ...
[SQL] describe data;
at /Users/kosiew/GitHub/datafusion/datafusion/sqllogictest/test_files/map.slt:43
2. query failed: DataFusion error: Substrait error: Only literal types and aliases are supported in Virtual Tables, got: ScalarFunction
[SQL] VALUES (MAP(['a'], [1])), (MAP(['b'], [2])), (MAP(['c', 'a'], [3, 1]))
at /Users/kosiew/GitHub/datafusion/datafusion/sqllogictest/test_files/map.slt:388
```
### After
```
❯ cargo test --test sqllogictests -- --substrait-round-trip map.slt:388
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.50s
Running bin/sqllogictests.rs (target/debug/deps/sqllogictests-62df8e0045f6176f)
Completed 1 test files in 0 seconds
```
## What changes are included in this PR?
* Introduces `convert_literal_rows` and `convert_expression_rows`
helpers to properly distinguish literal-only rows from expression-based
rows.
* Adds support for generating nested `Struct` expressions (Substrait
`NestedStruct`) for non-literal Virtual Table values.
* Updates `from_values` to dynamically choose between literal structs
and nested structs.
* Ensures schema consistency validation for expression-based rows.
* Adds new round‑trip test cases, including
`roundtrip_values_with_scalar_function`.
* Refactors tests to use a new `substrait_roundtrip` helper to reduce
duplication.
* Adds `LogicalPlan::DescribeTable(_)` handling in the round‑trip
engine.
## Are these changes tested?
Yes. New test coverage includes:
* A dedicated round‑trip test for scalar functions inside `VALUES`
clauses.
* Use of `substrait_roundtrip` across multiple existing tests to ensure
consistent behavior.
* Validation of expression-based row handling, alias stripping, and
schema equivalence.
## Are there any user-facing changes?
No direct API-breaking changes. The behavior of Substrait round‑trip
conversion improves and becomes more permissive regarding expressions in
Virtual Tables. This is internal to Substrait/DataFusion integration and
does not change SQL semantics or user-level APIs.
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated
content has been manually reviewed and tested.1 parent 1cc9bcd commit 2dbd9c7
File tree
3 files changed
+132
-38
lines changed- datafusion
- sqllogictest/src/engines/datafusion_substrait_roundtrip_engine
- substrait
- src/logical_plan/producer/rel
- tests/cases
3 files changed
+132
-38
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
Lines changed: 83 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
32 | 95 | | |
33 | 96 | | |
34 | 97 | | |
| |||
111 | 174 | | |
112 | 175 | | |
113 | 176 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
135 | 185 | | |
136 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
137 | 196 | | |
138 | 197 | | |
139 | 198 | | |
| |||
145 | 204 | | |
146 | 205 | | |
147 | 206 | | |
148 | | - | |
| 207 | + | |
149 | 208 | | |
150 | 209 | | |
151 | 210 | | |
| |||
Lines changed: 48 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
1266 | 1269 | | |
1267 | 1270 | | |
1268 | 1271 | | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
1269 | 1300 | | |
1270 | 1301 | | |
1271 | 1302 | | |
| |||
1449 | 1480 | | |
1450 | 1481 | | |
1451 | 1482 | | |
1452 | | - | |
1453 | | - | |
1454 | | - | |
| 1483 | + | |
1455 | 1484 | | |
1456 | 1485 | | |
1457 | 1486 | | |
| |||
1466 | 1495 | | |
1467 | 1496 | | |
1468 | 1497 | | |
1469 | | - | |
1470 | | - | |
1471 | | - | |
| 1498 | + | |
1472 | 1499 | | |
1473 | 1500 | | |
1474 | 1501 | | |
| |||
1650 | 1677 | | |
1651 | 1678 | | |
1652 | 1679 | | |
1653 | | - | |
1654 | | - | |
1655 | | - | |
| 1680 | + | |
1656 | 1681 | | |
1657 | 1682 | | |
1658 | 1683 | | |
| |||
1694 | 1719 | | |
1695 | 1720 | | |
1696 | 1721 | | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
| 1722 | + | |
1700 | 1723 | | |
1701 | 1724 | | |
1702 | 1725 | | |
| |||
1708 | 1731 | | |
1709 | 1732 | | |
1710 | 1733 | | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
1711 | 1746 | | |
1712 | 1747 | | |
1713 | 1748 | | |
| |||
1735 | 1770 | | |
1736 | 1771 | | |
1737 | 1772 | | |
1738 | | - | |
1739 | | - | |
| 1773 | + | |
1740 | 1774 | | |
1741 | 1775 | | |
1742 | 1776 | | |
| |||
0 commit comments