Commit d2b2866
committed
Replace parallel condition/result vectors with single CaseWhen vector in Expr::Case
The primary motivation for this change is to fix the visitor traversal order for CASE expressions. In SQL, CASE expressions follow a specific syntactic order (e.g., `CASE a WHEN 1 THEN 2 WHEN 3 THEN 4 ELSE 5`), AST visitors now process nodes in the same order as they appear in the source code. The previous implementation, using separate `conditions` and `results` vectors, would visit all conditions first and then all results, which didn't match the source order. The new `CaseWhen` structure ensures visitors process expressions in the correct order: `a,1,2,3,4,5`.
A secondary benefit is making invalid states unrepresentable in the type system. The previous implementation using parallel vectors (`conditions` and `results`) made it possible to create invalid CASE expressions where the number of conditions didn't match the number of results. When this happened, the `Display` implementation would silently drop elements from the longer list, potentially masking bugs. The new `CaseWhen` struct couples each condition with its result, making it impossible to create such mismatched states.
While this is a breaking change to the AST structure, sqlparser has a history of making such changes when they improve correctness. I don't expect significant downstream breakages, and the benefits of correct visitor ordering and type safety are significant, so I think the trade-off is worthwhile.1 parent b4b5576 commit d2b2866
File tree
5 files changed
+96
-51
lines changed- src
- ast
- parser
- tests
5 files changed
+96
-51
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
566 | 566 | | |
567 | 567 | | |
568 | 568 | | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
569 | 585 | | |
570 | 586 | | |
571 | 587 | | |
| |||
896 | 912 | | |
897 | 913 | | |
898 | 914 | | |
899 | | - | |
900 | | - | |
| 915 | + | |
901 | 916 | | |
902 | 917 | | |
903 | 918 | | |
| |||
1572 | 1587 | | |
1573 | 1588 | | |
1574 | 1589 | | |
1575 | | - | |
1576 | 1590 | | |
1577 | 1591 | | |
1578 | 1592 | | |
1579 | 1593 | | |
1580 | 1594 | | |
1581 | 1595 | | |
1582 | | - | |
1583 | | - | |
| 1596 | + | |
| 1597 | + | |
1584 | 1598 | | |
1585 | | - | |
1586 | 1599 | | |
1587 | 1600 | | |
1588 | 1601 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1428 | 1428 | | |
1429 | 1429 | | |
1430 | 1430 | | |
1431 | | - | |
1432 | 1431 | | |
1433 | 1432 | | |
1434 | 1433 | | |
1435 | 1434 | | |
1436 | 1435 | | |
1437 | 1436 | | |
1438 | | - | |
1439 | | - | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
1440 | 1440 | | |
1441 | 1441 | | |
1442 | 1442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1989 | 1989 | | |
1990 | 1990 | | |
1991 | 1991 | | |
1992 | | - | |
1993 | 1992 | | |
1994 | | - | |
| 1993 | + | |
1995 | 1994 | | |
1996 | | - | |
| 1995 | + | |
| 1996 | + | |
1997 | 1997 | | |
1998 | 1998 | | |
1999 | 1999 | | |
| |||
2007 | 2007 | | |
2008 | 2008 | | |
2009 | 2009 | | |
2010 | | - | |
2011 | 2010 | | |
2012 | 2011 | | |
2013 | 2012 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6257 | 6257 | | |
6258 | 6258 | | |
6259 | 6259 | | |
6260 | | - | |
6261 | | - | |
6262 | | - | |
6263 | | - | |
6264 | | - | |
| 6260 | + | |
| 6261 | + | |
| 6262 | + | |
6265 | 6263 | | |
6266 | | - | |
6267 | | - | |
6268 | | - | |
6269 | | - | |
| 6264 | + | |
| 6265 | + | |
| 6266 | + | |
| 6267 | + | |
| 6268 | + | |
| 6269 | + | |
| 6270 | + | |
| 6271 | + | |
| 6272 | + | |
| 6273 | + | |
| 6274 | + | |
| 6275 | + | |
| 6276 | + | |
| 6277 | + | |
| 6278 | + | |
6270 | 6279 | | |
6271 | | - | |
6272 | | - | |
6273 | | - | |
6274 | | - | |
6275 | | - | |
6276 | 6280 | | |
6277 | 6281 | | |
6278 | 6282 | | |
| |||
6291 | 6295 | | |
6292 | 6296 | | |
6293 | 6297 | | |
6294 | | - | |
6295 | | - | |
| 6298 | + | |
| 6299 | + | |
| 6300 | + | |
| 6301 | + | |
6296 | 6302 | | |
6297 | 6303 | | |
6298 | 6304 | | |
| |||
12992 | 12998 | | |
12993 | 12999 | | |
12994 | 13000 | | |
| 13001 | + | |
| 13002 | + | |
| 13003 | + | |
| 13004 | + | |
| 13005 | + | |
| 13006 | + | |
| 13007 | + | |
| 13008 | + | |
| 13009 | + | |
| 13010 | + | |
| 13011 | + | |
| 13012 | + | |
| 13013 | + | |
| 13014 | + | |
| 13015 | + | |
| 13016 | + | |
| 13017 | + | |
| 13018 | + | |
| 13019 | + | |
| 13020 | + | |
| 13021 | + | |
| 13022 | + | |
| 13023 | + | |
| 13024 | + | |
| 13025 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
115 | 135 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| |||
0 commit comments