Skip to content

Commit

Permalink
Nullable Timespan
Browse files Browse the repository at this point in the history
  • Loading branch information
cliedeman committed Mar 19, 2024
1 parent d8febde commit 17ce00a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Parquet.Test/Serialisation/ParquetSerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ public async Task Atomics_Simplest_Serde() {

await Compare(data);
}

class TimespanRecord {
public TimeSpan TimeSpan { get; set; }

public TimeSpan? NullableTimeSpan { get; set; }
}

[Fact]
public async Task TimeSpan_Simplest_Serde() {

var data = Enumerable.Range(0, 1_000).Select(i => new TimespanRecord {
TimeSpan = TimeSpan.Parse("6:12:14:45"),
NullableTimeSpan = null,
}).ToList();

await Compare(data);
}

[Fact]
public async Task Atomics_Simplest_Serde_Dict() {
Expand Down
12 changes: 12 additions & 0 deletions src/Parquet.Test/Serialisation/SchemaReflectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ class DatesPoco {
public DateTime? NullableTimestampDate { get; set; }

public TimeSpan DefaultTime { get; set; }

public TimeSpan? NullableTimeSpan { get; set; }

[ParquetMicroSecondsTime]
public TimeSpan MicroTime { get; set; }
Expand Down Expand Up @@ -395,6 +397,16 @@ public void Type_TimeSpan_Default() {
Assert.True(df is TimeSpanDataField);
Assert.Equal(TimeSpanFormat.MilliSeconds, ((TimeSpanDataField)df).TimeSpanFormat);
}

[Fact]
public void Type_TimeSpan_Nullable() {
ParquetSchema s = typeof(DatesPoco).GetParquetSchema(true);

DataField df = s.FindDataField(nameof(DatesPoco.NullableTimeSpan));
Assert.True(df is TimeSpanDataField);
Assert.True(df.IsNullable);
Assert.Equal(TimeSpanFormat.MilliSeconds, ((TimeSpanDataField)df).TimeSpanFormat);
}

[Fact]
public void Type_TimeSpan_Micros() {
Expand Down
2 changes: 1 addition & 1 deletion src/Parquet/Serialization/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static Field ConstructDataField(string name, string propertyName, Type t
member?.MicroSecondsTimeAttribute == null
? TimeSpanFormat.MilliSeconds
: TimeSpanFormat.MicroSeconds,
isNullable, null, propertyName);
t == typeof(TimeSpan?), null, propertyName);
#if NET6_0_OR_GREATER
} else if(t == typeof(TimeOnly) || t == typeof(TimeOnly?)) {
r = new TimeOnlyDataField(name,
Expand Down

0 comments on commit 17ce00a

Please sign in to comment.