Skip to content
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

Merged
merged 3 commits into from
Feb 20, 2024

Conversation

adamreeve
Copy link
Contributor

Fixes #423

This adds support for converting to and from the .NET TimeOnly and DateOnly types when using the .NET 6 target. For the TimeOnly type, I've added support for millisecond and microsecond precision, matching the existing TimeSpan 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 the ParquetSharp.Date and TimeSpan types. I've made these settable properties so that they can be modified on the default LogicalTypeFactory 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?

Comment on lines +612 to +661
#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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@marcin-krystianc marcin-krystianc merged commit d531836 into G-Research:master Feb 20, 2024
30 checks passed
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.

[FEATURE REQUEST]: DateOnly and TimeOnly for the new net6 target
2 participants