From a6290a88ec34a3378037c05b45a4f64ab91747d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Saint-Jacques?= Date: Mon, 20 Apr 2020 09:24:12 -0400 Subject: [PATCH] ARROW-8488: [R] Remove VALUE_OR_STOP and STOP_IF_NOT_OK macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefer templated functions over macro to align with the C++ style. Closes #6969 from fsaintjacques/ARROW-8488 Authored-by: François Saint-Jacques Signed-off-by: François Saint-Jacques --- r/src/array.cpp | 6 ++--- r/src/array_from_vector.cpp | 32 +++++++++++++-------------- r/src/array_to_vector.cpp | 12 +++++----- r/src/arrow_types.h | 20 +++++------------ r/src/chunkedarray.cpp | 4 ++-- r/src/compression.cpp | 6 ++--- r/src/compute.cpp | 30 ++++++++++++------------- r/src/csv.cpp | 8 +++---- r/src/dataset.cpp | 42 +++++++++++++++++------------------ r/src/datatype.cpp | 4 ++-- r/src/feather.cpp | 8 +++---- r/src/filesystem.cpp | 32 +++++++++++++-------------- r/src/io.cpp | 44 ++++++++++++++++++------------------- r/src/json.cpp | 4 ++-- r/src/message.cpp | 12 +++++----- r/src/parquet.cpp | 2 +- r/src/py-to-r.cpp | 17 +++++++------- r/src/recordbatch.cpp | 18 +++++++-------- r/src/recordbatchreader.cpp | 20 ++++++++--------- r/src/recordbatchwriter.cpp | 10 ++++----- r/src/schema.cpp | 4 ++-- r/src/table.cpp | 12 +++++----- r/src/threadpool.cpp | 2 +- 23 files changed, 169 insertions(+), 180 deletions(-) diff --git a/r/src/array.cpp b/r/src/array.cpp index 62446742d9256..f1c32ca41aa51 100644 --- a/r/src/array.cpp +++ b/r/src/array.cpp @@ -143,7 +143,7 @@ bool Array__RangeEquals(const std::shared_ptr& self, // [[arrow::export]] std::shared_ptr Array__View(const std::shared_ptr& array, const std::shared_ptr& type) { - return VALUE_OR_STOP(array->View(type)); + return ValueOrStop(array->View(type)); } // [[arrow::export]] @@ -164,7 +164,7 @@ LogicalVector Array__Mask(const std::shared_ptr& array) { // [[arrow::export]] void Array__Validate(const std::shared_ptr& array) { - STOP_IF_NOT_OK(array->Validate()); + StopIfNotOk(array->Validate()); } // [[arrow::export]] @@ -194,7 +194,7 @@ std::shared_ptr StructArray__GetFieldByName( // [[arrow::export]] arrow::ArrayVector StructArray__Flatten( const std::shared_ptr& array) { - return VALUE_OR_STOP(array->Flatten()); + return ValueOrStop(array->Flatten()); } // [[arrow::export]] diff --git a/r/src/array_from_vector.cpp b/r/src/array_from_vector.cpp index 35bfbae8e9de7..49ebfed25a6bb 100644 --- a/r/src/array_from_vector.cpp +++ b/r/src/array_from_vector.cpp @@ -203,13 +203,13 @@ struct VectorToArrayConverter { static std::shared_ptr Visit(SEXP x, const std::shared_ptr& type) { std::unique_ptr builder; - STOP_IF_NOT_OK(MakeBuilder(arrow::default_memory_pool(), type, &builder)); + StopIfNotOk(MakeBuilder(arrow::default_memory_pool(), type, &builder)); VectorToArrayConverter converter{x, builder.get()}; - STOP_IF_NOT_OK(arrow::VisitTypeInline(*type, &converter)); + StopIfNotOk(arrow::VisitTypeInline(*type, &converter)); std::shared_ptr result; - STOP_IF_NOT_OK(builder->Finish(&result)); + StopIfNotOk(builder->Finish(&result)); return result; } @@ -228,7 +228,7 @@ std::shared_ptr MakeFactorArrayImpl(Rcpp::IntegerVector_ factor, auto n = factor.size(); std::shared_ptr indices_buffer = - VALUE_OR_STOP(AllocateBuffer(n * sizeof(value_type))); + ValueOrStop(AllocateBuffer(n * sizeof(value_type))); std::vector> buffers{nullptr, indices_buffer}; @@ -243,7 +243,7 @@ std::shared_ptr MakeFactorArrayImpl(Rcpp::IntegerVector_ factor, if (i < n) { // there are NA's so we need a null buffer - auto null_buffer = VALUE_OR_STOP(AllocateBuffer(BitUtil::BytesForBits(n))); + auto null_buffer = ValueOrStop(AllocateBuffer(BitUtil::BytesForBits(n))); internal::FirstTimeBitmapWriter null_bitmap_writer(null_buffer->mutable_data(), 0, n); // catch up @@ -273,7 +273,7 @@ std::shared_ptr MakeFactorArrayImpl(Rcpp::IntegerVector_ factor, SEXP levels = Rf_getAttrib(factor, R_LevelsSymbol); auto dict = MakeStringArray(levels, utf8()); - return VALUE_OR_STOP(DictionaryArray::FromArrays(type, array_indices, dict)); + return ValueOrStop(DictionaryArray::FromArrays(type, array_indices, dict)); } std::shared_ptr MakeFactorArray(Rcpp::IntegerVector_ factor, @@ -1070,7 +1070,7 @@ std::shared_ptr MakeSimpleArray(SEXP x) { auto first_na = std::find_if(p_vec_start, p_vec_end, is_na); if (first_na < p_vec_end) { - auto null_bitmap = VALUE_OR_STOP(AllocateBuffer(BitUtil::BytesForBits(n))); + auto null_bitmap = ValueOrStop(AllocateBuffer(BitUtil::BytesForBits(n))); internal::FirstTimeBitmapWriter bitmap_writer(null_bitmap->mutable_data(), 0, n); // first loop to clear all the bits before the first NA @@ -1192,7 +1192,7 @@ std::shared_ptr Array__from_vector( // struct types if (type->id() == Type::STRUCT) { if (!type_inferred) { - STOP_IF_NOT_OK(arrow::r::CheckCompatibleStruct(x, type)); + StopIfNotOk(arrow::r::CheckCompatibleStruct(x, type)); } return arrow::r::MakeStructArray(x, type); @@ -1200,17 +1200,17 @@ std::shared_ptr Array__from_vector( // general conversion with converter and builder std::unique_ptr converter; - STOP_IF_NOT_OK(arrow::r::GetConverter(type, &converter)); + StopIfNotOk(arrow::r::GetConverter(type, &converter)); // Create ArrayBuilder for type std::unique_ptr type_builder; - STOP_IF_NOT_OK(arrow::MakeBuilder(arrow::default_memory_pool(), type, &type_builder)); - STOP_IF_NOT_OK(converter->Init(type_builder.get())); + StopIfNotOk(arrow::MakeBuilder(arrow::default_memory_pool(), type, &type_builder)); + StopIfNotOk(converter->Init(type_builder.get())); // ingest R data and grab the result array - STOP_IF_NOT_OK(converter->Ingest(x)); + StopIfNotOk(converter->Ingest(x)); std::shared_ptr result; - STOP_IF_NOT_OK(converter->GetResult(&result)); + StopIfNotOk(converter->GetResult(&result)); return result; } @@ -1261,8 +1261,8 @@ std::shared_ptr ChunkedArray__from_list(Rcpp::List chunks, if (n == 0) { std::shared_ptr array; std::unique_ptr type_builder; - STOP_IF_NOT_OK(arrow::MakeBuilder(arrow::default_memory_pool(), type, &type_builder)); - STOP_IF_NOT_OK(type_builder->Finish(&array)); + StopIfNotOk(arrow::MakeBuilder(arrow::default_memory_pool(), type, &type_builder)); + StopIfNotOk(type_builder->Finish(&array)); vec.push_back(array); } else { // the first - might differ from the rest of the loop @@ -1285,7 +1285,7 @@ std::shared_ptr DictionaryArray__FromArrays( const std::shared_ptr& type, const std::shared_ptr& indices, const std::shared_ptr& dict) { - return VALUE_OR_STOP(arrow::DictionaryArray::FromArrays(type, indices, dict)); + return ValueOrStop(arrow::DictionaryArray::FromArrays(type, indices, dict)); } #endif diff --git a/r/src/array_to_vector.cpp b/r/src/array_to_vector.cpp index 5aefaeefde36a..4f55610a43f31 100644 --- a/r/src/array_to_vector.cpp +++ b/r/src/array_to_vector.cpp @@ -129,7 +129,7 @@ Status SomeNull_Ingest(SEXP data, R_xlen_t start, R_xlen_t n, SEXP ArrayVector__as_vector(R_xlen_t n, const ArrayVector& arrays) { auto converter = Converter::Make(arrays); Shield data(converter->Allocate(n)); - STOP_IF_NOT_OK(converter->IngestSerial(data)); + StopIfNotOk(converter->IngestSerial(data)); return data; } @@ -387,7 +387,7 @@ class Converter_Struct : public Converter { Status Ingest_all_nulls(SEXP data, R_xlen_t start, R_xlen_t n) const { int nf = converters.size(); for (int i = 0; i < nf; i++) { - STOP_IF_NOT_OK(converters[i]->Ingest_all_nulls(VECTOR_ELT(data, i), start, n)); + StopIfNotOk(converters[i]->Ingest_all_nulls(VECTOR_ELT(data, i), start, n)); } return Status::OK(); } @@ -397,9 +397,9 @@ class Converter_Struct : public Converter { auto struct_array = internal::checked_cast(array.get()); int nf = converters.size(); // Flatten() deals with merging of nulls - auto arrays = VALUE_OR_STOP(struct_array->Flatten(default_memory_pool())); + auto arrays = ValueOrStop(struct_array->Flatten(default_memory_pool())); for (int i = 0; i < nf; i++) { - STOP_IF_NOT_OK( + StopIfNotOk( converters[i]->Ingest_some_nulls(VECTOR_ELT(data, i), arrays[i], start, n)); } @@ -760,7 +760,7 @@ Rcpp::List to_dataframe_serial( for (int i = 0; i < nc; i++) { SEXP column = tbl[i] = converters[i]->Allocate(nr); - STOP_IF_NOT_OK(converters[i]->IngestSerial(column)); + StopIfNotOk(converters[i]->IngestSerial(column)); } tbl.attr("names") = names; tbl.attr("class") = Rcpp::CharacterVector::create("tbl_df", "tbl", "data.frame"); @@ -801,7 +801,7 @@ Rcpp::List to_dataframe_parallel( // wait for the ingestion to be finished status &= tg->Finish(); - STOP_IF_NOT_OK(status); + StopIfNotOk(status); tbl.attr("names") = names; tbl.attr("class") = Rcpp::CharacterVector::create("tbl_df", "tbl", "data.frame"); diff --git a/r/src/arrow_types.h b/r/src/arrow_types.h index bcc1869ef9bc9..5c2b05abd279d 100644 --- a/r/src/arrow_types.h +++ b/r/src/arrow_types.h @@ -43,14 +43,6 @@ struct data { } // namespace r } // namespace arrow -#define STOP_IF_NOT(TEST, MSG) \ - do { \ - if (!(TEST)) Rcpp::stop(MSG); \ - } while (0) - -#define STOP_IF_NOT_OK(status) StopIfNotOk(status) -#define VALUE_OR_STOP(result) ValueOrStop(result) - template struct NoDelete { inline void operator()(T* ptr) {} @@ -244,18 +236,18 @@ namespace fs = ::arrow::fs; namespace arrow { -template -auto ValueOrStop(R&& result) -> decltype(std::forward(result).ValueOrDie()) { - STOP_IF_NOT_OK(result.status()); - return std::forward(result).ValueOrDie(); -} - static inline void StopIfNotOk(const Status& status) { if (!(status.ok())) { Rcpp::stop(status.ToString()); } } +template +auto ValueOrStop(R&& result) -> decltype(std::forward(result).ValueOrDie()) { + StopIfNotOk(result.status()); + return std::forward(result).ValueOrDie(); +} + namespace r { Status count_fields(SEXP lst, int* out); diff --git a/r/src/chunkedarray.cpp b/r/src/chunkedarray.cpp index 749dc2d0589a6..5aeea8a47d0da 100644 --- a/r/src/chunkedarray.cpp +++ b/r/src/chunkedarray.cpp @@ -74,12 +74,12 @@ std::shared_ptr ChunkedArray__Slice2( std::shared_ptr ChunkedArray__View( const std::shared_ptr& array, const std::shared_ptr& type) { - return VALUE_OR_STOP(array->View(type)); + return ValueOrStop(array->View(type)); } // [[arrow::export]] void ChunkedArray__Validate(const std::shared_ptr& chunked_array) { - STOP_IF_NOT_OK(chunked_array->Validate()); + StopIfNotOk(chunked_array->Validate()); } // [[arrow::export]] diff --git a/r/src/compression.cpp b/r/src/compression.cpp index 63beed8489097..cef03f1bf124c 100644 --- a/r/src/compression.cpp +++ b/r/src/compression.cpp @@ -22,7 +22,7 @@ // [[arrow::export]] std::unique_ptr util___Codec__Create(arrow::Compression::type codec, int compression_level) { - return VALUE_OR_STOP(arrow::util::Codec::Create(codec, compression_level)); + return ValueOrStop(arrow::util::Codec::Create(codec, compression_level)); } // [[arrow::export]] @@ -39,14 +39,14 @@ bool util___Codec__IsAvailable(arrow::Compression::type codec) { std::shared_ptr io___CompressedOutputStream__Make( const std::unique_ptr& codec, const std::shared_ptr& raw) { - return VALUE_OR_STOP(arrow::io::CompressedOutputStream::Make(codec.get(), raw)); + return ValueOrStop(arrow::io::CompressedOutputStream::Make(codec.get(), raw)); } // [[arrow::export]] std::shared_ptr io___CompressedInputStream__Make( const std::unique_ptr& codec, const std::shared_ptr& raw) { - return VALUE_OR_STOP(arrow::io::CompressedInputStream::Make(codec.get(), raw)); + return ValueOrStop(arrow::io::CompressedInputStream::Make(codec.get(), raw)); } #endif diff --git a/r/src/compute.cpp b/r/src/compute.cpp index 212b27c8a608a..bf9935ab8b852 100644 --- a/r/src/compute.cpp +++ b/r/src/compute.cpp @@ -36,7 +36,7 @@ std::shared_ptr Array__cast( const std::shared_ptr& options) { std::shared_ptr out; arrow::compute::FunctionContext context; - STOP_IF_NOT_OK(arrow::compute::Cast(&context, *array, target_type, *options, &out)); + StopIfNotOk(arrow::compute::Cast(&context, *array, target_type, *options, &out)); return out; } @@ -48,7 +48,7 @@ std::shared_ptr ChunkedArray__cast( arrow::compute::Datum value(chunked_array); arrow::compute::Datum out; arrow::compute::FunctionContext context; - STOP_IF_NOT_OK(arrow::compute::Cast(&context, value, target_type, *options, &out)); + StopIfNotOk(arrow::compute::Cast(&context, value, target_type, *options, &out)); return out.chunked_array(); } @@ -88,7 +88,7 @@ std::shared_ptr Array__Take(const std::shared_ptr& v std::shared_ptr out; arrow::compute::FunctionContext context; arrow::compute::TakeOptions options; - STOP_IF_NOT_OK(arrow::compute::Take(&context, *values, *indices, options, &out)); + StopIfNotOk(arrow::compute::Take(&context, *values, *indices, options, &out)); return out; } @@ -100,7 +100,7 @@ std::shared_ptr Array__TakeChunked( arrow::compute::FunctionContext context; arrow::compute::TakeOptions options; - STOP_IF_NOT_OK(arrow::compute::Take(&context, *values, *indices, options, &out)); + StopIfNotOk(arrow::compute::Take(&context, *values, *indices, options, &out)); return out; } @@ -111,7 +111,7 @@ std::shared_ptr RecordBatch__Take( std::shared_ptr out; arrow::compute::FunctionContext context; arrow::compute::TakeOptions options; - STOP_IF_NOT_OK(arrow::compute::Take(&context, *batch, *indices, options, &out)); + StopIfNotOk(arrow::compute::Take(&context, *batch, *indices, options, &out)); return out; } @@ -123,7 +123,7 @@ std::shared_ptr ChunkedArray__Take( arrow::compute::FunctionContext context; arrow::compute::TakeOptions options; - STOP_IF_NOT_OK(arrow::compute::Take(&context, *values, *indices, options, &out)); + StopIfNotOk(arrow::compute::Take(&context, *values, *indices, options, &out)); return out; } @@ -135,7 +135,7 @@ std::shared_ptr ChunkedArray__TakeChunked( arrow::compute::FunctionContext context; arrow::compute::TakeOptions options; - STOP_IF_NOT_OK(arrow::compute::Take(&context, *values, *indices, options, &out)); + StopIfNotOk(arrow::compute::Take(&context, *values, *indices, options, &out)); return out; } @@ -146,7 +146,7 @@ std::shared_ptr Table__Take(const std::shared_ptr& t arrow::compute::FunctionContext context; arrow::compute::TakeOptions options; - STOP_IF_NOT_OK(arrow::compute::Take(&context, *table, *indices, options, &out)); + StopIfNotOk(arrow::compute::Take(&context, *table, *indices, options, &out)); return out; } @@ -158,7 +158,7 @@ std::shared_ptr Table__TakeChunked( arrow::compute::FunctionContext context; arrow::compute::TakeOptions options; - STOP_IF_NOT_OK(arrow::compute::Take(&context, *table, *indices, options, &out)); + StopIfNotOk(arrow::compute::Take(&context, *table, *indices, options, &out)); return out; } @@ -173,7 +173,7 @@ std::shared_ptr Array__Filter(const std::shared_ptr& if (keep_na) { options.null_selection_behavior = arrow::compute::FilterOptions::EMIT_NULL; } - STOP_IF_NOT_OK(arrow::compute::Filter(&context, values, filter, {}, &out)); + StopIfNotOk(arrow::compute::Filter(&context, values, filter, {}, &out)); return out.make_array(); } @@ -188,7 +188,7 @@ std::shared_ptr RecordBatch__Filter( if (keep_na) { options.null_selection_behavior = arrow::compute::FilterOptions::EMIT_NULL; } - STOP_IF_NOT_OK(arrow::compute::Filter(&context, batch, filter, options, &out)); + StopIfNotOk(arrow::compute::Filter(&context, batch, filter, options, &out)); return out.record_batch(); } @@ -203,7 +203,7 @@ std::shared_ptr ChunkedArray__Filter( if (keep_na) { options.null_selection_behavior = arrow::compute::FilterOptions::EMIT_NULL; } - STOP_IF_NOT_OK(arrow::compute::Filter(&context, values, filter, options, &out)); + StopIfNotOk(arrow::compute::Filter(&context, values, filter, options, &out)); return out.chunked_array(); } @@ -218,7 +218,7 @@ std::shared_ptr ChunkedArray__FilterChunked( if (keep_na) { options.null_selection_behavior = arrow::compute::FilterOptions::EMIT_NULL; } - STOP_IF_NOT_OK(arrow::compute::Filter(&context, values, filter, options, &out)); + StopIfNotOk(arrow::compute::Filter(&context, values, filter, options, &out)); return out.chunked_array(); } @@ -233,7 +233,7 @@ std::shared_ptr Table__Filter(const std::shared_ptr& if (keep_na) { options.null_selection_behavior = arrow::compute::FilterOptions::EMIT_NULL; } - STOP_IF_NOT_OK(arrow::compute::Filter(&context, table, filter, options, &out)); + StopIfNotOk(arrow::compute::Filter(&context, table, filter, options, &out)); std::shared_ptr tab = out.table(); if (tab->num_rows() == 0) { // Slight hack: if there are no rows in the result, instead do a 0-length @@ -255,7 +255,7 @@ std::shared_ptr Table__FilterChunked( if (keep_na) { options.null_selection_behavior = arrow::compute::FilterOptions::EMIT_NULL; } - STOP_IF_NOT_OK(arrow::compute::Filter(&context, table, filter, options, &out)); + StopIfNotOk(arrow::compute::Filter(&context, table, filter, options, &out)); std::shared_ptr tab = out.table(); if (tab->num_rows() == 0) { // Slight hack: if there are no rows in the result, instead do a 0-length diff --git a/r/src/csv.cpp b/r/src/csv.cpp index 9c71ea6dcb3db..a4432eb01b0bd 100644 --- a/r/src/csv.cpp +++ b/r/src/csv.cpp @@ -78,15 +78,15 @@ std::shared_ptr csv___TableReader__Make( const std::shared_ptr& read_options, const std::shared_ptr& parse_options, const std::shared_ptr& convert_options) { - return VALUE_OR_STOP(arrow::csv::TableReader::Make(arrow::default_memory_pool(), input, - *read_options, *parse_options, - *convert_options)); + return ValueOrStop(arrow::csv::TableReader::Make(arrow::default_memory_pool(), input, + *read_options, *parse_options, + *convert_options)); } // [[arrow::export]] std::shared_ptr csv___TableReader__Read( const std::shared_ptr& table_reader) { - return VALUE_OR_STOP(table_reader->Read()); + return ValueOrStop(table_reader->Read()); } #endif diff --git a/r/src/dataset.cpp b/r/src/dataset.cpp index e92ac03b83907..d5c9d836dd8de 100644 --- a/r/src/dataset.cpp +++ b/r/src/dataset.cpp @@ -27,7 +27,7 @@ using Rcpp::String; // [[arrow::export]] std::shared_ptr dataset___Dataset__NewScan( const std::shared_ptr& ds) { - return VALUE_OR_STOP(ds->NewScan()); + return ValueOrStop(ds->NewScan()); } // [[arrow::export]] @@ -45,13 +45,13 @@ std::string dataset___Dataset__type_name(const std::shared_ptr& dat std::shared_ptr dataset___Dataset__ReplaceSchema( const std::shared_ptr& dataset, const std::shared_ptr& schm) { - return VALUE_OR_STOP(dataset->ReplaceSchema(schm)); + return ValueOrStop(dataset->ReplaceSchema(schm)); } // [[arrow::export]] std::shared_ptr dataset___UnionDataset__create( const ds::DatasetVector& datasets, const std::shared_ptr& schm) { - return VALUE_OR_STOP(ds::UnionDataset::Make(schm, datasets)); + return ValueOrStop(ds::UnionDataset::Make(schm, datasets)); } // [[arrow::export]] @@ -81,14 +81,14 @@ std::shared_ptr dataset___DatasetFactory__Finish1( if (unify_schemas) { opts.inspect_options.fragments = ds::InspectOptions::kInspectAllFragments; } - return VALUE_OR_STOP(factory->Finish(opts)); + return ValueOrStop(factory->Finish(opts)); } // [[arrow::export]] std::shared_ptr dataset___DatasetFactory__Finish2( const std::shared_ptr& factory, const std::shared_ptr& schema) { - return VALUE_OR_STOP(factory->Finish(schema)); + return ValueOrStop(factory->Finish(schema)); } // [[arrow::export]] @@ -98,13 +98,13 @@ std::shared_ptr dataset___DatasetFactory__Inspect( if (unify_schemas) { opts.fragments = ds::InspectOptions::kInspectAllFragments; } - return VALUE_OR_STOP(factory->Inspect(opts)); + return ValueOrStop(factory->Inspect(opts)); } // [[arrow::export]] std::shared_ptr dataset___UnionDatasetFactory__Make( const std::vector>& children) { - return VALUE_OR_STOP(ds::UnionDatasetFactory::Make(children)); + return ValueOrStop(ds::UnionDatasetFactory::Make(children)); } // [[arrow::export]] @@ -119,8 +119,7 @@ std::shared_ptr dataset___FileSystemDatasetFactory__Make2( options.partitioning = partitioning; } - return VALUE_OR_STOP( - ds::FileSystemDatasetFactory::Make(fs, *selector, format, options)); + return ValueOrStop(ds::FileSystemDatasetFactory::Make(fs, *selector, format, options)); } // [[arrow::export]] @@ -143,8 +142,7 @@ std::shared_ptr dataset___FileSystemDatasetFactory__Make3( options.partitioning = factory; } - return VALUE_OR_STOP( - ds::FileSystemDatasetFactory::Make(fs, *selector, format, options)); + return ValueOrStop(ds::FileSystemDatasetFactory::Make(fs, *selector, format, options)); } // FileFormat, ParquetFileFormat, IpcFileFormat @@ -206,7 +204,7 @@ std::shared_ptr dataset___HivePartitioning__MakeFactory // [[arrow::export]] void dataset___ScannerBuilder__Project(const std::shared_ptr& sb, const std::vector& cols) { - STOP_IF_NOT_OK(sb->Project(cols)); + StopIfNotOk(sb->Project(cols)); } // [[arrow::export]] @@ -214,20 +212,20 @@ void dataset___ScannerBuilder__Filter(const std::shared_ptr& const std::shared_ptr& expr) { // Expressions converted from R's expressions are typed with R's native type, // i.e. double, int64_t and bool. - auto cast_filter = VALUE_OR_STOP(InsertImplicitCasts(*expr, *sb->schema())); - STOP_IF_NOT_OK(sb->Filter(cast_filter)); + auto cast_filter = ValueOrStop(InsertImplicitCasts(*expr, *sb->schema())); + StopIfNotOk(sb->Filter(cast_filter)); } // [[arrow::export]] void dataset___ScannerBuilder__UseThreads(const std::shared_ptr& sb, bool threads) { - STOP_IF_NOT_OK(sb->UseThreads(threads)); + StopIfNotOk(sb->UseThreads(threads)); } // [[arrow::export]] void dataset___ScannerBuilder__BatchSize(const std::shared_ptr& sb, int64_t batch_size) { - STOP_IF_NOT_OK(sb->BatchSize(batch_size)); + StopIfNotOk(sb->BatchSize(batch_size)); } // [[arrow::export]] @@ -239,24 +237,24 @@ std::shared_ptr dataset___ScannerBuilder__schema( // [[arrow::export]] std::shared_ptr dataset___ScannerBuilder__Finish( const std::shared_ptr& sb) { - return VALUE_OR_STOP(sb->Finish()); + return ValueOrStop(sb->Finish()); } // [[arrow::export]] std::shared_ptr dataset___Scanner__ToTable( const std::shared_ptr& scanner) { - return VALUE_OR_STOP(scanner->ToTable()); + return ValueOrStop(scanner->ToTable()); } // [[arrow::export]] std::vector> dataset___Scanner__Scan( const std::shared_ptr& scanner) { - auto it = VALUE_OR_STOP(scanner->Scan()); + auto it = ValueOrStop(scanner->Scan()); std::vector> out; std::shared_ptr scan_task; // TODO(npr): can this iteration be parallelized? for (auto st : it) { - scan_task = VALUE_OR_STOP(st); + scan_task = ValueOrStop(st); out.push_back(scan_task); } return out; @@ -266,11 +264,11 @@ std::vector> dataset___Scanner__Scan( std::vector> dataset___ScanTask__get_batches( const std::shared_ptr& scan_task) { arrow::RecordBatchIterator rbi; - rbi = VALUE_OR_STOP(scan_task->Execute()); + rbi = ValueOrStop(scan_task->Execute()); std::vector> out; std::shared_ptr batch; for (auto b : rbi) { - batch = VALUE_OR_STOP(b); + batch = ValueOrStop(b); out.push_back(batch); } return out; diff --git a/r/src/datatype.cpp b/r/src/datatype.cpp index bad97ea8241a9..87b3c96cc0aa4 100644 --- a/r/src/datatype.cpp +++ b/r/src/datatype.cpp @@ -89,7 +89,7 @@ std::shared_ptr Null__initialize() { return arrow::null(); } std::shared_ptr Decimal128Type__initialize(int32_t precision, int32_t scale) { // Use the builder that validates inputs - return VALUE_OR_STOP(arrow::Decimal128Type::Make(precision, scale)); + return ValueOrStop(arrow::Decimal128Type::Make(precision, scale)); } // [[arrow::export]] @@ -216,7 +216,7 @@ arrow::TimeUnit::type TimestampType__unit( std::shared_ptr DictionaryType__initialize( const std::shared_ptr& index_type, const std::shared_ptr& value_type, bool ordered) { - return VALUE_OR_STOP(arrow::DictionaryType::Make(index_type, value_type, ordered)); + return ValueOrStop(arrow::DictionaryType::Make(index_type, value_type, ordered)); } // [[arrow::export]] diff --git a/r/src/feather.cpp b/r/src/feather.cpp index 7ab73606f8b21..f60f8b5753ce4 100644 --- a/r/src/feather.cpp +++ b/r/src/feather.cpp @@ -33,7 +33,7 @@ void ipc___WriteFeather__Table(const std::shared_ptr& s if (compression_level != -1) { properties.compression_level = compression_level; } - STOP_IF_NOT_OK(arrow::ipc::feather::WriteTable(*table, stream.get(), properties)); + StopIfNotOk(arrow::ipc::feather::WriteTable(*table, stream.get(), properties)); } // ----------- Reader @@ -56,11 +56,11 @@ std::shared_ptr ipc___feather___Reader__Read( for (R_xlen_t i = 0; i < n; i++) { names[i] = CHAR(STRING_ELT(columns, i)); } - STOP_IF_NOT_OK(reader->Read(names, &table)); + StopIfNotOk(reader->Read(names, &table)); break; } case NILSXP: - STOP_IF_NOT_OK(reader->Read(&table)); + StopIfNotOk(reader->Read(&table)); break; default: Rcpp::stop("incompatible column specification"); @@ -73,7 +73,7 @@ std::shared_ptr ipc___feather___Reader__Read( // [[arrow::export]] std::shared_ptr ipc___feather___Reader__Open( const std::shared_ptr& stream) { - return VALUE_OR_STOP(arrow::ipc::feather::Reader::Open(stream)); + return ValueOrStop(arrow::ipc::feather::Reader::Open(stream)); } // [[arrow::export]] diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 54f249182250d..ce69332205c32 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -120,7 +120,7 @@ std::vector> shared_ptr_vector(const std::vector& vec) { std::vector> fs___FileSystem__GetTargetInfos_Paths( const std::shared_ptr& file_system, const std::vector& paths) { - auto results = VALUE_OR_STOP(file_system->GetFileInfo(paths)); + auto results = ValueOrStop(file_system->GetFileInfo(paths)); return shared_ptr_vector(results); } @@ -128,74 +128,74 @@ std::vector> fs___FileSystem__GetTargetInfos_Paths std::vector> fs___FileSystem__GetTargetInfos_FileSelector( const std::shared_ptr& file_system, const std::shared_ptr& selector) { - auto results = VALUE_OR_STOP(file_system->GetFileInfo(*selector)); + auto results = ValueOrStop(file_system->GetFileInfo(*selector)); return shared_ptr_vector(results); } // [[arrow::export]] void fs___FileSystem__CreateDir(const std::shared_ptr& file_system, const std::string& path, bool recursive) { - STOP_IF_NOT_OK(file_system->CreateDir(path, recursive)); + StopIfNotOk(file_system->CreateDir(path, recursive)); } // [[arrow::export]] void fs___FileSystem__DeleteDir(const std::shared_ptr& file_system, const std::string& path) { - STOP_IF_NOT_OK(file_system->DeleteDir(path)); + StopIfNotOk(file_system->DeleteDir(path)); } // [[arrow::export]] void fs___FileSystem__DeleteDirContents( const std::shared_ptr& file_system, const std::string& path) { - STOP_IF_NOT_OK(file_system->DeleteDirContents(path)); + StopIfNotOk(file_system->DeleteDirContents(path)); } // [[arrow::export]] void fs___FileSystem__DeleteFile(const std::shared_ptr& file_system, const std::string& path) { - STOP_IF_NOT_OK(file_system->DeleteFile(path)); + StopIfNotOk(file_system->DeleteFile(path)); } // [[arrow::export]] void fs___FileSystem__DeleteFiles(const std::shared_ptr& file_system, const std::vector& paths) { - STOP_IF_NOT_OK(file_system->DeleteFiles(paths)); + StopIfNotOk(file_system->DeleteFiles(paths)); } // [[arrow::export]] void fs___FileSystem__Move(const std::shared_ptr& file_system, const std::string& src, const std::string& dest) { - STOP_IF_NOT_OK(file_system->Move(src, dest)); + StopIfNotOk(file_system->Move(src, dest)); } // [[arrow::export]] void fs___FileSystem__CopyFile(const std::shared_ptr& file_system, const std::string& src, const std::string& dest) { - STOP_IF_NOT_OK(file_system->CopyFile(src, dest)); + StopIfNotOk(file_system->CopyFile(src, dest)); } // [[arrow::export]] std::shared_ptr fs___FileSystem__OpenInputStream( const std::shared_ptr& file_system, const std::string& path) { - return VALUE_OR_STOP(file_system->OpenInputStream(path)); + return ValueOrStop(file_system->OpenInputStream(path)); } // [[arrow::export]] std::shared_ptr fs___FileSystem__OpenInputFile( const std::shared_ptr& file_system, const std::string& path) { - return VALUE_OR_STOP(file_system->OpenInputFile(path)); + return ValueOrStop(file_system->OpenInputFile(path)); } // [[arrow::export]] std::shared_ptr fs___FileSystem__OpenOutputStream( const std::shared_ptr& file_system, const std::string& path) { - return VALUE_OR_STOP(file_system->OpenOutputStream(path)); + return ValueOrStop(file_system->OpenOutputStream(path)); } // [[arrow::export]] std::shared_ptr fs___FileSystem__OpenAppendStream( const std::shared_ptr& file_system, const std::string& path) { - return VALUE_OR_STOP(file_system->OpenAppendStream(path)); + return ValueOrStop(file_system->OpenAppendStream(path)); } // [[arrow::export]] @@ -218,7 +218,7 @@ std::shared_ptr fs___SubTreeFileSystem__create( // [[arrow::export]] Rcpp::List fs___FileSystemFromUri(const std::string& path) { std::string out_path; - auto file_system = VALUE_OR_STOP(fs::FileSystemFromUri(path, &out_path)); + auto file_system = ValueOrStop(fs::FileSystemFromUri(path, &out_path)); return Rcpp::List::create(Rcpp::Named("fs") = file_system, Rcpp::Named("path") = out_path); } @@ -228,12 +228,12 @@ Rcpp::List fs___FileSystemFromUri(const std::string& path) { #if defined(ARROW_R_WITH_S3) // [[s3::export]] -void fs___EnsureS3Initialized() { STOP_IF_NOT_OK(fs::EnsureS3Initialized()); } +void fs___EnsureS3Initialized() { StopIfNotOk(fs::EnsureS3Initialized()); } // [[s3::export]] std::shared_ptr fs___S3FileSystem__create() { auto opts = fs::S3Options::Defaults(); - return VALUE_OR_STOP(fs::S3FileSystem::Make(opts)); + return ValueOrStop(fs::S3FileSystem::Make(opts)); } #endif diff --git a/r/src/io.cpp b/r/src/io.cpp index dc7bcaeefa9b4..41d902a24939f 100644 --- a/r/src/io.cpp +++ b/r/src/io.cpp @@ -26,21 +26,21 @@ using Rcpp::RawVector_; // [[arrow::export]] std::shared_ptr io___Readable__Read( const std::shared_ptr& x, int64_t nbytes) { - return VALUE_OR_STOP(x->Read(nbytes)); + return ValueOrStop(x->Read(nbytes)); } // ------ arrow::io::InputStream // [[arrow::export]] void io___InputStream__Close(const std::shared_ptr& x) { - STOP_IF_NOT_OK(x->Close()); + StopIfNotOk(x->Close()); } // ------ arrow::io::OutputStream // [[arrow::export]] void io___OutputStream__Close(const std::shared_ptr& x) { - STOP_IF_NOT_OK(x->Close()); + StopIfNotOk(x->Close()); } // ------ arrow::io::RandomAccessFile @@ -48,7 +48,7 @@ void io___OutputStream__Close(const std::shared_ptr& x) // [[arrow::export]] int64_t io___RandomAccessFile__GetSize( const std::shared_ptr& x) { - return VALUE_OR_STOP(x->GetSize()); + return ValueOrStop(x->GetSize()); } // [[arrow::export]] @@ -60,30 +60,30 @@ bool io___RandomAccessFile__supports_zero_copy( // [[arrow::export]] void io___RandomAccessFile__Seek(const std::shared_ptr& x, int64_t position) { - STOP_IF_NOT_OK(x->Seek(position)); + StopIfNotOk(x->Seek(position)); } // [[arrow::export]] int64_t io___RandomAccessFile__Tell( const std::shared_ptr& x) { - return VALUE_OR_STOP(x->Tell()); + return ValueOrStop(x->Tell()); } // [[arrow::export]] std::shared_ptr io___RandomAccessFile__Read0( const std::shared_ptr& x) { - int64_t current = VALUE_OR_STOP(x->Tell()); + int64_t current = ValueOrStop(x->Tell()); - int64_t n = VALUE_OR_STOP(x->GetSize()); + int64_t n = ValueOrStop(x->GetSize()); - return VALUE_OR_STOP(x->Read(n - current)); + return ValueOrStop(x->Read(n - current)); } // [[arrow::export]] std::shared_ptr io___RandomAccessFile__ReadAt( const std::shared_ptr& x, int64_t position, int64_t nbytes) { - return VALUE_OR_STOP(x->ReadAt(position, nbytes)); + return ValueOrStop(x->ReadAt(position, nbytes)); } // ------ arrow::io::MemoryMappedFile @@ -91,19 +91,19 @@ std::shared_ptr io___RandomAccessFile__ReadAt( // [[arrow::export]] std::shared_ptr io___MemoryMappedFile__Create( const std::string& path, int64_t size) { - return VALUE_OR_STOP(arrow::io::MemoryMappedFile::Create(path, size)); + return ValueOrStop(arrow::io::MemoryMappedFile::Create(path, size)); } // [[arrow::export]] std::shared_ptr io___MemoryMappedFile__Open( const std::string& path, arrow::io::FileMode::type mode) { - return VALUE_OR_STOP(arrow::io::MemoryMappedFile::Open(path, mode)); + return ValueOrStop(arrow::io::MemoryMappedFile::Open(path, mode)); } // [[arrow::export]] void io___MemoryMappedFile__Resize(const std::shared_ptr& x, int64_t size) { - STOP_IF_NOT_OK(x->Resize(size)); + StopIfNotOk(x->Resize(size)); } // ------ arrow::io::ReadableFile @@ -111,7 +111,7 @@ void io___MemoryMappedFile__Resize(const std::shared_ptr io___ReadableFile__Open( const std::string& path) { - return VALUE_OR_STOP(arrow::io::ReadableFile::Open(path)); + return ValueOrStop(arrow::io::ReadableFile::Open(path)); } // ------ arrow::io::BufferReader @@ -127,14 +127,14 @@ std::shared_ptr io___BufferReader__initialize( // [[arrow::export]] void io___Writable__write(const std::shared_ptr& stream, const std::shared_ptr& buf) { - STOP_IF_NOT_OK(stream->Write(buf->data(), buf->size())); + StopIfNotOk(stream->Write(buf->data(), buf->size())); } // ------- arrow::io::OutputStream // [[arrow::export]] int64_t io___OutputStream__Tell(const std::shared_ptr& stream) { - return VALUE_OR_STOP(stream->Tell()); + return ValueOrStop(stream->Tell()); } // ------ arrow::io::FileOutputStream @@ -142,7 +142,7 @@ int64_t io___OutputStream__Tell(const std::shared_ptr& // [[arrow::export]] std::shared_ptr io___FileOutputStream__Open( const std::string& path) { - return VALUE_OR_STOP(arrow::io::FileOutputStream::Open(path)); + return ValueOrStop(arrow::io::FileOutputStream::Open(path)); } // ------ arrow::BufferOutputStream @@ -150,8 +150,8 @@ std::shared_ptr io___FileOutputStream__Open( // [[arrow::export]] std::shared_ptr io___BufferOutputStream__Create( int64_t initial_capacity) { - return VALUE_OR_STOP(arrow::io::BufferOutputStream::Create( - initial_capacity, arrow::default_memory_pool())); + return ValueOrStop(arrow::io::BufferOutputStream::Create(initial_capacity, + arrow::default_memory_pool())); } // [[arrow::export]] @@ -163,19 +163,19 @@ int64_t io___BufferOutputStream__capacity( // [[arrow::export]] std::shared_ptr io___BufferOutputStream__Finish( const std::shared_ptr& stream) { - return VALUE_OR_STOP(stream->Finish()); + return ValueOrStop(stream->Finish()); } // [[arrow::export]] int64_t io___BufferOutputStream__Tell( const std::shared_ptr& stream) { - return VALUE_OR_STOP(stream->Tell()); + return ValueOrStop(stream->Tell()); } // [[arrow::export]] void io___BufferOutputStream__Write( const std::shared_ptr& stream, RawVector_ bytes) { - STOP_IF_NOT_OK(stream->Write(bytes.begin(), bytes.size())); + StopIfNotOk(stream->Write(bytes.begin(), bytes.size())); } #endif diff --git a/r/src/json.cpp b/r/src/json.cpp index 0479121b08c75..8bbd04280bc16 100644 --- a/r/src/json.cpp +++ b/r/src/json.cpp @@ -47,7 +47,7 @@ std::shared_ptr json___TableReader__Make( const std::shared_ptr& read_options, const std::shared_ptr& parse_options) { std::shared_ptr table_reader; - STOP_IF_NOT_OK(arrow::json::TableReader::Make( + StopIfNotOk(arrow::json::TableReader::Make( arrow::default_memory_pool(), input, *read_options, *parse_options, &table_reader)); return table_reader; } @@ -56,7 +56,7 @@ std::shared_ptr json___TableReader__Make( std::shared_ptr json___TableReader__Read( const std::shared_ptr& table_reader) { std::shared_ptr table; - STOP_IF_NOT_OK(table_reader->Read(&table)); + StopIfNotOk(table_reader->Read(&table)); return table; } diff --git a/r/src/message.cpp b/r/src/message.cpp index 4d7115f5d88eb..92c4613d79730 100644 --- a/r/src/message.cpp +++ b/r/src/message.cpp @@ -59,8 +59,8 @@ std::shared_ptr ipc___ReadRecordBatch__Message__Schema( const std::shared_ptr& schema) { // TODO: perhaps this should come from the R side arrow::ipc::DictionaryMemo memo; - return VALUE_OR_STOP(arrow::ipc::ReadRecordBatch( - *message, schema, &memo, arrow::ipc::IpcReadOptions::Defaults())); + return ValueOrStop(arrow::ipc::ReadRecordBatch(*message, schema, &memo, + arrow::ipc::IpcReadOptions::Defaults())); } // [[arrow::export]] @@ -68,14 +68,14 @@ std::shared_ptr ipc___ReadSchema_InputStream( const std::shared_ptr& stream) { // TODO: promote to function argument arrow::ipc::DictionaryMemo memo; - return VALUE_OR_STOP(arrow::ipc::ReadSchema(stream.get(), &memo)); + return ValueOrStop(arrow::ipc::ReadSchema(stream.get(), &memo)); } // [[arrow::export]] std::shared_ptr ipc___ReadSchema_Message( const std::unique_ptr& message) { arrow::ipc::DictionaryMemo empty_memo; - return VALUE_OR_STOP(arrow::ipc::ReadSchema(*message, &empty_memo)); + return ValueOrStop(arrow::ipc::ReadSchema(*message, &empty_memo)); } //--------- MessageReader @@ -89,13 +89,13 @@ std::unique_ptr ipc___MessageReader__Open( // [[arrow::export]] std::unique_ptr ipc___MessageReader__ReadNextMessage( const std::unique_ptr& reader) { - return VALUE_OR_STOP(reader->ReadNextMessage()); + return ValueOrStop(reader->ReadNextMessage()); } // [[arrow::export]] std::unique_ptr ipc___ReadMessage( const std::shared_ptr& stream) { - return VALUE_OR_STOP(arrow::ipc::ReadMessage(stream.get())); + return ValueOrStop(arrow::ipc::ReadMessage(stream.get())); } #endif diff --git a/r/src/parquet.cpp b/r/src/parquet.cpp index 562bc5d3d7af1..a2b389396f44e 100644 --- a/r/src/parquet.cpp +++ b/r/src/parquet.cpp @@ -296,7 +296,7 @@ void parquet___arrow___WriteTable( std::shared_ptr parquet___arrow___FileReader__GetSchema( const std::unique_ptr& reader) { std::shared_ptr schema; - STOP_IF_NOT_OK(reader->GetSchema(&schema)); + StopIfNotOk(reader->GetSchema(&schema)); return schema; } diff --git a/r/src/py-to-r.cpp b/r/src/py-to-r.cpp index 491ee5730eabe..021b8f4890b56 100644 --- a/r/src/py-to-r.cpp +++ b/r/src/py-to-r.cpp @@ -21,13 +21,13 @@ // [[arrow::export]] std::shared_ptr ImportArray(uintptr_t array, uintptr_t schema) { - return VALUE_OR_STOP(arrow::ImportArray(reinterpret_cast(array), - reinterpret_cast(schema))); + return ValueOrStop(arrow::ImportArray(reinterpret_cast(array), + reinterpret_cast(schema))); } // [[arrow::export]] std::shared_ptr ImportRecordBatch(uintptr_t array, uintptr_t schema) { - return VALUE_OR_STOP( + return ValueOrStop( arrow::ImportRecordBatch(reinterpret_cast(array), reinterpret_cast(schema))); } @@ -50,26 +50,25 @@ void delete_arrow_array(uintptr_t ptr) { // [[arrow::export]] void ExportType(const std::shared_ptr& type, uintptr_t ptr) { - STOP_IF_NOT_OK(arrow::ExportType(*type, reinterpret_cast(ptr))); + StopIfNotOk(arrow::ExportType(*type, reinterpret_cast(ptr))); } // [[arrow::export]] void ExportSchema(const std::shared_ptr& schema, uintptr_t ptr) { - STOP_IF_NOT_OK( - arrow::ExportSchema(*schema, reinterpret_cast(ptr))); + StopIfNotOk(arrow::ExportSchema(*schema, reinterpret_cast(ptr))); } // [[arrow::export]] void ExportArray(const std::shared_ptr& array, uintptr_t ptr, uintptr_t schema_ptr) { - STOP_IF_NOT_OK(arrow::ExportArray(*array, reinterpret_cast(ptr), - reinterpret_cast(schema_ptr))); + StopIfNotOk(arrow::ExportArray(*array, reinterpret_cast(ptr), + reinterpret_cast(schema_ptr))); } // [[arrow::export]] void ExportRecordBatch(const std::shared_ptr& batch, uintptr_t ptr, uintptr_t schema_ptr) { - STOP_IF_NOT_OK( + StopIfNotOk( arrow::ExportRecordBatch(*batch, reinterpret_cast(ptr), reinterpret_cast(schema_ptr))); } diff --git a/r/src/recordbatch.cpp b/r/src/recordbatch.cpp index eb375c5df7845..2cbc65666af44 100644 --- a/r/src/recordbatch.cpp +++ b/r/src/recordbatch.cpp @@ -112,7 +112,7 @@ bool RecordBatch__Equals(const std::shared_ptr& self, std::shared_ptr RecordBatch__RemoveColumn( const std::shared_ptr& batch, int i) { arrow::r::validate_index(i, batch->num_columns()); - return VALUE_OR_STOP(batch->RemoveColumn(i)); + return ValueOrStop(batch->RemoveColumn(i)); } // [[arrow::export]] @@ -153,7 +153,7 @@ Rcpp::RawVector ipc___SerializeRecordBatch__Raw( const std::shared_ptr& batch) { // how many bytes do we need ? int64_t size; - STOP_IF_NOT_OK(arrow::ipc::GetRecordBatchSize(*batch, &size)); + StopIfNotOk(arrow::ipc::GetRecordBatchSize(*batch, &size)); // allocate the result raw vector Rcpp::RawVector out(Rcpp::no_init(size)); @@ -161,9 +161,9 @@ Rcpp::RawVector ipc___SerializeRecordBatch__Raw( // serialize into the bytes of the raw vector auto buffer = std::make_shared>(out); arrow::io::FixedSizeBufferWriter stream(buffer); - STOP_IF_NOT_OK(arrow::ipc::SerializeRecordBatch( + StopIfNotOk(arrow::ipc::SerializeRecordBatch( *batch, arrow::ipc::IpcWriteOptions::Defaults(), &stream)); - STOP_IF_NOT_OK(stream.Close()); + StopIfNotOk(stream.Close()); return out; } @@ -174,7 +174,7 @@ std::shared_ptr ipc___ReadRecordBatch__InputStream__Schema( const std::shared_ptr& schema) { // TODO: promote to function arg arrow::ipc::DictionaryMemo memo; - return VALUE_OR_STOP(arrow::ipc::ReadRecordBatch( + return ValueOrStop(arrow::ipc::ReadRecordBatch( schema, &memo, arrow::ipc::IpcReadOptions::Defaults(), stream.get())); } @@ -223,7 +223,7 @@ Status count_fields(SEXP lst, int* out) { std::shared_ptr RecordBatch__from_arrays__known_schema( const std::shared_ptr& schema, SEXP lst) { int num_fields; - STOP_IF_NOT_OK(arrow::r::count_fields(lst, &num_fields)); + StopIfNotOk(arrow::r::count_fields(lst, &num_fields)); if (schema->num_fields() != num_fields) { Rcpp::stop("incompatible. schema has %d fields, and %d arrays are supplied", @@ -258,7 +258,7 @@ std::shared_ptr RecordBatch__from_arrays__known_schema( } int64_t num_rows = 0; - STOP_IF_NOT_OK(arrow::r::check_consistent_array_size(arrays, &num_rows)); + StopIfNotOk(arrow::r::check_consistent_array_size(arrays, &num_rows)); return arrow::RecordBatch::Make(schema, num_rows, arrays); } @@ -270,7 +270,7 @@ std::shared_ptr RecordBatch__from_arrays(SEXP schema_sxp, SE } int num_fields; - STOP_IF_NOT_OK(arrow::r::count_fields(lst, &num_fields)); + StopIfNotOk(arrow::r::count_fields(lst, &num_fields)); // convert lst to a vector of arrow::Array std::vector> arrays(num_fields); @@ -307,7 +307,7 @@ std::shared_ptr RecordBatch__from_arrays(SEXP schema_sxp, SE // check all sizes are the same int64_t num_rows = 0; - STOP_IF_NOT_OK(arrow::r::check_consistent_array_size(arrays, &num_rows)); + StopIfNotOk(arrow::r::check_consistent_array_size(arrays, &num_rows)); return arrow::RecordBatch::Make(schema, num_rows, arrays); } diff --git a/r/src/recordbatchreader.cpp b/r/src/recordbatchreader.cpp index 3fce4d094fbc7..2405bf827a0c1 100644 --- a/r/src/recordbatchreader.cpp +++ b/r/src/recordbatchreader.cpp @@ -29,7 +29,7 @@ std::shared_ptr RecordBatchReader__schema( std::shared_ptr RecordBatchReader__ReadNext( const std::shared_ptr& reader) { std::shared_ptr batch; - STOP_IF_NOT_OK(reader->ReadNext(&batch)); + StopIfNotOk(reader->ReadNext(&batch)); return batch; } @@ -39,7 +39,7 @@ std::shared_ptr RecordBatchReader__ReadNext( std::shared_ptr ipc___RecordBatchStreamReader__Open( const std::shared_ptr& stream) { std::shared_ptr reader; - return VALUE_OR_STOP(arrow::ipc::RecordBatchStreamReader::Open(stream)); + return ValueOrStop(arrow::ipc::RecordBatchStreamReader::Open(stream)); } // [[arrow::export]] @@ -49,7 +49,7 @@ std::vector> ipc___RecordBatchStreamReader__ while (true) { std::shared_ptr batch; - STOP_IF_NOT_OK(reader->ReadNext(&batch)); + StopIfNotOk(reader->ReadNext(&batch)); if (!batch) break; res.push_back(batch); @@ -78,14 +78,14 @@ std::shared_ptr ipc___RecordBatchFileReader__ReadRecordBatch if (i < 0 && i >= reader->num_record_batches()) { Rcpp::stop("Record batch index out of bounds"); } - return VALUE_OR_STOP(reader->ReadRecordBatch(i)); + return ValueOrStop(reader->ReadRecordBatch(i)); } // [[arrow::export]] std::shared_ptr ipc___RecordBatchFileReader__Open( const std::shared_ptr& file) { std::shared_ptr reader; - return VALUE_OR_STOP(arrow::ipc::RecordBatchFileReader::Open(file)); + return ValueOrStop(arrow::ipc::RecordBatchFileReader::Open(file)); } // [[arrow::export]] @@ -94,10 +94,10 @@ std::shared_ptr Table__from_RecordBatchFileReader( int num_batches = reader->num_record_batches(); std::vector> batches(num_batches); for (int i = 0; i < num_batches; i++) { - batches[i] = VALUE_OR_STOP(reader->ReadRecordBatch(i)); + batches[i] = ValueOrStop(reader->ReadRecordBatch(i)); } - return VALUE_OR_STOP(arrow::Table::FromRecordBatches(std::move(batches))); + return ValueOrStop(arrow::Table::FromRecordBatches(std::move(batches))); } // [[arrow::export]] @@ -106,12 +106,12 @@ std::shared_ptr Table__from_RecordBatchStreamReader( std::shared_ptr batch; std::vector> batches; while (true) { - STOP_IF_NOT_OK(reader->ReadNext(&batch)); + StopIfNotOk(reader->ReadNext(&batch)); if (!batch) break; batches.push_back(batch); } - return VALUE_OR_STOP(arrow::Table::FromRecordBatches(std::move(batches))); + return ValueOrStop(arrow::Table::FromRecordBatches(std::move(batches))); } // [[arrow::export]] @@ -121,7 +121,7 @@ std::vector> ipc___RecordBatchFileReader__ba std::vector> res(n); for (int i = 0; i < n; i++) { - res[i] = VALUE_OR_STOP(reader->ReadRecordBatch(i)); + res[i] = ValueOrStop(reader->ReadRecordBatch(i)); } return res; diff --git a/r/src/recordbatchwriter.cpp b/r/src/recordbatchwriter.cpp index c6ff171f80b71..847b3354d39fa 100644 --- a/r/src/recordbatchwriter.cpp +++ b/r/src/recordbatchwriter.cpp @@ -23,20 +23,20 @@ void ipc___RecordBatchWriter__WriteRecordBatch( const std::shared_ptr& batch_writer, const std::shared_ptr& batch) { - STOP_IF_NOT_OK(batch_writer->WriteRecordBatch(*batch)); + StopIfNotOk(batch_writer->WriteRecordBatch(*batch)); } // [[arrow::export]] void ipc___RecordBatchWriter__WriteTable( const std::shared_ptr& batch_writer, const std::shared_ptr& table) { - STOP_IF_NOT_OK(batch_writer->WriteTable(*table)); + StopIfNotOk(batch_writer->WriteTable(*table)); } // [[arrow::export]] void ipc___RecordBatchWriter__Close( const std::shared_ptr& batch_writer) { - STOP_IF_NOT_OK(batch_writer->Close()); + StopIfNotOk(batch_writer->Close()); } // [[arrow::export]] @@ -45,7 +45,7 @@ std::shared_ptr ipc___RecordBatchFileWriter__Open const std::shared_ptr& schema, bool use_legacy_format) { auto options = arrow::ipc::IpcWriteOptions::Defaults(); options.write_legacy_ipc_format = use_legacy_format; - return VALUE_OR_STOP(arrow::ipc::NewFileWriter(stream.get(), schema, options)); + return ValueOrStop(arrow::ipc::NewFileWriter(stream.get(), schema, options)); } // [[arrow::export]] @@ -54,7 +54,7 @@ std::shared_ptr ipc___RecordBatchStreamWriter__Op const std::shared_ptr& schema, bool use_legacy_format) { auto options = arrow::ipc::IpcWriteOptions::Defaults(); options.write_legacy_ipc_format = use_legacy_format; - return VALUE_OR_STOP(NewStreamWriter(stream.get(), schema, options)); + return ValueOrStop(NewStreamWriter(stream.get(), schema, options)); } #endif diff --git a/r/src/schema.cpp b/r/src/schema.cpp index af747311c4c13..35de1519f919d 100644 --- a/r/src/schema.cpp +++ b/r/src/schema.cpp @@ -85,7 +85,7 @@ std::shared_ptr Schema__WithMetadata( Rcpp::RawVector Schema__serialize(const std::shared_ptr& schema) { arrow::ipc::DictionaryMemo empty_memo; std::shared_ptr out = - VALUE_OR_STOP(arrow::ipc::SerializeSchema(*schema, &empty_memo)); + ValueOrStop(arrow::ipc::SerializeSchema(*schema, &empty_memo)); auto n = out->size(); Rcpp::RawVector vec(out->size()); @@ -103,7 +103,7 @@ bool Schema__Equals(const std::shared_ptr& schema, // [[arrow::export]] std::shared_ptr arrow__UnifySchemas( const std::vector>& schemas) { - return VALUE_OR_STOP(arrow::UnifySchemas(schemas)); + return ValueOrStop(arrow::UnifySchemas(schemas)); } #endif diff --git a/r/src/table.cpp b/r/src/table.cpp index 2b9fc4fd0f60d..2681548abbef9 100644 --- a/r/src/table.cpp +++ b/r/src/table.cpp @@ -28,7 +28,7 @@ using Rcpp::DataFrame; std::shared_ptr Table__from_dataframe(DataFrame tbl) { auto rb = RecordBatch__from_dataframe(tbl); - return VALUE_OR_STOP(arrow::Table::FromRecordBatches({std::move(rb)})); + return ValueOrStop(arrow::Table::FromRecordBatches({std::move(rb)})); } // [[arrow::export]] @@ -97,13 +97,13 @@ bool Table__Equals(const std::shared_ptr& lhs, // [[arrow::export]] bool Table__Validate(const std::shared_ptr& table) { - STOP_IF_NOT_OK(table->Validate()); + StopIfNotOk(table->Validate()); return true; } // [[arrow::export]] bool Table__ValidateFull(const std::shared_ptr& table) { - STOP_IF_NOT_OK(table->ValidateFull()); + StopIfNotOk(table->ValidateFull()); return true; } @@ -150,15 +150,15 @@ std::shared_ptr Table__from_dots(SEXP lst, SEXP schema_sxp) { if (Rf_inherits(schema_sxp, "Schema")) { auto schema = arrow::r::extract(schema_sxp); - tab = VALUE_OR_STOP(arrow::Table::FromRecordBatches(schema, std::move(batches))); + tab = ValueOrStop(arrow::Table::FromRecordBatches(schema, std::move(batches))); } else { - tab = VALUE_OR_STOP(arrow::Table::FromRecordBatches(std::move(batches))); + tab = ValueOrStop(arrow::Table::FromRecordBatches(std::move(batches))); } return tab; } int num_fields; - STOP_IF_NOT_OK(arrow::r::count_fields(lst, &num_fields)); + StopIfNotOk(arrow::r::count_fields(lst, &num_fields)); std::vector> columns(num_fields); std::shared_ptr schema; diff --git a/r/src/threadpool.cpp b/r/src/threadpool.cpp index b7a8c825045d9..0a2013d03049d 100644 --- a/r/src/threadpool.cpp +++ b/r/src/threadpool.cpp @@ -45,7 +45,7 @@ int GetCpuThreadPoolCapacity() { return arrow::GetCpuThreadPoolCapacity(); } //' @export // [[arrow::export]] void SetCpuThreadPoolCapacity(int threads) { - STOP_IF_NOT_OK(arrow::SetCpuThreadPoolCapacity(threads)); + StopIfNotOk(arrow::SetCpuThreadPoolCapacity(threads)); } #endif