Repository navigation
fix: Fail on infinite and out-of-range time values instead of storing garbage - #623
Conversation
Superseded: Accepted limitationsThree review rounds. The first found a Medium: the
Generated by Claude Code |
…NULL` Closes #613. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
…e = TRUE` `csv_quote()` now calls `time_to_finite()`, so non-finite and out-of-range Date, POSIXct, and hms values are written as `\N`. The warning is gated on `warn`, and the difftime threshold is computed in seconds. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
5eeaa55 to
4f1933b
Compare
|
Resolve conflicts. Fail instead of warning if encountering values that can't be represented. |
Resolved:
|
…g `NULL` Finite `POSIXct`, `hms`, `difftime`, and `Date` values beyond the 64-bit microsecond range now raise an error that names the affected columns, in `dbBind()`, `sqlData()`, and writes with `load_data_local_infile = TRUE`. Infinite values are still written as `NULL` without a warning. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
… error Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
|
Done in 1db2f5d, ac7369f and 1695af2. The conflicts with Generated by Claude Code |
Superseded: Accepted limitationsThree review rounds before the requested change. The first found a Medium: the
Generated by Claude Code |
|
Implement strict variant here, stacked PR for breaking changes in existing behavior. |
Infinite `POSIXct`, `hms`, `difftime`, and `Date` values now raise an error that names the affected columns, in `dbBind()`, `sqlData()`, and writes with `load_data_local_infile = TRUE`, instead of being written as `NULL`. Missing values are still written as `NULL`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Superseded: Accepted limitationsThree review rounds before the requested changes, with two Mediums fixed. The change to an error for values out of range had a clean review of its own, which found nothing above Low. So did the change to fail on
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
| stopc("Cannot specify `field.types` with `append = TRUE`") | ||
| } | ||
|
|
||
| # Fail on values that can't be written before the old table is dropped: |
There was a problem hiding this comment.
Accept the dropped old table, don't compute twice.
There was a problem hiding this comment.
Done in 1c704b8: dbWriteTable() computes the data only once again, and the test that kept the old table is gone. A time value that can't be represented now fails after overwrite = TRUE has dropped the old table, like any other write error. #636 has the same change through the merge in 76d0d12. Its own numeric check also runs only in that single pass.
Generated by Claude Code
An out-of-range time value now fails after an `overwrite = TRUE` has dropped the old table, as other write errors already do. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Accepted limitationsThree review rounds before the requested changes, with two Mediums fixed. The change to an error for values out of range had a clean review of its own, which found nothing above Low. So did the change to fail on
Generated by Claude Code |
|
Adjust PR titles in the stack. |
POSIXct and hms values as NULL|
Done. This PR is now "fix: Fail on infinite and out-of-range time values instead of storing garbage". The old title still said the values were bound as Generated by Claude Code |
Closes #613, closes #627.
Before this change,
Inf,-Infand huge time values were bound without a check, and the server stored garbage (0000-00-00 00:00:00, orTIMEvalues that depend on the client library). The conversion in C++ was undefined behavior for these values.Datevalues were affected too:Infwas stored as0000-00-00.Change
sql_data()calls a newtime_to_finite()inR/coerce.R, afterposixlt_to_posixct().csv_quote()inR/table.Rcalls it too, so theload_data_local_infile = TRUEpath fails on infinite and out-of-range values, as binding does. That path also convertsPOSIXltcolumns toPOSIXctfirst: before,dbAppendTable()treated them as list columns and wroteNULLfor every value (POSIXltcolumns are written asNULLwithload_data_local_infile = TRUE#627). There is no C++ change.Infand-InfinPOSIXct,difftime/hmsandDatefail with "Can't represent N infinite time value(s) in column(s)ts: useNAfor missing values.", as decided in the question below.NAandNaNare written asNULL. feat!: Fail on infinite numbers instead of writingNULL#636, stacked on this PR, does the same for numeric columns, which is a breaking change.POSIXct,hms/difftimeandDatevalues beyond 9.2e12 seconds can't be represented in the 64-bit microsecond count. As you asked, they now fail with an error on every write path:dbBind(),sqlData()andload_data_local_infile = TRUE. The error reads "Can't represent 1 time value(s) in column(s)ts: the absolute value must not exceed 9.2e+12 seconds." Unnamed parameters are labeled by position. The limit is checked in seconds, whatever the unit of adifftime.dbWriteTable()computes the data once, so withoverwrite = TRUEa value that can't be represented fails after the old table is dropped, like other write errors.Accepted limitations
Tests
tests/testthat/test-bind-nonfinite.R(new) coversInf,-Inf,1e13,-1e13and 0 inDATETIME(6),TIME(6)andDATE, and checks thatNAandNaNare still written asNULL. It checks the error for out-of-range values on every write path, includingsqlData(), adifftimein minutes, anddbWriteTable()anddbAppendTable()withload_data_local_infile = TRUE, where no rows are written. It also covers aPOSIXltcolumn on that path. Local run against MariaDB 10.11 withNOT_CRAN=true, beforeInfwas made to fail (the local test server is down since; CI runs the tests of the final version): the whole suite had 0 failures and the onetest-timezone.Rerror ("US/Alaska" unknown to CCTZ in this container), which also happens onmain. MySQL servers were not tested: there is no server in this container, and CI's MySQL entries currently run MariaDB (#592).Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Generated by Claude Code