Skip to content

Read and bind every TIMESTAMP the engine stores - #1

Open
semihalev wants to merge 1 commit into
mainfrom
fix/timestamp-range
Open

semihalev wants to merge 1 commit into
mainfrom
fix/timestamp-range

Conversation

@semihalev

Copy link
Copy Markdown
Member

The engine after 0.5.1 stores TIMESTAMP values from year 0000 to 9999 (stoolap#1309), but the JNI layer moved a timestamp as i64 nanoseconds, which only reaches 1677-09-21 to 2262-04-11. A query that returned a far value failed as a whole, and a far parameter was refused before it reached the engine.

What changed

  • The wire format between Rust and Java carries a TIMESTAMP as seconds (i64) plus nanoseconds (u32), the way java.time.Instant holds it (jni/src/lib.rs, BulkDecoder, ParamEncoder).
  • The driver no longer has a range check of its own. The engine decides what it stores, so sub-microsecond digits outside 1680 to 2254 surface as its type error (SQLSTATE 22000).
  • README: the TIMESTAMP range, the wire format and a note that a java.sql.Timestamp before 1582-10-15 prints in the Julian calendar while holding the same instant.

Cost

Four more bytes per TIMESTAMP value, and one division less when decoding. Reading 200k timestamps measured 28 to 36 ns per row before and 29 to 32 after; a bind-and-query loop measured 983 to 985 ns before and 984 to 987 after.

Tests

  • New tests in DriverFeaturesTest and JdbcConformanceTest read and bind 1500-06-15 12:00:00.123456, 0001-01-01, 9999-12-31 23:59:59.999999 and the nanosecond edges 1680-01-01 00:00:00.000000001 and 2253-12-31 23:59:59.999999999 through the native API and JDBC, and check the engine's type error for sub-microsecond digits outside their range. All six failed before the change.
  • Against the engine on core main: 169 passed. Against the pinned 0.5.1 crate: 167 passed, 2 skipped. That engine cannot store years outside 1677 to 2262, so the two tests that store them skip there.
  • Rust: fmt, clippy with -D warnings and the unit tests pass on both engines.

The engine now stores TIMESTAMP values from year 0000 to 9999, but the JNI
layer moved a timestamp as i64 nanoseconds, which only reaches 1677 to 2262.
A query that returned a far value failed as a whole, and a far parameter was
refused before it reached the engine.

I changed the wire format between Rust and Java to seconds (i64) plus
nanoseconds (u32), the way java.time.Instant holds a time. It costs four bytes
per value and drops a division when decoding; a read of 200k timestamps and a
bind-and-query loop measured the same before and after. The engine now decides
what it stores, so sub-microsecond digits outside 1680 to 2254 surface as its
own type error.

The new tests read and bind the far values and the nanosecond edges through
the native API and JDBC. The 0.5.1 engine cannot store years outside 1677 to
2262, so the tests that store them skip there; the parameter round trips and
the type error run on both engines.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant