diff --git a/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs b/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs index 5919c948..d8d8b267 100644 --- a/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs +++ b/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs @@ -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 data = await ParquetSerializer.DeserializeAsync(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() { diff --git a/src/Parquet/Schema/DataField.cs b/src/Parquet/Schema/DataField.cs index 45c30e0c..31685a81 100644 --- a/src/Parquet/Schema/DataField.cs +++ b/src/Parquet/Schema/DataField.cs @@ -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; } /// public override int GetHashCode() => base.GetHashCode(); + + /// + /// + /// + /// + /// + protected virtual bool BaseClrTypeCompatible(DataField other) => this.BaseClrType == other.BaseClrType; #region [ Type Resolution ] diff --git a/src/Parquet/Schema/DateTimeOffsetDataField.cs b/src/Parquet/Schema/DateTimeOffsetDataField.cs index ac8417a6..3d5baa28 100644 --- a/src/Parquet/Schema/DateTimeOffsetDataField.cs +++ b/src/Parquet/Schema/DateTimeOffsetDataField.cs @@ -28,5 +28,18 @@ public DateTimeOffsetDataField(string name, DateTimeTimeUnit? unit = null, bool? : base(name, typeof(DateTimeOffset), isNullable, isArray, propertyName) { Unit = unit ?? DateTimeTimeUnit.Millis; } + + /// + /// + /// + /// + /// + protected override bool BaseClrTypeCompatible(DataField other) { + if(other is DateTimeDataField) { + return true; + } + + return base.BaseClrTypeCompatible(other); + } } } \ No newline at end of file