-
-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: DateTimeOffset #546
base: master
Are you sure you want to change the base?
feat: DateTimeOffset #546
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,13 +63,8 @@ public DataField(string name, Type clrType, bool? isNullable = null, bool? isArr | |
|
||
Discover(clrType, isCompiledWithNullable ?? true, out Type baseType, out bool discIsArray, out bool discIsNullable); | ||
ClrType = baseType; | ||
if(!SchemaEncoder.IsSupported(ClrType)) { | ||
if(baseType == typeof(DateTimeOffset)) { | ||
throw new NotSupportedException($"{nameof(DateTimeOffset)} support was dropped due to numerous ambiguity issues, please use {nameof(DateTime)} from now on."); | ||
} | ||
else { | ||
throw new NotSupportedException($"type {clrType} is not supported"); | ||
} | ||
if(!SchemaEncoder.IsSupported(ClrType)){ | ||
throw new NotSupportedException($"type {clrType} is not supported"); | ||
} | ||
|
||
IsNullable = isNullable ?? discIsNullable; | ||
|
@@ -158,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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a hack to fix the serialization append issue I encountered. Fundamentally the parquet thrift schema on its own does not enough information to differentiate date time offset vs date time with the class. Will have to rethink my approach. Possibly merge DateTimeOffsetDataField into DateTimeDataField somehow |
||
|
||
#region [ Type Resolution ] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
|
||
namespace Parquet.Schema { | ||
/// <summary> | ||
/// Schema element for <see cref="DateTime"/> which allows to specify precision | ||
/// </summary> | ||
public class DateTimeOffsetDataField : DataField { | ||
/// <summary> | ||
/// IsAdjustedToUTC | ||
/// </summary> | ||
public bool IsAdjustedToUTC => true; | ||
|
||
/// <summary> | ||
/// TimeUnit | ||
/// </summary> | ||
public DateTimeTimeUnit Unit { get; } | ||
|
||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DateTimeDataField"/> class. | ||
/// </summary> | ||
/// <param name="name">The name.</param> | ||
/// <param name="unit"></param> | ||
/// <param name="isNullable"></param> | ||
/// <param name="isArray"></param> | ||
/// <param name="propertyName">When set, uses this property to get the field's data. When not set, uses the property that matches the name parameter.</param> | ||
public DateTimeOffsetDataField(string name, DateTimeTimeUnit? unit = null, bool? isNullable = null, bool? isArray = null, string? propertyName = null) | ||
: 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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably deserved a dedicated error and a link to the docs if this change is accepted