DateTimeException: Invalid value for NanoOfDay raised when running test_all_types()

Open
#448 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java, sql
Domain
api, database

Research direction

Start with org.duckdb.DuckDBVector.getLocalTime and getObject, where the stack trace shows the failing conversion, then review the TestTimestamp boundary case in the issue. Check how SELECT TIME values 00:00:00, 24:00:00, and NULL are returned through JDBC. Done means the boundary test no longer raises DateTimeException and verifies the intended floor and ceiling behavior.

Written by the indexing model from the issue text.

Description

I found when running FROM test_all_types() the following exception was raised

Execution error (DateTimeException) at java.time.temporal.ValueRange/checkValidValue (ValueRange.java:319).
Invalid value for NanoOfDay (valid values 0 - 86399999999999): 86400000000000

java.time.temporal.ValueRange/checkValidValue (ValueRange.java:319)
java.time.temporal.ChronoField/checkValidValue (ChronoField.java:721)
java.time.LocalTime/ofNanoOfDay (LocalTime.java:410)
org.duckdb.DuckDBVector/getLocalTime (DuckDBVector.java:137)
org.duckdb.DuckDBVector/getObject (DuckDBVector.java:96)
org.duckdb.DuckDBResultSet/getObject (DuckDBResultSet.java:168)
[OMITTED APPLICATION FRAMES]
[...]

After looking at the results of SELECT time FROM test_all_types();

time
00:00:00
24:00:00
NULL

and looking at the ISO 8601 wikipedia page it looks like the ISO 8601 standard has thrashed a little bit on if 24 is a valid value for an hour.

According to the LocalTime.ofNanoOfDay(long) docs the valid range is from 0 to 24 * 60 * 60 * 1,000,000,000 - 1 which is the source of the exception being raised. I'm unfamiliar with alternative Java APIs that would conform to the current state of the 8601 spec that does allow 24 for an hour value.

Here is a test case that I think should exercise the issue with the java.time.LocalTime#onNanoOfDay(long) implementation.

public class TestTimestamp {
    public static void test_duckdb_time_boundaries() throws Exception {
        try (Connection conn = DriverManager.getConnection(JDBC_URL); Statement stmt = conn.createStatement()) {
            try (ResultSet rs = stmt.executeQuery("SELECT '00:00:00'::TIME, '24:00:00'::TIME")) {
                rs.next();
                assertEquals(rs.getTime(0), 0, "floor");
                assertEquals(rs.getTime(1), 86400000000000, "ceil");
            }
        }
    }
}
Dominant language
C++
Stars
127
Forks
80
Avg merge
13h 41m
Merged PRs (30d)
44

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from duckdb/duckdb-java

All issues in duckdb/duckdb-java

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.