From 6ee9a0e494ea9e8ce64dfde6c3ebb27e86ff703b Mon Sep 17 00:00:00 2001 From: Eero Lihavainen Date: Sat, 30 Sep 2023 18:23:31 +0300 Subject: [PATCH] new version --- cpp/src/arrow/dataset/file_parquet.cc | 58 ++++++++++++--------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/cpp/src/arrow/dataset/file_parquet.cc b/cpp/src/arrow/dataset/file_parquet.cc index 091bf2ed4631a..5d62bc31304bb 100644 --- a/cpp/src/arrow/dataset/file_parquet.cc +++ b/cpp/src/arrow/dataset/file_parquet.cc @@ -479,40 +479,34 @@ Future> ParquetFileFormat::GetReader default_fragment_scan_options)); auto properties = MakeReaderProperties(*this, parquet_scan_options.get(), options->pool); - auto input_fut = source.OpenAsync(); - // TODO(ARROW-12259): workaround since we have Future<(move-only type)> - - auto path = source.path(); - auto reader_fut = - input_fut.Then([=](const std::shared_ptr&) mutable - -> Result> { - ARROW_ASSIGN_OR_RAISE(std::shared_ptr input, - input_fut.MoveResult()); - auto rfut = parquet::ParquetFileReader::OpenAsync( - std::move(input), std::move(properties), metadata); - ARROW_ASSIGN_OR_RAISE(auto reader, rfut.MoveResult()); - return reader; - }); auto self = checked_pointer_cast(shared_from_this()); - return reader_fut.Then( - [=](const std::unique_ptr&) mutable - -> Result> { - ARROW_ASSIGN_OR_RAISE(std::unique_ptr reader, - reader_fut.MoveResult()); - std::shared_ptr metadata = reader->metadata(); - auto arrow_properties = - MakeArrowReaderProperties(*this, *metadata, *options, *parquet_scan_options); - std::unique_ptr arrow_reader; - RETURN_NOT_OK(parquet::arrow::FileReader::Make(options->pool, std::move(reader), - std::move(arrow_properties), - &arrow_reader)); - return std::move(arrow_reader); - }, - [path]( - const Status& status) -> Result> { - return WrapSourceError(status, path); - }); + + return source.OpenAsync().Then([=](const std::shared_ptr& input) mutable { + return parquet::ParquetFileReader::OpenAsync(input, std::move(properties), metadata) + .Then( + [=](const std::unique_ptr& reader) mutable + -> Result> { + auto arrow_properties = MakeArrowReaderProperties( + *self, *reader->metadata(), *options, *parquet_scan_options); + + std::unique_ptr arrow_reader; + RETURN_NOT_OK(parquet::arrow::FileReader::Make( + options->pool, + // TODO(ARROW-12259): workaround since we have Future<(move-only type)> + // It *wouldn't* be safe to const_cast reader except that here we know + // there are no other waiters on the reader. + std::move( + const_cast&>(reader)), + std::move(arrow_properties), &arrow_reader)); + + return std::move(arrow_reader); + }, + [path = source.path()](const Status& status) + -> Result> { + return WrapSourceError(status, path); + }); + }); } struct SlicingGenerator {