Skip to content

Commit 62ae832

Browse files
authored
Fix out of memory errors causing logic_error when using ManagedRandomAccessFile (#471)
1 parent f1f2eda commit 62ae832

File tree

6 files changed

+48
-25
lines changed

6 files changed

+48
-25
lines changed

cpp/Enums.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ namespace
9797
static_assert(::arrow::TimeUnit::type::MILLI == 1);
9898
static_assert(::arrow::TimeUnit::type::MICRO == 2);
9999
static_assert(::arrow::TimeUnit::type::NANO == 3);
100-
}
101100

101+
// Arrow StatusCode values that should be kept up to date with ArrowStatusCode.cs
102+
static_assert((int) ::arrow::StatusCode::OutOfMemory == 1);
103+
static_assert((int) ::arrow::StatusCode::IOError == 5);
104+
static_assert((int) ::arrow::StatusCode::UnknownError == 9);
105+
}
102106
}

cpp/ExceptionInfo.h

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <exception>
44
#include <string>
55

6+
#include <parquet/exception.h>
7+
68
struct ExceptionInfo final
79
{
810
ExceptionInfo(const char* type, const char* message);
@@ -14,23 +16,28 @@ struct ExceptionInfo final
1416
};
1517

1618
#define SINGLE_ARG(...) __VA_ARGS__
17-
#define TRYCATCH(expression) \
18-
try \
19-
{ \
20-
expression \
21-
return nullptr; \
22-
} \
23-
catch (const std::bad_alloc& exception) \
24-
{ \
25-
return new ExceptionInfo("OutOfMemoryException", exception.what()); \
26-
} \
27-
catch (const std::exception& exception) \
28-
{ \
29-
return new ExceptionInfo(exception); \
30-
} \
31-
catch (...) \
32-
{ \
33-
return new ExceptionInfo("unkown", "uncaught exception"); \
34-
} \
35-
19+
#define TRYCATCH(expression) \
20+
try \
21+
{ \
22+
expression \
23+
return nullptr; \
24+
} \
25+
catch (const std::bad_alloc& exception) \
26+
{ \
27+
return new ExceptionInfo("OutOfMemoryException", exception.what()); \
28+
} \
29+
catch (const parquet::ParquetStatusException& exception) \
30+
{ \
31+
return exception.status().IsOutOfMemory() \
32+
? new ExceptionInfo("OutOfMemoryException", exception.what()) \
33+
: new ExceptionInfo(exception); \
34+
} \
35+
catch (const std::exception& exception) \
36+
{ \
37+
return new ExceptionInfo(exception); \
38+
} \
39+
catch (...) \
40+
{ \
41+
return new ExceptionInfo("unknown", "uncaught exception"); \
42+
} \
3643

cpp/ManagedRandomAccessFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ManagedRandomAccessFile final : public arrow::io::RandomAccessFile
121121
return Result<T>(result);
122122
}
123123

124-
return Result<T>(Status(statusCode, exception));
124+
return Result<T>(Status(statusCode, exception == nullptr ? "" : exception));
125125
}
126126

127127
static Status GetStatus(const StatusCode statusCode, const char* const exception)

csharp/ArrowStatusCode.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace ParquetSharp
2+
{
3+
/// <summary>
4+
/// Subset of Arrow StatusCode enums used from ParquetSharp.
5+
/// </summary>
6+
internal enum ArrowStatusCode
7+
{
8+
OutOfMemory = 1,
9+
IOError = 5,
10+
UnknownError = 9,
11+
}
12+
}

csharp/IO/ManagedRandomAccessFile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,16 @@ private byte HandleException(Exception error, out string? exception)
168168
if (error is OutOfMemoryException)
169169
{
170170
exception = _exceptionMessage = null;
171-
return 1;
171+
return (byte) ArrowStatusCode.OutOfMemory;
172172
}
173173
if (error is IOException)
174174
{
175175
exception = _exceptionMessage = error.ToString();
176-
return 5;
176+
return (byte) ArrowStatusCode.IOError;
177177
}
178178

179179
exception = _exceptionMessage = error.ToString();
180-
return 9;
180+
return (byte) ArrowStatusCode.UnknownError;
181181
}
182182

183183
[DllImport(ParquetDll.Name)]

csharp/ParquetSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1313
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1414
<NoWarn>1591;</NoWarn>
15-
<VersionPrefix>16.1.0-beta1</VersionPrefix>
15+
<VersionPrefix>16.1.0-beta2</VersionPrefix>
1616
<Company>G-Research</Company>
1717
<Authors>G-Research</Authors>
1818
<Product>ParquetSharp</Product>

0 commit comments

Comments
 (0)