Commit a8eb896
committed
fix(sql): surface division-by-zero and undefined-function errors (#216)
Two related classes of expression error silently evaluated to NULL
instead of failing the statement, letting bad queries return
plausible-looking wrong results:
- A `/` or `%` with a zero divisor folded to NULL in both the f64 and
Decimal arithmetic paths (`SqlExpr::eval`'s row-scope evaluator) and
in the `mod` scalar function. It now raises SQLSTATE 22012
(division_by_zero) at the point the divisor value is evaluated.
`SqlExpr::eval`/`eval_with_old`/`eval_with_excluded` and
`eval_function` now return `Result<Value, EvalError>` instead of
`Value`, threaded through every caller: the query evaluator's own
scan/filter/window/aggregate paths, CRDT CHECK-constraint and
transition-check validation, and every executor handler, columnar
scan, and cold-storage predicate pushdown in `nodedb` that evaluates
a row expression. CASE and COALESCE stay short-circuiting, so an
untaken branch or an already-satisfied argument never raises.
- A call to a scalar/aggregate/window function with no registered
definition fell through `eval_function`'s final
`unwrap_or(Value::Null)` and never surfaced as an error. The SQL
resolver now rejects any function name absent from
`FunctionRegistry` at plan time (SQLSTATE 42883, undefined_function)
instead of letting the call flow through to evaluate as NULL on
every row. This gate exposed collection registry gaps for function
families the runtime evaluator already supported (array-element,
ID-generation, and legacy JSON functions, plus several math,
datetime, misc, spatial, and string builtins) that would otherwise
have been wrongly rejected; those registrations are added alongside
the gate.
Adds pgwire integration coverage for both SQLSTATEs across the
document and columnar engines.1 parent 3c398eb commit a8eb896
101 files changed
Lines changed: 4005 additions & 529 deletions
File tree
- nodedb-crdt/src
- nodedb-query/src
- expr_parse
- expr
- functions
- msgpack_scan
- scan_filter
- window
- nodedb-sql/src
- functions
- builtins
- scalars
- planner
- resolver/expr
- nodedb
- src
- bridge
- control
- insert_select
- planner/context/query
- security/rls
- server
- pgwire/types
- response_translate
- trigger/batch
- data/executor
- core_loop
- enforcement
- handlers
- aggregate
- streaming
- bulk_dml
- columnar_read
- columnar_write
- document
- read
- join
- kv
- crud
- merge_orchestrated
- point
- apply_put
- timeseries/raw_scan
- transaction
- overlay
- stage_write
- engine/document
- storage
- tests
- executor_tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
88 | 99 | | |
89 | | - | |
90 | | - | |
91 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
92 | 103 | | |
93 | 104 | | |
94 | 105 | | |
95 | 106 | | |
96 | 107 | | |
97 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
98 | 119 | | |
99 | 120 | | |
100 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
37 | | - | |
38 | | - | |
39 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
40 | 56 | | |
41 | | - | |
| 57 | + | |
42 | 58 | | |
43 | 59 | | |
44 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
45 | 65 | | |
46 | 66 | | |
47 | 67 | | |
48 | 68 | | |
49 | 69 | | |
50 | 70 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
55 | 75 | | |
56 | 76 | | |
57 | 77 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
70 | 96 | | |
71 | 97 | | |
72 | 98 | | |
73 | | - | |
| 99 | + | |
74 | 100 | | |
75 | | - | |
| 101 | + | |
76 | 102 | | |
77 | 103 | | |
78 | | - | |
| 104 | + | |
79 | 105 | | |
80 | 106 | | |
81 | 107 | | |
82 | 108 | | |
83 | | - | |
| 109 | + | |
84 | 110 | | |
85 | | - | |
| 111 | + | |
86 | 112 | | |
87 | 113 | | |
88 | | - | |
| 114 | + | |
89 | 115 | | |
90 | | - | |
| 116 | + | |
91 | 117 | | |
92 | 118 | | |
93 | 119 | | |
94 | 120 | | |
95 | 121 | | |
96 | | - | |
| 122 | + | |
97 | 123 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
101 | 129 | | |
102 | 130 | | |
103 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
104 | 134 | | |
105 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
106 | 138 | | |
107 | 139 | | |
108 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
109 | 143 | | |
110 | | - | |
111 | | - | |
| 144 | + | |
| 145 | + | |
112 | 146 | | |
113 | 147 | | |
0 commit comments