-
-
Notifications
You must be signed in to change notification settings - Fork 87
Infinity dates+timestamps #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for infinity values in DuckDB DATE and TIMESTAMP types, closing issue #309. The implementation introduces special handling for positive and negative infinity values that DuckDB supports, ensuring they are properly represented in the .NET wrapper.
Key changes:
- Added infinity constants and detection properties to
DuckDBDateOnly,DuckDBTimestamp, and their underlying struct types - Implemented conversion methods that handle infinity values correctly when reading/writing dates and timestamps
- Added validation to throw
InvalidOperationExceptionwhen attempting to convert infinity values to standard .NET DateTime/DateOnly types - Added native bindings for DuckDB's
duckdb_is_finite_*functions
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| DuckDB.NET.Test/DuckDBInfinityTests.cs | Comprehensive test suite covering infinity date and timestamp operations, including reading, parameters, and mixed finite/infinite values |
| DuckDB.NET.Data/PreparedStatement/DuckDBTypeMap.cs | Added type mapping for DuckDBTimestamp to enable parameter binding |
| DuckDB.NET.Data/PreparedStatement/ClrToDuckDBConverter.cs | Updated conversion logic to use new infinity-aware methods |
| DuckDB.NET.Data/Extensions/DateTimeExtensions.cs | Added IsFinite extension method and updated timestamp conversions to handle infinity |
| DuckDB.NET.Data/DataChunk/Writer/DateTimeVectorDataWriter.cs | Updated writer to use infinity-aware conversion methods |
| DuckDB.NET.Data/DataChunk/Reader/DateTimeVectorDataReader.cs | Added infinity detection and validation when reading dates/timestamps |
| DuckDB.NET.Bindings/NativeMethods/NativeMethods.DateTime.cs | Added P/Invoke declarations for duckdb_is_finite_* functions |
| DuckDB.NET.Bindings/DuckDBWrapperObjects.cs | Updated to use new infinity-aware conversion methods |
| DuckDB.NET.Bindings/DuckDBTimestamp.cs | Added infinity constants, detection properties, and conversion methods |
| DuckDB.NET.Bindings/DuckDBNativeObjects.cs | Added infinity constants and detection properties to DuckDBDate and DuckDBTimestampStruct |
| DuckDB.NET.Bindings/DuckDBDateOnly.cs | Added infinity constants, detection properties, and infinity-aware conversion methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use test_all_types() in tests? https://duckdb.org/docs/stable/dev/sqllogictest/writing_tests#test_all_types-function
| public static readonly DuckDBTimestamp PositiveInfinity = | ||
| // The +infinity date value is not representable by the timestamp type, | ||
| // so this constant should never occur in normal usage | ||
| new(DuckDBDateOnly.PositiveInfinity, new DuckDBTimeOnly(0, 0, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. The values returned for test_all_types are the min/max which are separate from the infinity values, so for the infinity values I updated to use the min/max +/- one interval, where the interval is the unit of the core type in the duckdb source (days for date_t and microseconds for timestamp_t)
The |
|
@rynoV Any ideas why Julia uses a different time for infinity timestamp? |
|
I'm not sure, but it might be the "real" minimum value, as in the lowest timestamp that can be represented by the int64 value in the c++ code, whereas the value I used was the value a microsecond lower than the minimum set here, which seems to be the minimum that can actually be used without an error |

Closes #309