Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable no-throw behavior for simple functions #9659

Closed

Conversation

mbasmanova
Copy link
Contributor

Summary:
Throwing exceptions is expensive. When many rows throw exceptions that are being suppressed by TRY, query performance degrades a lot.

Vector functions may avoid throwing exceptions by calling EvalCtx::setError, but Simple functions can only throw.

This change introduces new 'call' method to be used by Simple function to avoid throwing:

Status call(result, arg1, arg2,...);

This method can report errors via Status without throwing.

This change allows default-null-behavior functions to avoid throwing. More changes are needed to allow all simple functions to avoid throwing.

Differential Revision: D56705407

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 29, 2024
Copy link

netlify bot commented Apr 29, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 7a6e6aa
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/6631218e8bc1770008ac500e

@mbasmanova mbasmanova requested a review from pedroerp April 29, 2024 17:56
@mbasmanova mbasmanova force-pushed the export-D56705407 branch 3 times, most recently from 5a64a6a to fce47c7 Compare April 29, 2024 18:12
Copy link
Contributor

@pedroerp pedroerp left a comment

Choose a reason for hiding this comment

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

Small comment, but overall looks good. Thanks!

if constexpr (udf_has_call_return_bool) {

if constexpr (udf_has_call_return_status) {
notNull = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

so the new call function cannot return nulls for now, and support for this will be added in a future PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right.

@@ -172,6 +172,36 @@ auto throwError(const std::exception_ptr& exceptionPtr) {
}
} // namespace

void EvalCtx::setStatus(vector_size_t index, Status status) {
VELOX_DCHECK(!status.ok());
Copy link
Contributor

Choose a reason for hiding this comment

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

wonder if we should have an actual check. Otherwise in non-debug code an "ok" will be wrapped as a runtime error.

struct NoThrowFunction {
VELOX_DEFINE_FUNCTION_TYPES(TExec);

Status call(out_type<int64_t>& out, const arg_type<int64_t>& in) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe tests what happens if you have a runtime error? Should it always "throw" right away, or does "try" also swallow it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have consistency here at the moment. TRY should suppress only USER errors. EvalCtx::applyToSelectedNoThrow throws non-USER errors and stores USER errors. However. EvalCtx::setError stores all errors. I think it makes sense for EvalCtx::setStatus to match EvalCtx::applyToSelectedNoThrow and store USER errors while throwing other errors. Let me know if you think otherwise.

@@ -1303,14 +1303,17 @@ struct DateParseFunction {
}

auto dateTimeResult =
format_->parse(std::string_view(input.data(), input.size()), true)
.value();
format_->parse(std::string_view(input.data(), input.size()));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can't you do implicit cast from StringView into string_view? If not, explicit should work:

  format_->parse(input);

or

  format_->parse((std::string_view)input);

Summary:
Throwing exceptions is expensive. When many rows throw exceptions that are being suppressed by TRY, query performance degrades a lot.

Vector functions may avoid throwing exceptions by calling EvalCtx::setError, but Simple functions can only throw.

This change introduces new 'call' method to be used by Simple function to avoid throwing:

```
Status call(result, arg1, arg2,...);
```

This method can report errors via Status without throwing.

This change allows default-null-behavior functions to avoid throwing. More changes are needed to allow all simple functions to avoid throwing.

Use the new API to avoid throwing in date_parse Presto function.

Reviewed By: pedroerp

Differential Revision: D56705407
@mbasmanova
Copy link
Contributor Author

@pedroerp Pedro, thank you for review. I updated the PR to address your comments.

Copy link
Contributor

@pedroerp pedroerp left a comment

Choose a reason for hiding this comment

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

Thank you!

@mbasmanova mbasmanova closed this May 24, 2024
facebook-github-bot pushed a commit that referenced this pull request Jun 28, 2024
…0274)

Summary:
This pr continues the no-throw-exception optimization for more simple
function methods, following the work of PR #9659.

Fixes #10265

Pull Request resolved: #10274

Reviewed By: xiaoxmeng

Differential Revision: D59012420

Pulled By: bikramSingh91

fbshipit-source-id: 3b409782f3ab4e2e401e4027ae251cf552d4620c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants