duckdb: [Java] Regression in conversion of Long to Timestamp value via appender

What happens?

In 0.3.3, DuckDBAppender.append(long) could be used to append a millisecond value to be converted to a timestamp in the resulting table.

As of 0.4.0, appending the value fails with an exception:

Not implemented Error: Unimplemented type for cast (INT64 -> TIMESTAMP)
java.sql.SQLException: Not implemented Error: Unimplemented type for cast (INT64 -> TIMESTAMP)
	at org.duckdb.DuckDBNative.duckdb_jdbc_appender_append_long(Native Method)
	at org.duckdb.DuckDBAppender.append(DuckDBAppender.java:47)

To Reproduce

In 0.4.0 the test fails with the above error, but in 0.3.3 it passes successfully.

  TimeZone currentTimeZone = TimeZone.getDefault();
    try {
      TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

      DuckDBConnection connection = getConnection();
      executeOnConnection(connection, "CREATE TABLE ts_test(ts_value timestamp)");

      Instant instant = Instant.now().truncatedTo(ChronoUnit.MILLIS);

      try (DuckDBAppender appender = connection.createAppender("main", "ts_test")) {
        appender.beginRow();
        appender.append(instant.toEpochMilli() * 1000);
        appender.endRow();
      }

      Statement resultStatement = connection.createStatement();
      ResultSet resultSet = resultStatement.executeQuery( "SELECT ts_value from ts_test");

      resultSet.next();

      Timestamp appendedTimestamp = resultSet.getTimestamp(1);
      assertEquals(instant.toEpochMilli(), appendedTimestamp.toInstant().toEpochMilli());

      resultSet.close();
      resultStatement.close();
      connection.close();
    } finally {
      // return timezone back to default.
      TimeZone.setDefault(currentTimeZone);
    }

Environment (please complete the following information):

  • OS: Mac OS X (Apple Silicon)
  • DuckDB Version: 0.4.0
  • DuckDB Client: JDBC

Identity Disclosure:

  • Full Name: Jonathan Swenson
  • Affiliation: Omni

Before Submitting

  • Have you tried this on the latest master branch?
  • Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Any workaround for inserting timestamps through the appender? 0.6.1 is returning the following error when trying to insert the time as microseconds double

Not implemented Error: Unimplemented type for cast (INT64 -> INT64)

I like the appendTimestampMicros and appendTimestamp that both call a private appendTimestampInternal that could create and append the appropriate timestamp_t value.

That sounds good to me.

You’d rather a distinct, purpose specific class for each of these? DuckDBAppenderTimestamp / Date / Time or something to that tune? The time classes are a bit of a nightmare, but I could definitely see the argument for using Instant or java.sql.Timestamp (especially because this IS kind of a jdbc driver).

It would not need to be restricted only to the Appender, but indeed these classes might not be used for anything else in the JDBC. Accepting Java classes seems like a good idea regardless.