bkietz commented on a change in pull request #10566:
URL: https://github.com/apache/arrow/pull/10566#discussion_r655503062



##########
File path: cpp/src/arrow/dataset/file_parquet.cc
##########
@@ -270,24 +279,29 @@ ParquetFileFormat::ParquetFileFormat(const 
parquet::ReaderProperties& reader_pro
 }
 
 Result<bool> ParquetFileFormat::IsSupported(const FileSource& source) const {
-  try {
-    ARROW_ASSIGN_OR_RAISE(auto input, source.Open());
-    ARROW_ASSIGN_OR_RAISE(auto parquet_scan_options,
-                          GetFragmentScanOptions<ParquetFragmentScanOptions>(
-                              kParquetTypeName, nullptr, 
default_fragment_scan_options));
-    auto reader = parquet::ParquetFileReader::Open(
-        std::move(input), MakeReaderProperties(*this, 
parquet_scan_options.get()));
-    std::shared_ptr<parquet::FileMetaData> metadata = reader->metadata();
-    return metadata != nullptr && metadata->can_decompress();
-  } catch (const ::parquet::ParquetInvalidOrCorruptedFileException& e) {
-    ARROW_UNUSED(e);
-    return false;
-  } catch (const ::parquet::ParquetException& e) {
-    return Status::IOError("Could not open parquet input source '", 
source.path(),
-                           "': ", e.what());
-  }
-
-  return true;
+  auto maybe_is_supported = [&]() -> Result<bool> {

Review comment:
       Please move this to `IsSupportedImpl` or so, then
   ```suggestion
     auto maybe_is_supported = IsSupportedImpl(*this, source);
   ```

##########
File path: cpp/src/arrow/dataset/file_parquet.cc
##########
@@ -307,14 +321,17 @@ Result<std::unique_ptr<parquet::arrow::FileReader>> 
ParquetFileFormat::GetReader
   auto properties = MakeReaderProperties(*this, parquet_scan_options.get(), 
pool);
 
   ARROW_ASSIGN_OR_RAISE(auto input, source.Open());
-  std::unique_ptr<parquet::ParquetFileReader> reader;
-  try {
-    reader = parquet::ParquetFileReader::Open(std::move(input), 
std::move(properties));
-  } catch (const ::parquet::ParquetException& e) {
-    return Status::IOError("Could not open parquet input source '", 
source.path(),
-                           "': ", e.what());
-  }
 
+  auto maybe_reader = [&]() -> 
Result<std::unique_ptr<parquet::ParquetFileReader>> {

Review comment:
       Less fragile than macros would be:
   
   ```c++
     auto maybe_reader = parquet::CatchNotOk([&] {
       return parquet::ParquetFileReader::Open(std::move(input), 
std::move(properties));
     });
   ```
   
   Could be implemented like:
   
   ```c++
   template <typename Fn, typename Ret>
   struct CatchNotOkImpl {
     static typename EnsureResult<Ret>::type Call(Fn&& fn) { return 
std::forward<Fn>(fn)(); }
   };
   
   template <typename Fn>
   struct CatchNotOkImpl<Fn, Status> {
     static Status Call(Fn&& fn) { return std::forward<Fn>(fn)(); }
   };
   
   template <typename Fn>
   struct CatchNotOkImpl<Fn, void> {
     static Status Call(Fn&& fn) {
       std::forward<Fn>(fn)();
       return Status::OK();
     }
   };
   
   template <typename Fn, typename Impl = CatchNotOkImpl<Fn, 
decltype(std::declval<Fn>()())>>
   auto CatchNotOk(Fn&& fn) -> decltype(Impl::Call(std::forward<Fn>(fn))) try {
     return Impl::Call(std::forward<Fn>(fn));
   } catch (const ParquetStatusException& e) {
     return e.status();
   } catch (const ParquetException& e) {
     return Status::IOError(e.what());
   }
   ```
   
   What do you think?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to