4
4
namespace ParquetSharp
5
5
{
6
6
public enum LogicalTypeEnum
7
+ {
8
+ Undefined = 0 ,
9
+ String = 1 ,
10
+ Map = 2 ,
11
+ List = 3 ,
12
+ Enum = 4 ,
13
+ Decimal = 5 ,
14
+ Date = 6 ,
15
+ Time = 7 ,
16
+ Timestamp = 8 ,
17
+ Interval = 9 ,
18
+ Int = 10 ,
19
+ Nil = 11 ,
20
+ Json = 12 ,
21
+ Bson = 13 ,
22
+ Uuid = 14 ,
23
+ None = 15 ,
24
+ Float16 = 16 ,
25
+ }
26
+
27
+ /// <summary>
28
+ /// Type enum with values that match the C++ Parquet library.
29
+ /// These are not guaranteed to be stable between releases, but we need to keep
30
+ /// the LogicalTypeEnum values above stable to ensure ABI compatibility.
31
+ /// </summary>
32
+ internal enum CppLogicalTypeEnum
7
33
{
8
34
Undefined = 0 ,
9
35
String = 1 ,
@@ -21,7 +47,35 @@ public enum LogicalTypeEnum
21
47
Bson = 13 ,
22
48
Uuid = 14 ,
23
49
Float16 = 15 ,
24
- None = 16
50
+ None = 16 ,
51
+ }
52
+
53
+ internal static class CppLogicalTypeEnumExtensions
54
+ {
55
+ public static LogicalTypeEnum ToPublicEnum ( this CppLogicalTypeEnum enumValue )
56
+ {
57
+ return enumValue switch
58
+ {
59
+ CppLogicalTypeEnum . Undefined => LogicalTypeEnum . Undefined ,
60
+ CppLogicalTypeEnum . String => LogicalTypeEnum . String ,
61
+ CppLogicalTypeEnum . Map => LogicalTypeEnum . Map ,
62
+ CppLogicalTypeEnum . List => LogicalTypeEnum . List ,
63
+ CppLogicalTypeEnum . Enum => LogicalTypeEnum . Enum ,
64
+ CppLogicalTypeEnum . Decimal => LogicalTypeEnum . Decimal ,
65
+ CppLogicalTypeEnum . Date => LogicalTypeEnum . Date ,
66
+ CppLogicalTypeEnum . Time => LogicalTypeEnum . Time ,
67
+ CppLogicalTypeEnum . Timestamp => LogicalTypeEnum . Timestamp ,
68
+ CppLogicalTypeEnum . Interval => LogicalTypeEnum . Interval ,
69
+ CppLogicalTypeEnum . Int => LogicalTypeEnum . Int ,
70
+ CppLogicalTypeEnum . Nil => LogicalTypeEnum . Nil ,
71
+ CppLogicalTypeEnum . Json => LogicalTypeEnum . Json ,
72
+ CppLogicalTypeEnum . Bson => LogicalTypeEnum . Bson ,
73
+ CppLogicalTypeEnum . Uuid => LogicalTypeEnum . Uuid ,
74
+ CppLogicalTypeEnum . Float16 => LogicalTypeEnum . Float16 ,
75
+ CppLogicalTypeEnum . None => LogicalTypeEnum . None ,
76
+ _ => throw new ArgumentOutOfRangeException ( nameof ( enumValue ) , enumValue , null )
77
+ } ;
78
+ }
25
79
}
26
80
27
81
public abstract class LogicalType : IDisposable , IEquatable < LogicalType >
@@ -36,7 +90,7 @@ public void Dispose()
36
90
Handle . Dispose ( ) ;
37
91
}
38
92
39
- public LogicalTypeEnum Type => ExceptionInfo . Return < LogicalTypeEnum > ( Handle , LogicalType_Type ) ;
93
+ public LogicalTypeEnum Type => ExceptionInfo . Return < CppLogicalTypeEnum > ( Handle , LogicalType_Type ) . ToPublicEnum ( ) ;
40
94
41
95
public bool Equals ( LogicalType ? other )
42
96
{
@@ -86,7 +140,7 @@ internal static LogicalType Create(IntPtr handle)
86
140
throw new ArgumentNullException ( nameof ( handle ) ) ;
87
141
}
88
142
89
- var type = ExceptionInfo . Return < LogicalTypeEnum > ( handle , LogicalType_Type ) ;
143
+ var type = ExceptionInfo . Return < CppLogicalTypeEnum > ( handle , LogicalType_Type ) . ToPublicEnum ( ) ;
90
144
91
145
return type switch
92
146
{
@@ -114,7 +168,7 @@ internal static LogicalType Create(IntPtr handle)
114
168
private static extern void LogicalType_Free ( IntPtr logicalType ) ;
115
169
116
170
[ DllImport ( ParquetDll . Name ) ]
117
- private static extern IntPtr LogicalType_Type ( IntPtr logicalType , out LogicalTypeEnum type ) ;
171
+ private static extern IntPtr LogicalType_Type ( IntPtr logicalType , out CppLogicalTypeEnum type ) ;
118
172
119
173
[ DllImport ( ParquetDll . Name ) ]
120
174
private static extern IntPtr LogicalType_Equals ( IntPtr left , IntPtr right , [ MarshalAs ( UnmanagedType . I1 ) ] out bool equals ) ;
0 commit comments