-
Notifications
You must be signed in to change notification settings - Fork 49
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
Support the TimeOnly and DateOnly types added in .NET 6 #424
Conversation
#if NET6_0_OR_GREATER | ||
public static void ConvertDateOnly(ReadOnlySpan<int> source, Span<DateOnly> destination) | ||
{ | ||
for (int i = 0; i < destination.Length; ++i) | ||
{ | ||
destination[i] = ToDateOnly(source[i]); | ||
} | ||
} | ||
|
||
public static void ConvertDateOnly(ReadOnlySpan<int> source, ReadOnlySpan<short> defLevels, Span<DateOnly?> destination, short definedLevel) | ||
{ | ||
for (int i = 0, src = 0; i < destination.Length; ++i) | ||
{ | ||
destination[i] = defLevels[i] != definedLevel ? default(DateOnly?) : ToDateOnly(source[src++]); | ||
} | ||
} | ||
|
||
public static void ConvertTimeOnlyMicros(ReadOnlySpan<long> source, Span<TimeOnly> destination) | ||
{ | ||
for (int i = 0; i < destination.Length; ++i) | ||
{ | ||
destination[i] = ToTimeOnlyMicros(source[i]); | ||
} | ||
} | ||
|
||
public static void ConvertTimeOnlyMicros(ReadOnlySpan<long> source, ReadOnlySpan<short> defLevels, Span<TimeOnly?> destination, short definedLevel) | ||
{ | ||
for (int i = 0, src = 0; i < destination.Length; ++i) | ||
{ | ||
destination[i] = defLevels[i] != definedLevel ? default(TimeOnly?) : ToTimeOnlyMicros(source[src++]); | ||
} | ||
} | ||
|
||
public static void ConvertTimeOnlyMillis(ReadOnlySpan<int> source, Span<TimeOnly> destination) | ||
{ | ||
for (int i = 0; i < destination.Length; ++i) | ||
{ | ||
destination[i] = ToTimeOnlyMillis(source[i]); | ||
} | ||
} | ||
|
||
public static void ConvertTimeOnlyMillis(ReadOnlySpan<int> source, ReadOnlySpan<short> defLevels, Span<TimeOnly?> destination, short definedLevel) | ||
{ | ||
for (int i = 0, src = 0; i < destination.Length; ++i) | ||
{ | ||
destination[i] = defLevels[i] != definedLevel ? default(TimeOnly?) : ToTimeOnlyMillis(source[src++]); | ||
} | ||
} | ||
#endif | ||
|
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.
I think all those methods could be internal
, but given that other converters are already public
we should probably maintain consistency.
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.
Hmm yeah the convert methods were all made public intentionally in #185. I assume the reason is that users might want to make use of these methods in their own custom converters. It does mean we have to try not to introduce breaking changes here though.
Fixes #423
This adds support for converting to and from the .NET
TimeOnly
andDateOnly
types when using the .NET 6 target. For theTimeOnly
type, I've added support for millisecond and microsecond precision, matching the existingTimeSpan
conversion behaviour.In addition, I've added two options to allow customizing the built-in
LogicalTypeFactory
class so that these types can be used by default instead of theParquetSharp.Date
andTimeSpan
types. I've made these settable properties so that they can be modified on the defaultLogicalTypeFactory
instance to allow changing the process-wide behaviour. I'd usually tend towards using immutable objects, but in this case it seems worthwhile to allow configuring this without too much boilerplate. I'm open to other suggestions on how to handle this though.We've also previously used AppContext switches to allow customizing behaviour in csproj configuration files (see #288), and it could make sense to support that here too?