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

Improve evaluateOnce() helper function #9708

Closed
wants to merge 1 commit into from

Conversation

pedroerp
Copy link
Contributor

@pedroerp pedroerp commented May 4, 2024

Summary:
Improving the evaluateOnce() helper function to allow for more
flexibility when specifying input logical types. Also deprecating an old
overload of the function that only allowed multiple parameters with they had
the same type.
.
For a lot more details, check the header documentation added.

Differential Revision: D56962773

@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 May 4, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56962773

Copy link

netlify bot commented May 4, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 8f2a9f2
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/663993b5f6701a0008f7d8af

@pedroerp pedroerp requested review from mbasmanova and svm1 May 4, 2024 17:25
Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@pedroerp This is looking very nice. Thank you for improving this helper function. Some nits.

/// physical type that represent the custom type (e.g. `CustomType<T>::type`).
/// For example, use `int64_t` to return TIMESTAMP_WITH_TIME_ZONE()
///
/// Input parameters and output should always wrapped in an std::optional to
Copy link
Contributor

Choose a reason for hiding this comment

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

typos: Input and output parameters should always be wrapped ...

/// return evaluateOnce<double>("exp(c0)", a);
/// }
/// EXPECT_EQ(1, exp(0));
/// EXPECT_EQ(std::nullopt, exp(std::nullopt));
Copy link
Contributor

Choose a reason for hiding this comment

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

When testing default-null-behavior simple functions, it is redundant to test null inputs because these are handled by the framework, not by the function. It would be nice to clarify here that null tests are needed only when testing functions with non-default null behavior. It would also be nice to provide a version of evaluateOne that doesn't require std::optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess here the point is less to test that the default null behavior works (which must already be covered elsewhere), but that the function null behavior is correctly defined.

For example, if at some point someone changes a function definition and that changes (breaks) its semantic regarding nulls, you should have a test case to point that out. So IMHO, even if the function has default null behavior, you should still add a null in, null out check.

/// }
///
///
/// If not specified, input logical types are derived from the C++ type
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this also true for return type? Is std::string supported as return type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a sentence to clarify.

///
///
/// One can also manually specify additional template parameters, in case
/// there are problems with template type deduction:
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be an example of such a problem?

Copy link
Contributor Author

@pedroerp pedroerp May 6, 2024

Choose a reason for hiding this comment

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

for example, if the compiler cannot detect the full type, or if you want to a cast literal precision. Something like:

evaluateOnce<int64_t>("bla(c0, c1)", "my input char *", 1);

but this would:

evaluateOnce<int64_t, std::string, int64_t>("bla(c0, c1)", "my input char *", 1);

In most places I saw this being used, it wasn't really required, but this may come handy if you want to template test cases

std::optional<TReturn> evaluateOnce(
const std::string& expr,
const TypePtr& type,
std::optional<TArgs>... args) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we support more that one argument here? If so, does 'type' apply only to first argument? It would be nice to clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This overload is only here so you can do:

return evaluateOnce<int64_t>("hour(c0)", DATE(), date)

instead of:

return evaluateOnce<int64_t>("hour(c0)", {DATE()}, date)

I'll add a small comment to clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we support more that one argument here?

Yes, through the first overloaded version of this function (pass the types in the initializer_list)

const std::string& expr,
const RowVectorPtr rowVectorPtr,
const std::optional<SelectivityVector>& rows = std::nullopt,
const TypePtr& resultType = nullptr) {
auto result =
evaluate<SimpleVector<facebook::velox::test::EvalType<ReturnType>>>(
evaluate<SimpleVector<facebook::velox::test::EvalType<TReturn>>>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps, clarify somewhere that TReturn must be std::string for VARCHAR, VARBINARY and other typed based on StringView.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Added a sentence.

pedroerp added a commit to pedroerp/velox-1 that referenced this pull request May 6, 2024
Summary:

Improving the evaluateOnce() helper function to allow for more
flexibility when specifying input logical types. Also deprecating an old
overload of the function that only allowed multiple parameters with they had
the same type.
.
For a lot more details, check the header documentation added.

Differential Revision: D56962773
@pedroerp pedroerp force-pushed the export-D56962773 branch from e8aea05 to febdb71 Compare May 6, 2024 15:03
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56962773

pedroerp added a commit to pedroerp/velox-1 that referenced this pull request May 6, 2024
Summary:

Improving the evaluateOnce() helper function to allow for more
flexibility when specifying input logical types. Also deprecating an old
overload of the function that only allowed multiple parameters with they had
the same type.
.
For a lot more details, check the header documentation added.

Reviewed By: mbasmanova

Differential Revision: D56962773
@pedroerp pedroerp force-pushed the export-D56962773 branch from febdb71 to 6d2009c Compare May 6, 2024 21:06
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56962773

pedroerp added a commit to pedroerp/velox-1 that referenced this pull request May 6, 2024
Summary:

Improving the evaluateOnce() helper function to allow for more
flexibility when specifying input logical types. Also deprecating an old
overload of the function that only allowed multiple parameters with they had
the same type.
.
For a lot more details, check the header documentation added.

Reviewed By: mbasmanova

Differential Revision: D56962773
@pedroerp pedroerp force-pushed the export-D56962773 branch from 6d2009c to 29a0a9a Compare May 6, 2024 21:08
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56962773

Summary:

Improving the evaluateOnce() helper function to allow for more
flexibility when specifying input logical types. Also deprecating an old
overload of the function that only allowed multiple parameters with they had
the same type.
.
For a lot more details, check the header documentation added.

Reviewed By: mbasmanova

Differential Revision: D56962773
@pedroerp pedroerp force-pushed the export-D56962773 branch from 29a0a9a to 8f2a9f2 Compare May 7, 2024 02:36
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56962773

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in ec4d2ec.

Copy link

Conbench analyzed the 1 benchmark run on commit ec4d2ec1.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

Joe-Abraham pushed a commit to Joe-Abraham/velox that referenced this pull request May 8, 2024
Summary:
Pull Request resolved: facebookincubator#9708

Improving the evaluateOnce() helper function to allow for more
flexibility when specifying input logical types. Also deprecating an old
overload of the function that only allowed multiple parameters with they had
the same type.
.
For a lot more details, check the header documentation added.

Reviewed By: mbasmanova

Differential Revision: D56962773

fbshipit-source-id: 3b16756ff6443275f08c401ccccff81e3aa1c399
Joe-Abraham pushed a commit to Joe-Abraham/velox that referenced this pull request Jun 7, 2024
Summary:
Pull Request resolved: facebookincubator#9708

Improving the evaluateOnce() helper function to allow for more
flexibility when specifying input logical types. Also deprecating an old
overload of the function that only allowed multiple parameters with they had
the same type.
.
For a lot more details, check the header documentation added.

Reviewed By: mbasmanova

Differential Revision: D56962773

fbshipit-source-id: 3b16756ff6443275f08c401ccccff81e3aa1c399
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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants