Skip to content

Commit

Permalink
Fix breaking change to LogicalTypeEnum.None value (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreeve authored May 2, 2024
1 parent 9fba131 commit 5aaff18
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
62 changes: 58 additions & 4 deletions csharp/LogicalType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@
namespace ParquetSharp
{
public enum LogicalTypeEnum
{
Undefined = 0,
String = 1,
Map = 2,
List = 3,
Enum = 4,
Decimal = 5,
Date = 6,
Time = 7,
Timestamp = 8,
Interval = 9,
Int = 10,
Nil = 11,
Json = 12,
Bson = 13,
Uuid = 14,
None = 15,
Float16 = 16,
}

/// <summary>
/// Type enum with values that match the C++ Parquet library.
/// These are not guaranteed to be stable between releases, but we need to keep
/// the LogicalTypeEnum values above stable to ensure ABI compatibility.
/// </summary>
internal enum CppLogicalTypeEnum
{
Undefined = 0,
String = 1,
Expand All @@ -21,7 +47,35 @@ public enum LogicalTypeEnum
Bson = 13,
Uuid = 14,
Float16 = 15,
None = 16
None = 16,
}

internal static class CppLogicalTypeEnumExtensions
{
public static LogicalTypeEnum ToPublicEnum(this CppLogicalTypeEnum enumValue)
{
return enumValue switch
{
CppLogicalTypeEnum.Undefined => LogicalTypeEnum.Undefined,
CppLogicalTypeEnum.String => LogicalTypeEnum.String,
CppLogicalTypeEnum.Map => LogicalTypeEnum.Map,
CppLogicalTypeEnum.List => LogicalTypeEnum.List,
CppLogicalTypeEnum.Enum => LogicalTypeEnum.Enum,
CppLogicalTypeEnum.Decimal => LogicalTypeEnum.Decimal,
CppLogicalTypeEnum.Date => LogicalTypeEnum.Date,
CppLogicalTypeEnum.Time => LogicalTypeEnum.Time,
CppLogicalTypeEnum.Timestamp => LogicalTypeEnum.Timestamp,
CppLogicalTypeEnum.Interval => LogicalTypeEnum.Interval,
CppLogicalTypeEnum.Int => LogicalTypeEnum.Int,
CppLogicalTypeEnum.Nil => LogicalTypeEnum.Nil,
CppLogicalTypeEnum.Json => LogicalTypeEnum.Json,
CppLogicalTypeEnum.Bson => LogicalTypeEnum.Bson,
CppLogicalTypeEnum.Uuid => LogicalTypeEnum.Uuid,
CppLogicalTypeEnum.Float16 => LogicalTypeEnum.Float16,
CppLogicalTypeEnum.None => LogicalTypeEnum.None,
_ => throw new ArgumentOutOfRangeException(nameof(enumValue), enumValue, null)
};
}
}

public abstract class LogicalType : IDisposable, IEquatable<LogicalType>
Expand All @@ -36,7 +90,7 @@ public void Dispose()
Handle.Dispose();
}

public LogicalTypeEnum Type => ExceptionInfo.Return<LogicalTypeEnum>(Handle, LogicalType_Type);
public LogicalTypeEnum Type => ExceptionInfo.Return<CppLogicalTypeEnum>(Handle, LogicalType_Type).ToPublicEnum();

public bool Equals(LogicalType? other)
{
Expand Down Expand Up @@ -86,7 +140,7 @@ internal static LogicalType Create(IntPtr handle)
throw new ArgumentNullException(nameof(handle));
}

var type = ExceptionInfo.Return<LogicalTypeEnum>(handle, LogicalType_Type);
var type = ExceptionInfo.Return<CppLogicalTypeEnum>(handle, LogicalType_Type).ToPublicEnum();

return type switch
{
Expand Down Expand Up @@ -114,7 +168,7 @@ internal static LogicalType Create(IntPtr handle)
private static extern void LogicalType_Free(IntPtr logicalType);

[DllImport(ParquetDll.Name)]
private static extern IntPtr LogicalType_Type(IntPtr logicalType, out LogicalTypeEnum type);
private static extern IntPtr LogicalType_Type(IntPtr logicalType, out CppLogicalTypeEnum type);

[DllImport(ParquetDll.Name)]
private static extern IntPtr LogicalType_Equals(IntPtr left, IntPtr right, [MarshalAs(UnmanagedType.I1)] out bool equals);
Expand Down
2 changes: 1 addition & 1 deletion csharp/ParquetSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1591;</NoWarn>
<Version>15.0.2</Version>
<Version>15.0.2.1</Version>
<Company>G-Research</Company>
<Authors>G-Research</Authors>
<Product>ParquetSharp</Product>
Expand Down

0 comments on commit 5aaff18

Please sign in to comment.