Skip to content

ARROW-13135: [C++] Fix Status propagation from Parquet exception - #10566

Closed
pitrou wants to merge 4 commits into
apache:masterfrom
pitrou:ARROW-13135-parquet-status-exception
Closed

ARROW-13135: [C++] Fix Status propagation from Parquet exception#10566
pitrou wants to merge 4 commits into
apache:masterfrom
pitrou:ARROW-13135-parquet-status-exception

Conversation

@pitrou

@pitrou pitrou commented Jun 21, 2021

Copy link
Copy Markdown
Member

No description provided.

@pitrou
pitrou requested a review from bkietz June 21, 2021 14:48
@github-actions

Copy link
Copy Markdown

@bkietz bkietz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some minor style nits

Comment thread cpp/src/arrow/dataset/file_parquet.cc Outdated
Comment thread cpp/src/arrow/dataset/file_parquet.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less fragile than macros would be:

  auto maybe_reader = parquet::CatchNotOk([&] {
    return parquet::ParquetFileReader::Open(std::move(input), std::move(properties));
  });

Could be implemented like:

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm a bit lukewarm. Other similar functionality is already managed as macros (ARROW_RETURN_NOT_OK, RETURN_IF_PYERROR...). It seems like it would introduce a gratuitous variation. Also, given the size of the C++ metaprogramming alternative, this is possibly a reasonable use case for a macro.

@pitrou
pitrou force-pushed the ARROW-13135-parquet-status-exception branch from ed0eb0d to bccfaa5 Compare June 22, 2021 10:20
@pitrou
pitrou force-pushed the ARROW-13135-parquet-status-exception branch from bccfaa5 to f337dab Compare June 22, 2021 15:01
@pitrou

pitrou commented Jun 22, 2021

Copy link
Copy Markdown
Member Author

Rebased to fix conflicts, will merge if CI green.

@pitrou

pitrou commented Jun 22, 2021

Copy link
Copy Markdown
Member Author

CI failures are unrelated.

@pitrou pitrou closed this in da841cc Jun 22, 2021
@pitrou
pitrou deleted the ARROW-13135-parquet-status-exception branch June 22, 2021 18:17
sjperkins pushed a commit to sjperkins/arrow that referenced this pull request Jun 23, 2021
Closes apache#10566 from pitrou/ARROW-13135-parquet-status-exception

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants