Skip to content

Commit

Permalink
fix: Fix deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
cliedeman committed Sep 20, 2024
1 parent 3f4f8a6 commit 954a4bb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/Parquet.Test/Serialisation/ParquetSerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,35 @@ public async Task Interface_Serialize() {
Assert.Equivalent(data, data2);

}

[Fact]
public async Task DateTimeOffset_Serialize() {
var ms = new MemoryStream();
var value = new DateTimeOffset(2020, 1, 1, 0, 0, 0, TimeSpan.Zero);

var expected = new DateTimeOffsetClass {
DateTimeOffset = value,
};

//write
await ParquetSerializer.SerializeAsync([expected], ms);

//read back
ms.Position = 0;
IList<DateTimeOffsetClass> data = await ParquetSerializer.DeserializeAsync<DateTimeOffsetClass>(ms);
DateTimeOffsetClass actual = Assert.Single(data);
Assert.Equal(expected.DateTimeOffset, actual.DateTimeOffset);

//write append
ms.Position = 0;
await ParquetSerializer.SerializeAsync([expected], ms, new ParquetSerializerOptions {
Append = true,
});
}

private class DateTimeOffsetClass {
public DateTimeOffset DateTimeOffset { get; set; }
}

[Fact]
public async Task InterfaceProperty_Serialize() {
Expand Down
9 changes: 8 additions & 1 deletion src/Parquet/Schema/DataField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,20 @@ public override bool Equals(object? obj) {
return false;

return base.Equals(obj) &&
BaseClrType == other.BaseClrType &&
BaseClrTypeCompatible(other) &&
IsNullable == other.IsNullable &&
IsArray == other.IsArray;
}

/// <inheritdoc/>
public override int GetHashCode() => base.GetHashCode();

/// <summary>
///
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
protected virtual bool BaseClrTypeCompatible(DataField other) => this.BaseClrType == other.BaseClrType;

#region [ Type Resolution ]

Expand Down
13 changes: 13 additions & 0 deletions src/Parquet/Schema/DateTimeOffsetDataField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,18 @@ public DateTimeOffsetDataField(string name, DateTimeTimeUnit? unit = null, bool?
: base(name, typeof(DateTimeOffset), isNullable, isArray, propertyName) {
Unit = unit ?? DateTimeTimeUnit.Millis;
}

/// <summary>
///
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
protected override bool BaseClrTypeCompatible(DataField other) {
if(other is DateTimeDataField) {
return true;
}

return base.BaseClrTypeCompatible(other);
}
}
}

0 comments on commit 954a4bb

Please sign in to comment.