Skip to content

Conversation

@rynoV
Copy link
Contributor

@rynoV rynoV commented Dec 4, 2025

Closes #309

Copy link

Copilot AI left a 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 InvalidOperationException when 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.

Copy link
Owner

@Giorgi Giorgi left a comment

Choose a reason for hiding this comment

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

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));
Copy link
Owner

Choose a reason for hiding this comment

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

The Infinity dates for timestamp types are different, should we use them instead?

Image

Copy link
Contributor Author

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)

@rynoV
Copy link
Contributor Author

rynoV commented Dec 8, 2025

Can you use test_all_types() in tests?

The date and timestamp... columns only contained the min/max values, but I updated the skipped tests in DuckDBDataReaderTestAllTypes which had the arrays containing +/- infinity

@Giorgi
Copy link
Owner

Giorgi commented Dec 10, 2025

@rynoV Any ideas why Julia uses a different time for infinity timestamp?

@Giorgi Giorgi merged commit 7293cac into Giorgi:develop Dec 10, 2025
4 of 6 checks passed
@rynoV
Copy link
Contributor Author

rynoV commented Dec 10, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for 'infinity' date and timestamp

2 participants