1414#include " Framework/CompilerBuiltins.h"
1515#include " Framework/VariantHelpers.h"
1616#include < arrow/compute/api_aggregate.h>
17+ #include < arrow/compute/initialize.h>
1718#include < arrow/compute/kernel.h>
1819#include < arrow/status.h>
1920#include < arrow/table.h>
2021#include < arrow/util/key_value_metadata.h>
2122
2223namespace o2 ::framework
2324{
24- void cannotBuildAnArray ()
25+ void cannotBuildAnArray (const char * reason )
2526{
26- throw framework::runtime_error (" Cannot finish an array" );
27+ throw framework::runtime_error_f (" Cannot finish an array: %s " , reason );
2728}
2829
2930void cannotCreateIndexBuilder ()
@@ -62,10 +63,10 @@ SelfBuilder::SelfBuilder(arrow::MemoryPool* pool)
6263{
6364 auto status = arrow::MakeBuilder (pool, arrow::int32 (), &mBuilder );
6465 if (!status.ok ()) {
65- throw framework::runtime_error (" Cannot create array builder for the self-index! " );
66+ throw framework::runtime_error_f (" Cannot create array builder for the self-index: %s " , status. ToString (). c_str () );
6667 }
6768}
68- // static_cast<ChunkedArrayIterator*>(this)->reset(pool);
69+
6970void SelfBuilder::reset (std::shared_ptr<arrow::ChunkedArray>)
7071{
7172 mBuilder ->Reset ();
@@ -74,15 +75,18 @@ void SelfBuilder::reset(std::shared_ptr<arrow::ChunkedArray>)
7475
7576void SelfBuilder::fill (int idx)
7677{
77- (void )static_cast <arrow::Int32Builder*>(mBuilder .get ())->Append (idx);
78+ auto status = static_cast <arrow::Int32Builder*>(mBuilder .get ())->Append (idx);
79+ if (!status.ok ()) {
80+ throw framework::runtime_error_f (" Cannot append to self-index array: %s" , status.ToString ().c_str ());
81+ }
7882}
7983
8084std::shared_ptr<arrow::ChunkedArray> SelfBuilder::result () const
8185{
8286 std::shared_ptr<arrow::Array> array;
8387 auto status = static_cast <arrow::Int32Builder*>(mBuilder .get ())->Finish (&array);
8488 if (!status.ok ()) {
85- cannotBuildAnArray ();
89+ cannotBuildAnArray (status. ToString (). c_str () );
8690 }
8791
8892 return std::make_shared<arrow::ChunkedArray>(array);
@@ -93,7 +97,7 @@ SingleBuilder::SingleBuilder(std::shared_ptr<arrow::ChunkedArray> source, arrow:
9397{
9498 auto status = arrow::MakeBuilder (pool, arrow::int32 (), &mBuilder );
9599 if (!status.ok ()) {
96- throw framework::runtime_error (" Cannot create array builder for the single-valued index! " );
100+ throw framework::runtime_error_f (" Cannot create array builder for the single-valued index: %s " , status. ToString (). c_str () );
97101 }
98102}
99103
@@ -126,10 +130,14 @@ bool SingleBuilder::find(int idx)
126130
127131void SingleBuilder::fill (int idx)
128132{
133+ arrow::Status status;
129134 if (mPosition < mSourceSize && valueAt (mPosition ) == idx) {
130- ( void ) static_cast <arrow::Int32Builder*>(mBuilder .get ())->Append ((int )mPosition );
135+ status = static_cast <arrow::Int32Builder*>(mBuilder .get ())->Append ((int )mPosition );
131136 } else {
132- (void )static_cast <arrow::Int32Builder*>(mBuilder .get ())->Append (-1 );
137+ status = static_cast <arrow::Int32Builder*>(mBuilder .get ())->Append (-1 );
138+ }
139+ if (!status.ok ()) {
140+ throw framework::runtime_error_f (" Cannot append to array: %s" , status.ToString ().c_str ());
133141 }
134142}
135143
@@ -138,22 +146,23 @@ std::shared_ptr<arrow::ChunkedArray> SingleBuilder::result() const
138146 std::shared_ptr<arrow::Array> array;
139147 auto status = static_cast <arrow::Int32Builder*>(mBuilder .get ())->Finish (&array);
140148 if (!status.ok ()) {
141- cannotBuildAnArray ();
149+ cannotBuildAnArray (status. ToString (). c_str () );
142150 }
143151 return std::make_shared<arrow::ChunkedArray>(array);
144152}
145153
146154SliceBuilder::SliceBuilder (std::shared_ptr<arrow::ChunkedArray> source, arrow::MemoryPool* pool)
147155 : ChunkedArrayIterator{source}
148156{
149- if (!preSlice ().ok ()) {
150- throw framework::runtime_error (" Cannot pre-slice the source for slice-index building" );
157+ auto status = preSlice ();
158+ if (!status.ok ()) {
159+ throw framework::runtime_error_f (" Cannot pre-slice the source for slice-index building: %s" , status.ToString ().c_str ());
151160 }
152161
153162 std::unique_ptr<arrow::ArrayBuilder> builder;
154- auto status = arrow::MakeBuilder (pool, arrow::int32 (), &builder);
163+ status = arrow::MakeBuilder (pool, arrow::int32 (), &builder);
155164 if (!status.ok ()) {
156- throw framework::runtime_error (" Cannot create array for the slice-index builder! " );
165+ throw framework::runtime_error_f (" Cannot create array for the slice-index builder: %s " , status. ToString (). c_str () );
157166 }
158167 mListBuilder = std::make_unique<arrow::FixedSizeListBuilder>(pool, std::move (builder), 2 );
159168 mValueBuilder = static_cast <arrow::FixedSizeListBuilder*>(mListBuilder .get ())->value_builder ();
@@ -166,8 +175,9 @@ void SliceBuilder::reset(std::shared_ptr<arrow::ChunkedArray> source)
166175 mListBuilder ->Reset ();
167176 mValuePos = 0 ;
168177 static_cast <ChunkedArrayIterator*>(this )->reset (source);
169- if (!preSlice ().ok ()) {
170- throw framework::runtime_error (" Cannot pre-slice the source for slice-index building" );
178+ auto status = preSlice ();
179+ if (!status.ok ()) {
180+ throw framework::runtime_error_f (" Cannot pre-slice the source for slice-index building: %s" , status.ToString ().c_str ());
171181 }
172182}
173183
@@ -211,13 +221,17 @@ std::shared_ptr<arrow::ChunkedArray> SliceBuilder::result() const
211221 std::shared_ptr<arrow::Array> array;
212222 auto status = static_cast <arrow::FixedSizeListBuilder*>(mListBuilder .get ())->Finish (&array);
213223 if (!status.ok ()) {
214- cannotBuildAnArray ();
224+ cannotBuildAnArray (status. ToString (). c_str () );
215225 }
216226 return std::make_shared<arrow::ChunkedArray>(array);
217227}
218228
219229arrow::Status SliceBuilder::SliceBuilder::preSlice ()
220230{
231+ auto status = arrow::compute::Initialize ();
232+ if (!status.ok ()) {
233+ throw framework::runtime_error_f (" Cannot initialize arrow compute: %s" , status.ToString ().c_str ());
234+ }
221235 arrow::Datum value_counts;
222236 auto options = arrow::compute::ScalarAggregateOptions::Defaults ();
223237 ARROW_ASSIGN_OR_RAISE (value_counts, arrow::compute::CallFunction (" value_counts" , {mSource }, &options));
@@ -230,14 +244,15 @@ arrow::Status SliceBuilder::SliceBuilder::preSlice()
230244ArrayBuilder::ArrayBuilder (std::shared_ptr<arrow::ChunkedArray> source, arrow::MemoryPool* pool)
231245 : ChunkedArrayIterator{source}
232246{
233- if (!preFind ().ok ()) {
234- throw framework::runtime_error (" Cannot pre-find in a source for array-index building" );
247+ auto && status = preFind ();
248+ if (!status.ok ()) {
249+ throw framework::runtime_error_f (" Cannot pre-find in a source for array-index building: %s" , status.ToString ().c_str ());
235250 }
236251
237252 std::unique_ptr<arrow::ArrayBuilder> builder;
238- auto status = arrow::MakeBuilder (pool, arrow::int32 (), &builder);
253+ status = arrow::MakeBuilder (pool, arrow::int32 (), &builder);
239254 if (!status.ok ()) {
240- throw framework::runtime_error (" Cannot create array for the array-index builder! " );
255+ throw framework::runtime_error_f (" Cannot create array for the array-index builder: %s " , status. ToString (). c_str () );
241256 }
242257 mListBuilder = std::make_unique<arrow::ListBuilder>(pool, std::move (builder));
243258 mValueBuilder = static_cast <arrow::ListBuilder*>(mListBuilder .get ())->value_builder ();
@@ -246,8 +261,9 @@ ArrayBuilder::ArrayBuilder(std::shared_ptr<arrow::ChunkedArray> source, arrow::M
246261void ArrayBuilder::reset (std::shared_ptr<arrow::ChunkedArray> source)
247262{
248263 static_cast <ChunkedArrayIterator*>(this )->reset (source);
249- if (!preFind ().ok ()) {
250- throw framework::runtime_error (" Cannot pre-find in a source for array-index building" );
264+ auto status = preFind ();
265+ if (!status.ok ()) {
266+ throw framework::runtime_error_f (" Cannot pre-find in a source for array-index building: %s" , status.ToString ().c_str ());
251267 }
252268 mValues .clear ();
253269 mIndices .clear ();
@@ -274,13 +290,17 @@ std::shared_ptr<arrow::ChunkedArray> ArrayBuilder::result() const
274290 std::shared_ptr<arrow::Array> array;
275291 auto status = static_cast <arrow::ListBuilder*>(mListBuilder .get ())->Finish (&array);
276292 if (!status.ok ()) {
277- cannotBuildAnArray ();
293+ cannotBuildAnArray (status. ToString (). c_str () );
278294 }
279295 return std::make_shared<arrow::ChunkedArray>(array);
280296}
281297
282298arrow::Status ArrayBuilder::preFind ()
283299{
300+ auto status = arrow::compute::Initialize ();
301+ if (!status.ok ()) {
302+ throw framework::runtime_error_f (" Cannot initialize arrow compute: %s" , status.ToString ().c_str ());
303+ }
284304 arrow::Datum max;
285305 auto options = arrow::compute::ScalarAggregateOptions::Defaults ();
286306 ARROW_ASSIGN_OR_RAISE (max, arrow::compute::CallFunction (" max" , {mSource }, &options));
0 commit comments