Skip to content

Preserve nanoseconds when binding TIMESTAMP_NS parameters - #948

Open
hutiefang76 wants to merge 2 commits into
duckdb:mainfrom
hutiefang76:frank/duckdb571-nanos-20261024
Open

hutiefang76 wants to merge 2 commits into
duckdb:mainfrom
hutiefang76:frank/duckdb571-nanos-20261024

Conversation

@hutiefang76

@hutiefang76 hutiefang76 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #571.

Binding 2026-02-20 12:00:00.123456789 to a TIMESTAMP_NS parameter currently stores .123456000. Keep the exact epoch nanoseconds through the Java/JNI parameter conversion for Timestamp and LocalDateTime, including the Calendar timestamp overload. Literal reads already preserve nanoseconds; the new insert/read round trips exercise the affected binding path.

The conversion checks overflow and the native infinity sentinels without changing ordinary TIMESTAMP/TIMESTAMPTZ bindings or the default type of untyped parameters. Tests cover negative fractions, Calendar zones, NULL, finite bounds, rejected values and the wider microsecond date range. The existing Appender comparison is updated only where its prepared-statement row expected the old precision loss.

Validation on macOS arm64, JDK 21.0.10:

  • make release and make test: passed, 589 distinct test methods, no failures.
  • Nine focused regressions passed with both UTC and Asia/Shanghai as the JVM default timezone. Five fail against the original driver; the corrected existing Appender assertion also fails against that driver.
  • Official make format-check passed with clang-format 11.0.1.

AI assistance: Codex and DeepSeek assisted with investigation, implementation, tests and review. The native build and test results above were executed locally. The previous head passed 13 CI jobs but failed the Graal native runtime smoke test because the new JNI class lacked reachability metadata. This follow-up registers it and extends that smoke test with nanosecond binding assertions. CI for the updated head remains to be verified.

Graal follow-up validation:

  • GraalVM CE 25.0.2, Linux aarch64: rebuilt and ran the official native-image smoke runner with the published head’s successful ARM64 CI JAR. The baseline fails at startup with NoClassDefFoundError: org/duckdb/DuckDBTimestampNS; changing only the JAR’s JNI reachability metadata makes the same final smoke test pass, including exact 123456789 nanoseconds for setTimestamp and setObject(LocalDateTime).
  • The local ARM64 harness changes only the evidence copy’s resource regex from AMD64 to ARM64 in both runs; the upstream AMD64 resource configuration is unchanged. This is local ARM64 native validation, not a claim that the failed AMD64 CI job has passed.
  • Final make release, make test (589 distinct test methods) and official clang-format 11.0.1 make format-check passed again on macOS arm64.

Keep Timestamp and LocalDateTime nanoseconds through typed prepared
parameters and JNI, including Calendar bindings. Preserve the existing
microsecond conversions for other parameter types, and reject values
that overflow the nanosecond range or coincide with infinity sentinels.

Add round-trip, boundary and compatibility regressions, and update the
existing Appender comparison that expected the old precision loss.

AI-assisted implementation and review using Codex and DeepSeek.
The startup JNI cache loads DuckDBTimestampNS even for ordinary queries. Register its class and getNanosEpoch method, and exercise Timestamp and LocalDateTime nanosecond binds in the existing native-image smoke test.

Generated-by: Codex and DeepSeek V4 Flash
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.

TIMESTAMP_NS nanoseconds are truncated

1 participant