Commit b370df5
authored
fix(isthmus): use Substrait type system when building Calcite RelBuilder (#973)
When converting Substrait to Calcite, the `RelBuilder` was created via
`RelBuilder.create(Frameworks...)` without specifying a type system, so
its internal `RexBuilder` used Calcite's default type system (max
decimal precision 19) while the converted expressions carried
`SubstraitTypeSystem` types (precision 38). `RelBuilder.project` runs
`RexSimplify` by default; with the mismatched type system it re-derived
decimal arithmetic at precision 19 and then wrapped the result in a
preserving `CAST(... AS DECIMAL(38,0))` to keep the declared type.
For TPC-H queries 8 and 14 this surfaced as the numerator `SUM(CAST(CASE
... AS DECIMAL(19,0)))` while the denominator was left uncast. In
PostgreSQL, where the `DECIMAL` columns are arbitrary-precision
`NUMERIC`, the cast truncated the fractional values in the numerator
only, so the round-tripped SQL produced different results from the
reference. This was latent until Calcite 1.42, which changed
`RelDataTypeSystemImpl` so the max numeric precision/scale are derived
from `getMaxPrecision(DECIMAL)`/`getMaxScale(DECIMAL)`.
## Changes
- Build the Substrait-to-Calcite `RelBuilder` with the Substrait type
system, exposed via a new `ConverterProvider.getTypeSystem()` accessor
(derived from the type factory so the two never disagree).
- `SubstraitTypeSystem` gains a public no-arg constructor because
Calcite's `Frameworks`/Avatica machinery re-instantiates the type system
from its class name when it is supplied to a `FrameworkConfig`.
- Removed queries 8 and 14 from the integration test's expected-failures
list, and dropped the now-empty expected-failures code path.
## Testing
- `./gradlew :isthmus:test` — all unit tests pass.
- `./gradlew :isthmus:integrationTest` — all 22 TPC-H queries (including
8 and 14) now produce results matching the reference SQL in PostgreSQL.
Closes #954
Closes #955
🤖 Generated with AI1 parent b07d8a3 commit b370df5
4 files changed
Lines changed: 36 additions & 21 deletions
File tree
- isthmus/src
- main/java/io/substrait/isthmus
- test/java/io/substrait/isthmus/integration
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
332 | 333 | | |
333 | 334 | | |
334 | 335 | | |
335 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
336 | 341 | | |
337 | 342 | | |
338 | 343 | | |
| |||
346 | 351 | | |
347 | 352 | | |
348 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
349 | 367 | | |
350 | 368 | | |
351 | 369 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| |||
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
37 | 45 | | |
38 | 46 | | |
39 | 47 | | |
| |||
Lines changed: 6 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 41 | | |
46 | 42 | | |
47 | 43 | | |
| |||
126 | 122 | | |
127 | 123 | | |
128 | 124 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
143 | 131 | | |
144 | 132 | | |
145 | 133 | | |
| |||
0 commit comments