-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What changes are included in this PR? Complete support for the Duration array type in the C# implementation. ### Are these changes tested? Yes. ### Are there any user-facing changes? The Duration array type is now supported in the C# library. This also does some slight refactoring of classes which could impact edge cases of user scenarios. * Closes: #38061
- Loading branch information
1 parent
cbf1bb5
commit 20e120b
Showing
27 changed files
with
465 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using Apache.Arrow.Types; | ||
|
||
namespace Apache.Arrow | ||
{ | ||
public class DurationArray : PrimitiveArray<long> | ||
{ | ||
public class Builder : PrimitiveArrayBuilder<long, DurationArray, Builder> | ||
{ | ||
public DurationType DataType { get; } | ||
|
||
public Builder(DurationType dataType) | ||
{ | ||
DataType = dataType; | ||
} | ||
|
||
protected override DurationArray Build( | ||
ArrowBuffer valueBuffer, ArrowBuffer nullBitmapBuffer, | ||
int length, int nullCount, int offset) => | ||
new DurationArray(DataType, valueBuffer, nullBitmapBuffer, length, nullCount, offset); | ||
|
||
/// <summary> | ||
/// Append a duration in the form of a <see cref="TimeSpan"/> object to the array. | ||
/// </summary> | ||
/// <param name="value">TimeSpan to add.</param> | ||
/// <returns>Returns the builder (for fluent-style composition).</returns> | ||
public Builder Append(TimeSpan value) | ||
{ | ||
Append(DataType.Unit.ConvertFromTicks(value.Ticks)); | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Append a duration in the form of a <see cref="TimeSpan"/> object to the array. | ||
/// </summary> | ||
/// <param name="value">TimeSpan to add.</param> | ||
/// <returns>Returns the builder (for fluent-style composition).</returns> | ||
public Builder Append(TimeSpan? value) => | ||
(value == null) ? AppendNull() : Append(value.Value); | ||
} | ||
|
||
public DurationArray( | ||
DurationType type, | ||
ArrowBuffer valueBuffer, ArrowBuffer nullBitmapBuffer, | ||
int length, int nullCount, int offset) | ||
: this(new ArrayData(type, length, nullCount, offset, | ||
new[] { nullBitmapBuffer, valueBuffer })) | ||
{ } | ||
|
||
public DurationArray(ArrayData data) | ||
: base(data) | ||
{ | ||
data.EnsureDataType(ArrowTypeId.Duration); | ||
} | ||
|
||
public DurationType DataType => (DurationType)this.Data.DataType; | ||
|
||
public TimeSpan? GetTimeSpan(int index) | ||
{ | ||
if (index < 0 || index >= Length) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
} | ||
return IsValid(index) ? new TimeSpan(DataType.Unit.ConvertToTicks(Values[index])) : null; | ||
} | ||
|
||
public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace Apache.Arrow.Types | ||
{ | ||
public sealed class DurationType : TimeBasedType | ||
{ | ||
public static readonly DurationType Second = new DurationType(TimeUnit.Second); | ||
public static readonly DurationType Millisecond = new DurationType(TimeUnit.Millisecond); | ||
public static readonly DurationType Microsecond = new DurationType(TimeUnit.Microsecond); | ||
public static readonly DurationType Nanosecond = new DurationType(TimeUnit.Nanosecond); | ||
private static readonly DurationType[] _types = new DurationType[] { Second, Millisecond, Microsecond, Nanosecond }; | ||
|
||
private DurationType(TimeUnit unit) | ||
: base(unit) | ||
{ | ||
} | ||
|
||
public override ArrowTypeId TypeId => ArrowTypeId.Duration; | ||
public override string Name => "duration"; | ||
public override int BitWidth => 64; | ||
|
||
public static DurationType FromTimeUnit(TimeUnit unit) | ||
{ | ||
return _types[(int)unit]; | ||
} | ||
|
||
public override void Accept(IArrowTypeVisitor visitor) => Accept(this, visitor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ public enum ArrowTypeId | |
Dictionary, | ||
Map, | ||
FixedSizeList, | ||
Duration, | ||
} | ||
|
||
public interface IArrowType | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace Apache.Arrow.Types | ||
{ | ||
public abstract class TimeBasedType : FixedWidthType | ||
{ | ||
public TimeUnit Unit { get; } | ||
|
||
protected TimeBasedType(TimeUnit unit) | ||
{ | ||
Unit = unit; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.