Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Apache.Arrow/Types/DurationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace Apache.Arrow.Types
{
public sealed class DurationType : TimeBasedType
Expand All @@ -21,7 +23,6 @@ public sealed class DurationType : TimeBasedType
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)
Expand All @@ -32,10 +33,14 @@ private DurationType(TimeUnit unit)
public override string Name => "duration";
public override int BitWidth => 64;

public static DurationType FromTimeUnit(TimeUnit unit)
public static DurationType FromTimeUnit(TimeUnit unit) => unit switch
{
return _types[(int)unit];
}
TimeUnit.Second => Second,
TimeUnit.Millisecond => Millisecond,
TimeUnit.Microsecond => Microsecond,
TimeUnit.Nanosecond => Nanosecond,
_ => throw new ArgumentOutOfRangeException(nameof(unit), unit, @"Unsupported time unit.")
};

public override void Accept(IArrowTypeVisitor visitor) => Accept(this, visitor);
}
Expand Down
10 changes: 6 additions & 4 deletions src/Apache.Arrow/Types/IntervalType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public sealed class IntervalType : FixedWidthType
public static readonly IntervalType YearMonth = new IntervalType(IntervalUnit.YearMonth);
public static readonly IntervalType DayTime = new IntervalType(IntervalUnit.DayTime);
public static readonly IntervalType MonthDayNanosecond = new IntervalType(IntervalUnit.MonthDayNanosecond);
private static readonly IntervalType[] _types = new IntervalType[] { YearMonth, DayTime, MonthDayNanosecond };

public override ArrowTypeId TypeId => ArrowTypeId.Interval;
public override string Name => "interval";
Expand All @@ -43,9 +42,12 @@ public IntervalType(IntervalUnit unit = IntervalUnit.YearMonth)

public override void Accept(IArrowTypeVisitor visitor) => Accept(this, visitor);

public static IntervalType FromIntervalUnit(IntervalUnit unit)
public static IntervalType FromIntervalUnit(IntervalUnit unit) => unit switch
{
return _types[(int)unit];
}
IntervalUnit.YearMonth => YearMonth,
IntervalUnit.DayTime => DayTime,
IntervalUnit.MonthDayNanosecond => MonthDayNanosecond,
_ => throw new ArgumentOutOfRangeException(nameof(unit), unit, @"Unsupported interval unit")
};
}
}
13 changes: 9 additions & 4 deletions src/Apache.Arrow/Types/TimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace Apache.Arrow.Types
{
public abstract class TimeType : TimeBasedType
Expand All @@ -21,16 +23,19 @@ public abstract class TimeType : TimeBasedType
public static readonly Time32Type Millisecond = new Time32Type(TimeUnit.Millisecond);
public static readonly Time64Type Microsecond = new Time64Type(TimeUnit.Microsecond);
public static readonly Time64Type Nanosecond = new Time64Type(TimeUnit.Nanosecond);
private static readonly TimeType[] _types = new TimeType[] { Second, Millisecond, Microsecond, Nanosecond };

protected TimeType(TimeUnit unit)
: base(unit)
{
}

public static TimeType FromTimeUnit(TimeUnit unit)
public static TimeType FromTimeUnit(TimeUnit unit) => unit switch
{
return _types[(int)unit];
}
TimeUnit.Second => Second,
TimeUnit.Millisecond => Millisecond,
TimeUnit.Microsecond => Microsecond,
TimeUnit.Nanosecond => Nanosecond,
_ => throw new ArgumentOutOfRangeException(nameof(unit), unit, @"Unsupported time unit")
};
}
}
Loading