Skip to content

more TIME_NS support (v1.4)#19613

Closed
jraymakers wants to merge 6 commits intoduckdb:v1.4-andiumfrom
motherduckdb:jray/more-time-ns-support-v1.4
Closed

more TIME_NS support (v1.4)#19613
jraymakers wants to merge 6 commits intoduckdb:v1.4-andiumfrom
motherduckdb:jray/more-time-ns-support-v1.4

Conversation

@jraymakers
Copy link
Contributor

#19606 rebased to v1.4-andium.

Differences:

  • No changes to Shell required (relevant code is only in main).
  • Some tests that only exist in main (parquet/variant) didn't need changes in this PR.
  • Some (straightforward) fixes were needed to variant conversion in this branch.

@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 4, 2025 07:16
@jraymakers jraymakers marked this pull request as ready for review November 4, 2025 07:17
@pdet pdet self-requested a review November 5, 2025 09:41
Copy link
Collaborator

@pdet pdet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jraymakers thanks for the PR, is looking good!

Just had a couple minor comments.

Comment on lines +251 to +264
// time_ns columns
REQUIRE_NO_FAIL(tester.Query("CREATE TABLE time_ns_values(d TIME_NS)"));
REQUIRE_NO_FAIL(tester.Query("INSERT INTO time_ns_values VALUES ('12:34:56.789123456'), (NULL), ('12:34:56')"));

result = tester.Query("SELECT * FROM time_ns_values ORDER BY d");
REQUIRE_NO_FAIL(*result);
REQUIRE(result->IsNull(0, 0));
duckdb_time_ns time_ns_val = result->Fetch<duckdb_time_ns>(0, 1);
REQUIRE(time_ns_val.nanos == 45296000000000);
REQUIRE(result->Fetch<string>(0, 1) == Value::TIME_NS(dtime_ns_t(45296000000000)).ToString());
time_ns_val = result->Fetch<duckdb_time_ns>(0, 2);
REQUIRE(time_ns_val.nanos == 45296789123456);
REQUIRE(result->Fetch<string>(0, 2) == Value::TIME_NS(dtime_ns_t(45296789123456)).ToString());

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests for the other conversion values as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which other conversion values are you referring to? I tried to cover all the same cases as the similar code above, testing TIME.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR implements the conversion for many different precisions, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I assume you mean the new case for TIME_NS I added to ColumnArrowToDuckDB.

It's true this case, like the one for TIME it is patterned after, implements conversions from all four precision levels defined by Arrow (second, millisecond, microsecond, and nanosecond). But, since DuckDB only writes microseconds for TIME, and (now) nanoseconds for TIME_NS, it's not clear to me how to exercise the other code paths. The existing "Arrow roundtrip" test infrastructure can only converts from Arrow to DuckDB what is converted from DuckDB to Arrow, and I'm not aware of any way to generate the second or millisecond precision levels through this path. There don't appear to be any existing tests for these paths for TIME.

With some effort, it might be possible to write additional test infrastructure that could test non-roundtrip Arrow conversions, such as writing microseconds (using TIME) and then reading nanoseconds (using TIME_NS), or vice versa. But I don't feel confident in my ability to implement that infrastructure; in this PR, I'm just trying to plug some gaps in TIME_NS support by closely following existing patterns for TIME.

@jraymakers jraymakers force-pushed the jray/more-time-ns-support-v1.4 branch from f7be3d5 to 0bb38f4 Compare November 7, 2025 19:59
@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 7, 2025 19:59
@jraymakers jraymakers marked this pull request as ready for review November 7, 2025 20:00
@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 7, 2025 20:05
@jraymakers jraymakers marked this pull request as ready for review November 7, 2025 20:05
@jraymakers
Copy link
Contributor Author

@pdet Thanks for the review. I'd love to get this in for 1.4.2 (scheduled for next week), to unblock TIME_NS support in Node Neo (and other users of the C API). Let me know if you think the remaining issue about the test coverage of Arrow conversions for other precision levels is a blocker, or whether it can wait for later.

