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

ARROW-16660: [C#] Add support for Time32Array and Time64Array #13279

Merged
merged 7 commits into from
Jun 14, 2022

Conversation

rishabh-rana
Copy link
Contributor

@rishabh-rana rishabh-rana commented Jun 1, 2022

Implemented support without using TImespan in C# as it cannot hold values that have the resolution in microseconds & nanoseconds as specified on the Jira.

@github-actions
Copy link

github-actions bot commented Jun 1, 2022

@rishabh-rana
Copy link
Contributor Author

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?

Copy link
Contributor

@HashidaTKS HashidaTKS left a 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));
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 we need to delete these comments.

//builder.Field(CreateField(Time32Type.Default));
//builder.Field(CreateField(Time64Type.Default));

Copy link
Contributor Author

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;
Copy link
Contributor

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().

Copy link
Contributor Author

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>
Copy link
Contributor

@HashidaTKS HashidaTKS Jun 2, 2022

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

Copy link
Contributor Author

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

@HashidaTKS
Copy link
Contributor

@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?

@eerhardt
Copy link
Contributor

eerhardt commented Jun 4, 2022

Can you also update the following places?

  1. https://github.com/apache/arrow/blame/master/docs/source/status.rst#L52
  2. Remove the skip line here, so we can start covering all the datetime types in the integration tests:
    generate_datetime_case()
    .skip_category('C#'),

Copy link
Contributor

@eerhardt eerhardt left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// 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);


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

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>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// <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>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// <param name="index">Index at which to get the date.</param>
/// <param name="index">Index at which to get the time.</param>

Comment on lines 164 to 165
TimeUnit.Second => value * 1_000_000_000,
TimeUnit.Millisecond => value * 1_000_000,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TimeUnit.Second => value * 1_000_000_000,
TimeUnit.Millisecond => value * 1_000_000,

According to

arrow/format/Schema.fbs

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

Comment on lines 139 to 140
TimeUnit.Second => value * 1_000_000,
TimeUnit.Millisecond => value * 1_000,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TimeUnit.Second => value * 1_000_000,
TimeUnit.Millisecond => value * 1_000,

According to

arrow/format/Schema.fbs

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);


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

extra blank line

@rishabh-rana
Copy link
Contributor Author

@eerhardt Thank you for your comments! I have resolved all and made the changes to the docs and the integration tests as you mentioned

@rishabh-rana
Copy link
Contributor Author

@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?

Copy link
Contributor

@eerhardt eerhardt left a 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.

@rishabh-rana
Copy link
Contributor Author

@eerhardt Thank you for your review! All good to merge now

@tustvold
Copy link
Contributor

tustvold commented Jul 5, 2022

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

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

Successfully merging this pull request may close these issues.

None yet

4 participants