Skip to content

more TIME_NS support#19606

Closed
jraymakers wants to merge 4 commits intoduckdb:mainfrom
motherduckdb:jray/more-time-ns-support
Closed

more TIME_NS support#19606
jraymakers wants to merge 4 commits intoduckdb:mainfrom
motherduckdb:jray/more-time-ns-support

Conversation

@jraymakers
Copy link
Contributor

@jraymakers jraymakers commented Nov 2, 2025

A v1.4-andium version of this PR is here: #19613


While attempting to add support for the relatively new TIME_NS logical type in Node Neo, I found some places where it was not fully supported. This is an attempt to support this type in more contexts. This doesn't cover everything, but should be a step forward.

Areas affected:

  • Appender
  • Arrow conversion
    • I added what I think should be necessary for TIME_NS to work in Arrow, but the arrow_roundtrip tests still fail. I'm unsure why. I excluded the time_ns column from the tests for now. I welcome ideas of how to make this work, because it will likely be necessary for TIME_NS to work in DuckDB Wasm.
  • C API
    • These are the key changes needed to support TIME_NS in the C API, and thus Node Neo (and other clients).
  • Miscellaneous type functions
    • includes: isTemporal, toSQLString, DuckDBTypesFunction, TypesMatch, CastIsInvertible
  • Shell
  • test_all_types
    • Adding a time_ns column to test_all_types required changing the expected values in several tests.

I tried to update the parquet extension to support TIME_NS, but was unable to make it work. I've excluded the time_ns column of test_all_types from the parquet tests that use it (following the pattern of several other unsupported types).

There are likely other places that should support TIME_NS, such as various casts, several aggregate functions, and the CSV reader. I didn't attempt to update these areas.

FYI @hawkfish

return;
#endif
TestArrowRoundtrip("SELECT * EXCLUDE(bit,time_tz, bignum) REPLACE "
TestArrowRoundtrip("SELECT * EXCLUDE(bit, time_ns, time_tz, bignum) REPLACE "
Copy link
Contributor

Choose a reason for hiding this comment

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

You need this patch to get time_ns to pass:

diff --git a/src/function/table/arrow/arrow_duck_schema.cpp b/src/function/table/arrow/arrow_duck_schema.cpp
index ab5611c13a..f722a5df09 100644
--- a/src/function/table/arrow/arrow_duck_schema.cpp
+++ b/src/function/table/arrow/arrow_duck_schema.cpp
@@ -370,6 +370,18 @@ LogicalType ArrowType::GetDuckType(bool use_dictionary) const {
 		}
 		return LogicalType::UNION(std::move(new_children));
 	}
+	case LogicalTypeId::TIME: {
+		auto time_info = type_info->Cast<ArrowDateTimeInfo>();
+		if (type.id() == LogicalTypeId::TIME) {
+			switch (time_info.GetDateTimeType()) {
+				case ArrowDateTimeType::NANOSECONDS:
+					return LogicalType::TIME_NS;
+				default:
+					return type;
+			}
+		}
+		return type;
+	}
 	default: {
 		if (extension_data) {
 			return extension_data->GetDuckDBType();

I haven't tested whether this breaks anything else, but it shouldn't
If it does, we can leave it skipped for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip - I found an even simpler change to this file (where the type for the "ttn" format is defined) that fixes this case. I was able to remove the time_ns exclusion, as well as all the other (existing) type exclusions, from the arrow_roundtrip test and have it pass!

@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 2, 2025 17:50
@jraymakers jraymakers changed the base branch from main to v1.4-andium November 2, 2025 17:50
@jraymakers jraymakers changed the base branch from v1.4-andium to main November 2, 2025 17:51
@jraymakers
Copy link
Contributor Author

It occurs to me that this change should have been submitted against v1.4-andium instead of main. I'll work on getting a similar PR up for that branch.

In the meantime, I could use some help fixing the failing "Forwards compatibility tests". It looks like the tests are trying to load a database containing a table created with the latest test_all_types(), which includes TIME_NS, on old DuckDB versions, which of course don't understand TIME_NS. I'm not sure what should be done about this. Perhaps the table in question should be created with an exclusion for the time_ns column? But I wasn't sure which code creates this table.

@jraymakers jraymakers marked this pull request as ready for review November 2, 2025 18:49
@jraymakers
Copy link
Contributor Author

Here's the v1.4-andium version of this change: #19613

@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 4, 2025 07:39
@jraymakers jraymakers marked this pull request as ready for review November 4, 2025 07:45
@jraymakers
Copy link
Contributor Author

It's probably best if the v1.4-andium version of this PR is reviewed & merged instead, but I wanted to fix this one up in case that's not an option.

@lnkuiper lnkuiper requested a review from pdet November 7, 2025 12:28
@jraymakers jraymakers force-pushed the jray/more-time-ns-support branch from 690b0a6 to fc6c851 Compare November 12, 2025 00:33
@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 12, 2025 00:34
@jraymakers
Copy link
Contributor Author

Based on the conversation in the v1.4-andium version of this PR, I'm reviving this one (against main) with some of the improvements made there.

@jraymakers jraymakers marked this pull request as ready for review November 12, 2025 00:36
@jraymakers jraymakers force-pushed the jray/more-time-ns-support branch from fc6c851 to cb73c6e Compare November 21, 2025 03:04
@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 21, 2025 03:05
@jraymakers jraymakers marked this pull request as ready for review November 21, 2025 03:05
@jraymakers jraymakers requested a review from Tishj November 21, 2025 03:05
@jraymakers
Copy link
Contributor Author

@pdet @Tishj Any further comments on this PR?

@lnkuiper
Copy link
Collaborator

lnkuiper commented Jan 2, 2026

@pdet Could you have another look at this PR? I think we still want this for compatibility. There is a merge conflict due to the shell rework, but that should be easy to fix.

@pdet
Copy link
Collaborator

pdet commented Jan 2, 2026

Yeah, I'll pick it up!

@pdet pdet mentioned this pull request Jan 2, 2026
@pdet pdet closed this Jan 2, 2026
pdet added a commit that referenced this pull request Jan 7, 2026
Picking up #19606, solving merge
conflict, and removing unnecessary exclusions of `time_ns` type.

We are still missing the tests for the different precision types of
`TIME`, these should be added in our Python client after this code gets
merged, as we need arrow to produce these precision types.
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.

5 participants