case VariantLogicalType::TIME_NANOS: {
auto val = Value::TIME_NS(Load<dtime_ns_t>(ptr));
auto val_str = val.ToString();
return yyjson_mut_strncpy(doc, val_str.c_str(), val_str.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is untested, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is covered by test/sql/types/variant/test_all_types.test. Without this addition, that test (now) fails with INTERNAL Error: VariantLogicalType(21) not handled, because of the addition of time_ns to test_all_types (in this PR).


statement ok
CREATE TABLE all_types AS SELECT * FROM test_all_types();
CREATE TABLE all_types AS SELECT * EXCLUDE(time_ns) FROM test_all_types();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think just excluding it is the right move

@pdet
Copy link
Collaborator

pdet commented Nov 10, 2025

Hi @jraymakers, after chatting with @Tishj, the basic conclusion is that we need to remove all test exclusions of time_ns, and that the remaining missing tests are a blocker, especially for the release of a minor version.

As it stands, there are untested code paths with potential undesirable side effects.

@jraymakers
Copy link
Contributor Author

jraymakers commented Nov 10, 2025

I hear you that the exclusions are not desirable. They were not my first choice; I added them because I couldn't figure out another path forward.

I want to point out that the exclusions don't reduce test coverage. They are only necessary because of the change in this PR that adds a time_ns column to test_all_types. Today, there is no such column. So the exclusions simply maintain the status quo, for the subset of tests that can't handle the new type, and for which this is not clear (to me) how to fix.

Here are some possible paths forward:

  • Help me understand how to avoid the test exclusions while maintaining the functionality (i.e. the time_ns column in test_all_types). The challenge (as I understand it) is the relevant tests are BWC tests, and this column doesn't exist in the old versions but does in the new ones.
  • Merge this PR as-is, with the exclusions that maintain test coverage at (no less than) current levels, and work on improving both TIME_NS support (e.g. in conversions and aggregate functions) and TIME_NS test coverage in future PRs.
  • Split this PR into parts, so the most critical pieces, which fix the broken TIME_NS type in both the C API and Arrow conversion (and hence Wasm), can be merged for 1.4.2, without the addition of time_ns to test_all_types.

I'm open to any of these paths, but I'm doubtful I'll be unable to accomplish the first on my own.

@jraymakers
Copy link
Contributor Author

jraymakers commented Nov 10, 2025

Note that my reason for expanding the scope of this PR to include the addition to test_all_types was to increase test coverage, because so many existing tests use test_all_types, including the Arrow roundtrip tests. If I split the PR, it would be hard to achieve the same level of coverage in each part without the addition to test_all_types.

@pdet
Copy link
Collaborator

pdet commented Nov 11, 2025

Note that my reason for expanding the scope of this PR to include the addition to test_all_types was to increase test coverage, because so many existing tests use test_all_types, including the Arrow roundtrip tests. If I split the PR, it would be hard to achieve the same level of coverage in each part without the addition to test_all_types.

Hi @jraymakers, I think your reasoning makes perfect sense. Either @Tishj or I can pick it up and fix the test for all types.

The last thing is that it’s not possible to get this PR into v1.4.2, considering it’s a feature and we still need to implement the aforementioned missing tests first. I understand it’s necessary for TIME_NS support in Node Neo, but again, this is not a bug, and we should refrain from adding features in minor releases.

I think the way to move forward is to get your latest changes to #19606, close this PR and continue from there.

@jraymakers
Copy link
Contributor Author

jraymakers commented Nov 11, 2025

I'd argue there is a bug, or several:

  • Running select '00:00:00'::time_ns::variant; in the CLI results in INTERNAL Error: VariantLogicalType(21) not handled.
  • Running select '00:00:00'::time_ns; in DuckDB Wasm (e.g. https://shell.duckdb.org/) results in {"exception_type":"Not implemented","exception_message":"Unsupported Arrow type TIME_NS"}.
  • Any query returning a TIME_NS will run into problems in the C API because it doesn't handle that type. (In Node Neo, this manifests as Error: Unexpected type id: 0.)

But, it's your call, and I can understand how adding a new column to test_all_types in a patch release could be disruptive. I'll port my changes over to the main PR so we can move forward.

@jraymakers
Copy link
Contributor Author

I've updated the main version of this PR: #19606

@pdet
Copy link
Collaborator

pdet commented Nov 14, 2025

Thanks @jraymakers I'll close this one for now in favor of #19606
I'll have a look on the missing tests next week!

@pdet pdet closed this Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants