22
33internal sealed class DateTimeVectorDataReader : VectorDataReaderBase
44{
5- private static readonly Type DateTimeType = typeof ( DateTime ) ;
6- private static readonly Type DateTimeOffsetType = typeof ( DateTimeOffset ) ;
7- private static readonly Type DateOnlyType = typeof ( DateOnly ) ;
8- private static readonly Type TimeOnlyType = typeof ( TimeOnly ) ;
9-
105 internal unsafe DateTimeVectorDataReader ( void * dataPointer , ulong * validityMaskPointer , DuckDBType columnType , string columnName ) : base ( dataPointer , validityMaskPointer , columnType , columnName )
116 {
127 }
138
14- protected override T GetValidValue < T > ( ulong offset , Type targetType )
9+ protected override T GetValidValue < T > ( ulong offset )
1510 {
1611 if ( DuckDBType == DuckDBType . Date )
1712 {
1813 var ( dateOnly , isFinite ) = GetDateOnly ( offset ) ;
1914
2015 if ( ! isFinite )
2116 {
22- if ( targetType == DateTimeType || targetType == DateOnlyType )
17+ if ( typeof ( T ) == typeof ( DateTime ) || typeof ( T ) == typeof ( DateOnly ) )
2318 {
2419 ThrowInfinityDateException ( ) ;
2520 }
2621
2722 return ( T ) ( object ) dateOnly ;
2823 }
2924
30- if ( targetType == DateTimeType )
25+ if ( typeof ( T ) == typeof ( DateTime ) )
3126 {
3227 return ( T ) ( object ) ( DateTime ) dateOnly ;
3328 }
3429
35- if ( targetType == DateOnlyType )
30+ if ( typeof ( T ) == typeof ( DateOnly ) )
3631 {
3732 return ( T ) ( object ) ( DateOnly ) dateOnly ;
3833 }
@@ -44,12 +39,12 @@ protected override T GetValidValue<T>(ulong offset, Type targetType)
4439 {
4540 var timeOnly = GetTimeOnly ( offset ) ;
4641
47- if ( targetType == DateTimeType )
42+ if ( typeof ( T ) == typeof ( DateTime ) )
4843 {
4944 return ( T ) ( object ) ( DateTime ) timeOnly ;
5045 }
5146
52- if ( targetType == TimeOnlyType )
47+ if ( typeof ( T ) == typeof ( TimeOnly ) )
5348 {
5449 return ( T ) ( object ) ( TimeOnly ) timeOnly ;
5550 }
@@ -61,7 +56,7 @@ protected override T GetValidValue<T>(ulong offset, Type targetType)
6156 {
6257 var timeTz = GetTimeTz ( offset ) ;
6358
64- if ( targetType == DateTimeOffsetType )
59+ if ( typeof ( T ) == typeof ( DateTimeOffset ) )
6560 {
6661 var dateTimeOffset = new DateTimeOffset ( timeTz . Time . ToDateTime ( ) , TimeSpan . FromSeconds ( timeTz . Offset ) ) ;
6762 return ( T ) ( object ) dateTimeOffset ;
@@ -74,18 +69,18 @@ protected override T GetValidValue<T>(ulong offset, Type targetType)
7469 {
7570 DuckDBType . Timestamp or DuckDBType . TimestampS or
7671 DuckDBType . TimestampTz or DuckDBType . TimestampMs or
77- DuckDBType . TimestampNs => ReadTimestamp < T > ( offset , targetType ) ,
78- _ => base . GetValidValue < T > ( offset , targetType )
72+ DuckDBType . TimestampNs => ReadTimestamp < T > ( offset ) ,
73+ _ => base . GetValidValue < T > ( offset )
7974 } ;
8075 }
8176
82- private T ReadTimestamp < T > ( ulong offset , Type targetType )
77+ private T ReadTimestamp < T > ( ulong offset )
8378 {
8479 var timestampStruct = GetFieldData < DuckDBTimestampStruct > ( offset ) ;
8580
8681 if ( ! timestampStruct . IsFinite ( DuckDBType ) )
8782 {
88- if ( targetType == DateTimeType || targetType == DateTimeOffsetType )
83+ if ( typeof ( T ) == typeof ( DateTime ) || typeof ( T ) == typeof ( DateTimeOffset ) )
8984 {
9085 ThrowInfinityTimestampException ( ) ;
9186 }
@@ -95,12 +90,12 @@ private T ReadTimestamp<T>(ulong offset, Type targetType)
9590
9691 var ( timestamp , additionalTicks ) = timestampStruct . ToDuckDBTimestamp ( DuckDBType ) ;
9792
98- if ( targetType == DateTimeType )
93+ if ( typeof ( T ) == typeof ( DateTime ) )
9994 {
10095 return ( T ) ( object ) timestamp . ToDateTime ( ) . AddTicks ( additionalTicks ) ;
10196 }
10297
103- if ( targetType == DateTimeOffsetType )
98+ if ( typeof ( T ) == typeof ( DateTimeOffset ) )
10499 {
105100 var dateTime = timestamp . ToDateTime ( ) . AddTicks ( additionalTicks ) ;
106101 return ( T ) ( object ) new DateTimeOffset ( dateTime , TimeSpan . Zero ) ;
@@ -148,20 +143,20 @@ private object GetDate(ulong offset, Type targetType)
148143
149144 if ( ! isFinite )
150145 {
151- if ( targetType == DateTimeType || targetType == DateOnlyType )
146+ if ( targetType == typeof ( DateTime ) || targetType == typeof ( DateOnly ) )
152147 {
153148 ThrowInfinityDateException ( ) ;
154149 }
155150
156151 return dateOnly ;
157152 }
158153
159- if ( targetType == DateTimeType )
154+ if ( targetType == typeof ( DateTime ) )
160155 {
161156 return ( DateTime ) dateOnly ;
162157 }
163158
164- if ( targetType == DateOnlyType )
159+ if ( targetType == typeof ( DateOnly ) )
165160 {
166161 return ( DateOnly ) dateOnly ;
167162 }
@@ -172,12 +167,12 @@ private object GetDate(ulong offset, Type targetType)
172167 private object GetTime ( ulong offset , Type targetType )
173168 {
174169 var timeOnly = GetTimeOnly ( offset ) ;
175- if ( targetType == DateTimeType )
170+ if ( targetType == typeof ( DateTime ) )
176171 {
177172 return ( DateTime ) timeOnly ;
178173 }
179174
180- if ( targetType == TimeOnlyType )
175+ if ( targetType == typeof ( TimeOnly ) )
181176 {
182177 return ( TimeOnly ) timeOnly ;
183178 }
@@ -191,7 +186,7 @@ private object GetDateTime(ulong offset, Type targetType)
191186
192187 if ( ! timestampStruct . IsFinite ( DuckDBType ) )
193188 {
194- if ( targetType == DateTimeType || targetType == DateTimeOffsetType )
189+ if ( targetType == typeof ( DateTime ) || targetType == typeof ( DateTimeOffset ) )
195190 {
196191 ThrowInfinityTimestampException ( ) ;
197192 }
@@ -201,14 +196,14 @@ private object GetDateTime(ulong offset, Type targetType)
201196
202197 var ( timestamp , additionalTicks ) = timestampStruct . ToDuckDBTimestamp ( DuckDBType ) ;
203198
204- if ( targetType == DateTimeType )
199+ if ( targetType == typeof ( DateTime ) )
205200 {
206201 var dateTime = timestamp . ToDateTime ( ) . AddTicks ( additionalTicks ) ;
207202
208203 return dateTime ;
209204 }
210205
211- if ( targetType == DateTimeOffsetType )
206+ if ( targetType == typeof ( DateTimeOffset ) )
212207 {
213208 var dateTime = timestamp . ToDateTime ( ) . AddTicks ( additionalTicks ) ;
214209 return new DateTimeOffset ( dateTime , TimeSpan . Zero ) ;
@@ -221,7 +216,7 @@ private object GetDateTimeOffset(ulong offset, Type targetType)
221216 {
222217 var timeTz = GetTimeTz ( offset ) ;
223218
224- if ( targetType == DateTimeOffsetType )
219+ if ( targetType == typeof ( DateTimeOffset ) )
225220 {
226221 return new DateTimeOffset ( timeTz . Time . ToDateTime ( ) , TimeSpan . FromSeconds ( timeTz . Offset ) ) ;
227222 }
0 commit comments