-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
ARROW-16660: [C#] Add support for Time32Array and Time64Array #13279
Conversation
Hey, not sure who the maintainers are that look at the C# implementation, but I saw @eerhardt @HashidaTKS being tagged on a closed PR for C#. Can you please review/ suggest people for reviews? |
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.
Thank you for your pull request!
I have commented on the details.
If these were addressed, this patch looks good to me.
@@ -47,6 +47,8 @@ public static RecordBatch CreateSampleRecordBatch(int length, int columnSetCount | |||
builder.Field(CreateField(DoubleType.Default, i)); | |||
builder.Field(CreateField(Date32Type.Default, i)); | |||
builder.Field(CreateField(Date64Type.Default, i)); | |||
builder.Field(CreateField(Time32Type.Default, i)); | |||
builder.Field(CreateField(Time64Type.Default, i)); |
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 we need to delete these comments.
arrow/csharp/test/Apache.Arrow.Tests/TestData.cs
Lines 66 to 67 in 0556c8b
//builder.Field(CreateField(Time32Type.Default)); | |
//builder.Field(CreateField(Time64Type.Default)); |
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.
removed these
/// </summary> | ||
public class Time32Array : PrimitiveArray<int> | ||
{ | ||
private static readonly int seconds_in_millisecond = 1_000; |
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.
[nits]
How about directly using 1_000
instead of this field as in Time64Array
?
I think a meaning of 1_000
is clear in GetSeconds()
and GetMilliSeconds()
.
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.
made this change
/// <summary> | ||
/// The <see cref="Builder"/> class can be used to fluently build <see cref="Time64Array"/> objects. | ||
/// </summary> | ||
public class Builder : PrimitiveArrayBuilder<long, long, Time64Array, Builder> |
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.
Does Builder
need to inherit PrimitiveArrayBuilder<TFrom, TTo, TArray, TBuilder>
?
Can we directly use PrimitiveArrayBuilder<T, TArray, TBuilder>
(PrimitiveArrayBuilder<long, Time64Array, Builder>
) if ConvertTo
does nothing?
It is similar for Time32Array.Builder
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 initially played around with using Timespan which needed this, but this is not required now. I have made this change
@rishabh-rana Thanks! It looks good to me but I have no right to merge... @eerhardt Would you please merge this patch if you have no objection? |
Can you also update the following places?
|
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.
This looks pretty good, @rishabh-rana. Thanks so much for the contribution!
I just had some nit comments. I think the most important is to turn on the integration tests now that C# supports Time.
/// <param name="index">Index at which to get the date.</param> | ||
/// <returns>Returns an int, or <c>null</c> if there is no object at that index. | ||
/// </returns> | ||
public int? GetMilliSeconds(int index) |
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.
One thought I have is that we could add some helper methods for .net 6+ that gets a TimeOnly
value at each index. This doesn't need to be done in this PR, but I just wanted to get your thoughts on it.
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.
Sure, I think we can do this for Time32Array. I will raise a follow up
{ | ||
/// <summary> | ||
/// The <see cref="Time64Array"/> class holds an array of longs, where each value is | ||
/// stored as the number of seconds/ milliseconds (depending on the Time64Type) since midnight. |
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.
/// stored as the number of seconds/ milliseconds (depending on the Time64Type) since midnight. | |
/// stored as the number of microseconds/nanoseconds (depending on the Time64Type) since midnight. |
namespace Apache.Arrow | ||
{ | ||
/// <summary> | ||
/// The <see cref="Time32Array"/> class holds an array of ints, where each value is |
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.
/// The <see cref="Time32Array"/> class holds an array of ints, where each value is | |
/// The <see cref="Time32Array"/> class holds an array of <see cref="Int32" />, where each value is |
"int" and "long" are C# specific, but the xml doc is for all languages (VB, F#), so we don't use C# specific keywords in xml doc.
namespace Apache.Arrow | ||
{ | ||
/// <summary> | ||
/// The <see cref="Time64Array"/> class holds an array of longs, where each value is |
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.
/// The <see cref="Time64Array"/> class holds an array of longs, where each value is | |
/// The <see cref="Time64Array"/> class holds an array of <see cref="Int64" />, where each value is |
|
||
public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor); | ||
|
||
|
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.
extra blank space.
/// <summary> | ||
/// Get the time at the specified index as seconds | ||
/// </summary> | ||
/// <param name="index">Index at which to get the date.</param> |
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.
/// <param name="index">Index at which to get the date.</param> | |
/// <param name="index">Index at which to get the time.</param> |
/// <summary> | ||
/// Get the time at the specified index as microseconds | ||
/// </summary> | ||
/// <param name="index">Index at which to get the date.</param> |
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.
/// <param name="index">Index at which to get the date.</param> | |
/// <param name="index">Index at which to get the time.</param> |
TimeUnit.Second => value * 1_000_000_000, | ||
TimeUnit.Millisecond => value * 1_000_000, |
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.
TimeUnit.Second => value * 1_000_000_000, | |
TimeUnit.Millisecond => value * 1_000_000, |
According to
Lines 218 to 220 in 25e0dd4
/// The integer `bitWidth` depends on the `unit` and must be one of the following: | |
/// * SECOND and MILLISECOND: 32 bits | |
/// * MICROSECOND and NANOSECOND: 64 bits |
Time64 only supports micro and nano seconds
TimeUnit.Second => value * 1_000_000, | ||
TimeUnit.Millisecond => value * 1_000, |
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.
TimeUnit.Second => value * 1_000_000, | |
TimeUnit.Millisecond => value * 1_000, |
According to
Lines 218 to 220 in 25e0dd4
/// The integer `bitWidth` depends on the `unit` and must be one of the following: | |
/// * SECOND and MILLISECOND: 32 bits | |
/// * MICROSECOND and NANOSECOND: 64 bits |
Time64 only supports micro and nano seconds
|
||
public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor); | ||
|
||
|
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.
extra blank line
@eerhardt Thank you for your comments! I have resolved all and made the changes to the docs and the integration tests as you mentioned |
Add support for new time types.
@eerhardt I have added the missing implementation for the Timestamp array which was causing the integration tests to fail. Can you please approve the workflows to run and review? |
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.
This looks good to me. Thank you @rishabh-rana for the contribution!
I'm just waiting for the CI to finish successfully and then I will merge.
@eerhardt Thank you for your review! All good to merge now |
We are seeing intermittent archery failures which appear to be related to this change, I wonder if someone might be able to help look into this? Ticket here |
Implemented support without using TImespan in C# as it cannot hold values that have the resolution in microseconds & nanoseconds as specified on the Jira.