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

Add custom argument generators for Presto decimal functions #9715

Closed
wants to merge 1 commit into from

Conversation

rui-mo
Copy link
Collaborator

@rui-mo rui-mo commented May 6, 2024

To generate argument types in the decimal fuzzer test correctly, customized
argument type generators are required. This PR adds arg generators for the
Presto functions plus/minus, multiply, divide, and floor/round.
Inspired by #9358.

@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 6, 2024
Copy link

netlify bot commented May 6, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit cbdaa94
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/663ad1c60d33f70008277e56

@rui-mo rui-mo force-pushed the presto_arg branch 3 times, most recently from bcae811 to 8249229 Compare May 6, 2024 08: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.

@rui-mo Looks great % small comments.

class ArgGeneratorTest : public testing::Test {};

TEST_F(ArgGeneratorTest, plusMinus) {
auto signature =
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of hard-coding function signature here, can we fetch it from the registry?

Copy link
Collaborator Author

@rui-mo rui-mo May 7, 2024

Choose a reason for hiding this comment

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

Added this function to fetch signature from the registry.

std::vector<const exec::FunctionSignature*> getSignatures(
const FunctionSignatureMap& map,
const std::string& functionName,
const std::string& returnType);

#include "velox/expression/fuzzer/ArgGenerator.h"

namespace facebook::velox::exec::test {
namespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

no anonymous namespaces in header files, please

use 'detail' namespace or make this a private static method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for pointing out this. Made it a private static method.

DECIMAL(38, 20),
DECIMAL(38, 38),
DECIMAL(38, 0)}) {
fuzzer::test::assertReturnType(generator, *signature, returnType);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it might be easier to read if this is written without a loop

fuzzer::test::assertReturnType(generator, *signature, DECIMAL(10, 2));
fuzzer::test::assertReturnType(generator, *signature, DECIMAL(18, 18));
...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated. Thanks.

if (binder.tryBind()) {
actualType = binder.tryResolveReturnType();
} else {
VELOX_FAIL(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

VELOX_CHECK(binder.tryBind(), ...)
auto actualType = binder.tryResolveReturnType();

@rui-mo rui-mo force-pushed the presto_arg branch 4 times, most recently from b73776a to 6eb2e13 Compare May 7, 2024 05:27
EXPECT_TRUE(argTypes.empty());
}

std::vector<const exec::FunctionSignature*> getSignatures(
Copy link
Contributor

Choose a reason for hiding this comment

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

There is FunctionBaseTest::getSignatureStrings method. Maybe add another one that returns signatures as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for your suggestion. Added getSignatures in FunctionBaseTest.

static std::unordered_set<const exec::FunctionSignature*> getSignatures(
const std::string& functionName,
const std::string& returnType);

Comment on lines 33 to 35
const auto signatures = getSignatures(allSignatures_, "plus", "decimal");
VELOX_CHECK_EQ(signatures.size(), 1);
const auto& signature = *signatures[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

This code repeats multiple time. Consider adding helper method:

const auto& signature = getOnlySignature("plus");

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated. Thanks.

@mbasmanova mbasmanova changed the title Add Presto arg generators Add custom argument generators for Presto decimal functions May 7, 2024
@rui-mo rui-mo force-pushed the presto_arg branch 2 times, most recently from 4863a71 to 2edc272 Compare May 7, 2024 14:47
@@ -318,6 +318,11 @@ class FunctionBaseTest : public testing::Test,
return result[0];
}

// Returns a set of signatures for the given function name and return type.
static std::unordered_set<const exec::FunctionSignature*> getSignatures(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we return a set? An std::vector should work just fine, no?

Let's document 'returnType' parameter. It may not be obvious what the value is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was using set to keep similar style with FunctionBaseTest::getSignatureStrings method. Changed to use vector.

Document 'returnType' parameter as below.

The name of expected return type defined in function signature.

Thanks.

@rui-mo rui-mo force-pushed the presto_arg branch 3 times, most recently from aba3f02 to 2de6929 Compare May 8, 2024 01:10
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.

Thanks.

@mbasmanova mbasmanova added the ready-to-merge PR that have been reviewed and are ready for merging. PRs with this tag notify the Velox Meta oncall label May 8, 2024
@rui-mo
Copy link
Collaborator Author

rui-mo commented May 9, 2024

@mbasmanova Could we merge this PR? Thanks!

@mbasmanova
Copy link
Contributor

@rui-mo Yes, we'll merge this soon.

CC: @kgpai

@facebook-github-bot
Copy link
Contributor

@kgpai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@rui-mo
Copy link
Collaborator Author

rui-mo commented May 15, 2024

Hi @kgpai, I notice there are some internal failures. If there is anything needs to be fixed, please kindly let me know. Thanks.

@facebook-github-bot
Copy link
Contributor

@kgpai merged this pull request in 08ffe22.

Copy link

Conbench analyzed the 1 benchmark run on commit 08ffe220.

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 Jun 7, 2024
…incubator#9715)

Summary:
To generate argument types in the decimal fuzzer test correctly, customized
argument type generators are required. This PR adds arg generators for the
Presto functions plus/minus, multiply, divide, and floor/round.
Inspired by facebookincubator#9358.

Pull Request resolved: facebookincubator#9715

Reviewed By: Yuhta

Differential Revision: D57173196

Pulled By: kgpai

fbshipit-source-id: 0bb23aaa55be046b27e4edef2aef9ed4cdf0545e
Joe-Abraham pushed a commit to Joe-Abraham/velox that referenced this pull request Jun 7, 2024
…incubator#9715)

Summary:
To generate argument types in the decimal fuzzer test correctly, customized
argument type generators are required. This PR adds arg generators for the
Presto functions plus/minus, multiply, divide, and floor/round.
Inspired by facebookincubator#9358.

Pull Request resolved: facebookincubator#9715

Reviewed By: Yuhta

Differential Revision: D57173196

Pulled By: kgpai

fbshipit-source-id: 0bb23aaa55be046b27e4edef2aef9ed4cdf0545e
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. Merged ready-to-merge PR that have been reviewed and are ready for merging. PRs with this tag notify the Velox Meta oncall
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants