Commit 7bcb613
fix sqrt(-1.0::float8) should error, not return NaN (apache#22308)
## Which issue does this PR close?
- Closes apache#22260.
## Rationale for this change
DataFusion previously returned `NaN` for `sqrt` on negative
floating-point inputs, for example `sqrt((-1.0)::float8)`. This differs
from PostgreSQL semantics, which raise an error for square root of a
negative number.
This change makes `sqrt` return an execution error for out-of-domain
negative inputs so its behavior is closer to PostgreSQL and avoids
silently producing `NaN` for invalid inputs.
## What changes are included in this PR?
- Updated the unary math UDF helper to support an optional validator
callback for runtime input validation.
- Switched `sqrt` to use a named validator helper instead of inline
predicate and error-string arguments.
- Added runtime validation for `sqrt` so negative inputs now raise
`cannot take square root of a negative number`.
- Updated sqllogictests for `sqrt`:
- negative literal inputs now expect an error
- negative column inputs now expect an error
- positive column coverage was retained using in-domain inputs
## Are these changes tested?
Yes.
The change is covered by existing SQL logic tests and targeted
validation runs:
- `cargo test -p datafusion-functions sqrt`
- `cargo test -p datafusion-sqllogictest --test sqllogictests scalar`
## Are there any user-facing changes?
Yes.
`sqrt` now raises an execution error for negative inputs instead of
returning `NaN`. This changes user-visible query behavior to better
align with PostgreSQL semantics.
---------
Co-authored-by: Copilot <copilot@github.com>1 parent 7ad8e2c commit 7bcb613
3 files changed
Lines changed: 66 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
213 | 224 | | |
214 | 225 | | |
215 | 226 | | |
| |||
218 | 229 | | |
219 | 230 | | |
220 | 231 | | |
| 232 | + | |
221 | 233 | | |
222 | 234 | | |
223 | 235 | | |
| |||
280 | 292 | | |
281 | 293 | | |
282 | 294 | | |
283 | | - | |
284 | | - | |
| 295 | + | |
| 296 | + | |
285 | 297 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
290 | 313 | | |
291 | | - | |
292 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
293 | 327 | | |
294 | 328 | | |
295 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
45 | 54 | | |
46 | 55 | | |
47 | 56 | | |
| |||
208 | 217 | | |
209 | 218 | | |
210 | 219 | | |
211 | | - | |
| 220 | + | |
| 221 | + | |
212 | 222 | | |
213 | 223 | | |
214 | 224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
1110 | | - | |
| 1110 | + | |
1111 | 1111 | | |
1112 | | - | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
1113 | 1115 | | |
1114 | | - | |
1115 | | - | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
1116 | 1120 | | |
1117 | 1121 | | |
1118 | 1122 | | |
| |||
1128 | 1132 | | |
1129 | 1133 | | |
1130 | 1134 | | |
1131 | | - | |
| 1135 | + | |
1132 | 1136 | | |
1133 | | - | |
1134 | | - | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
1135 | 1141 | | |
1136 | 1142 | | |
1137 | 1143 | | |
| |||
0 commit comments