-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(fuzzer): Add input generator for json_parse in expression fuzzer #12019
base: main
Are you sure you want to change the base?
Conversation
This pull request was exported from Phabricator. Differential Revision: D67820571 |
✅ Deploy Preview for meta-velox canceled.
|
This pull request was exported from Phabricator. Differential Revision: D67820571 |
3c0d260
to
d72e075
Compare
…facebookincubator#12019) Summary: Pull Request resolved: facebookincubator#12019 Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
This pull request was exported from Phabricator. Differential Revision: D67820571 |
…facebookincubator#12019) Summary: Pull Request resolved: facebookincubator#12019 Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
d72e075
to
6f75498
Compare
This pull request was exported from Phabricator. Differential Revision: D67820571 |
…facebookincubator#12019) Summary: Pull Request resolved: facebookincubator#12019 Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
6f75498
to
38a3cf0
Compare
I assume this is also based/waiting on #12080? |
38a3cf0
to
822f9c3
Compare
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
This pull request was exported from Phabricator. Differential Revision: D67820571 |
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
822f9c3
to
2f60556
Compare
This pull request was exported from Phabricator. Differential Revision: D67820571 |
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
2f60556
to
6ca61e0
Compare
This pull request was exported from Phabricator. Differential Revision: D67820571 |
6ca61e0
to
9fec9e9
Compare
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
This pull request was exported from Phabricator. Differential Revision: D67820571 |
funcArgOverrides_["switch"] = std::bind( | ||
&ExpressionFuzzer::generateSwitchArgs, this, std::placeholders::_1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to fit switch into the ArgsOverrideFunc interface? It'd be nice to get rid of this one off exceptional case (doesn't have to be done as part of this change).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I don't think so. Because the function signature of "switch" only contains (conditionType, thenType, elseType). It is the generateSwitchArgs() method that randomly generate 1--5 else and then branches by calling ExpressionFuzzer::generateArg(). So generateSwitchArgs() has to be a member method of ExpressionFuzzer to be able to call generateArg().
Since the additional then and else branches are not specified in the function signature, we also cannot let generateSwitchArgs() return nullptr for them and wait for the caller of generateSwitchArgs() call generateArg().
funcArgOverrides_[name] = std::bind( | ||
func, | ||
std::placeholders::_1, | ||
std::cref(this->vectorFuzzer_->getOptions()), | ||
std::ref(this->rng_), | ||
std::ref(this->state_)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using function pointers, could we make a virtual base class with a function that can be overridden?
With function pointers you just have to know the signature when you write a new one, and it will make evolving it in the future (if we need to) difficult. If we use an interface, the compiler can enforce that the signature is correct.
VELOX_CHECK_GT(callable.args.size(), i); | ||
args[i] = generateArg(callable.args[i], callable.constantArgs[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just use callable.args.at(i) and callable.constantArgs.at(i), no need to do the bounds check yourself
int32_t remainingLevelOfNesting_; | ||
}; | ||
|
||
State& stateMultable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stateMultable -> stateMutable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But also, why do we need to expose it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was for the last version of the code. I forgot to remove it. Will remove.
const std::unordered_map<std::string, std::shared_ptr<ArgGenerator>>& | ||
argGenerators) | ||
argGenerators, | ||
const std::unordered_map<std::string, ArgsOverrideFuncPtr>& | ||
argsOverrideFuncs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the names it's unclear what the difference is between ArgGenerator and ArgsOverrideFuncPtr, I thought ArgGenerator was doing the same thing until I read the code.
Could we rename these to something like ArgTypesGenerator and ArgValuesGenerator (or something better).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I'm renaming them in #12283.
9fec9e9
to
e0b4cd4
Compare
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
This pull request was exported from Phabricator. Differential Revision: D67820571 |
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
e0b4cd4
to
9cf9fb0
Compare
This pull request was exported from Phabricator. Differential Revision: D67820571 |
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Differential Revision: D67820571
9cf9fb0
to
c103528
Compare
This pull request was exported from Phabricator. Differential Revision: D67820571 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
|
||
namespace facebook::velox::fuzzer { | ||
|
||
class generateJsonParseArgs : public ArgValuesGenerator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class names should be upper case: GenerateJsonParseArgs
nit: JsonParseArgsGenerator?
/*std::vector<core::TypedExprPtr> generateJsonParseArg( | ||
const CallableSignature& signature, | ||
const VectorFuzzer::Options& options, | ||
FuzzerGenerator& rng, | ||
ExpressionFuzzer::State& state) { | ||
VELOX_CHECK_EQ(signature.args.size(), 1); | ||
std::vector<core::TypedExprPtr> inputExpressions; | ||
|
||
state.inputRowTypes_.emplace_back(signature.args[0]); | ||
state.inputRowNames_.emplace_back( | ||
fmt::format("c{}", state.inputRowTypes_.size() - 1)); | ||
|
||
const auto representedType = facebook::velox::randType(rng, 3); | ||
const auto seed = rand<uint32_t>(rng); | ||
const auto nullRatio = options.nullRatio; | ||
state.customInputGenerators_.emplace_back( | ||
std::make_shared<fuzzer::JsonInputGenerator>( | ||
seed, | ||
signature.args[0], | ||
nullRatio, | ||
fuzzer::getRandomInputGenerator(seed, representedType, nullRatio), | ||
true)); | ||
|
||
inputExpressions.push_back(std::make_shared<core::FieldAccessTypedExpr>( | ||
signature.args[0], state.inputRowNames_.back())); | ||
return inputExpressions; | ||
}*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot it. Thank you for catching this.
// Special case for switch because it has a variable number of arguments not | ||
// specified in the signature. Other functions' argument override should be | ||
// specified through funcArgOverrides_. | ||
if (callable.name == "switch") { | ||
return generateSwitchArgs(callable); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I like this better!
/// nullptr at the corresponding index. ExpressionFuzzer then generates random | ||
/// arguments for these unspecified ones with the types specified in the | ||
/// function signature. (Functions of variable arity must determine the number | ||
/// of arguments in the overridden method. Arguments at indices beyong the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: beyong -> beyond
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Reviewed By: kevinwilfong Differential Revision: D67820571
…facebookincubator#12019) Summary: Make expression fuzzer generate input vectors of valid JSON strings for the json_parse function. To test corner cases, the JSON strings may be randomly truncated or inserted with a space character. Reviewed By: kevinwilfong Differential Revision: D67820571
4bd683e
to
40f50b3
Compare
This pull request was exported from Phabricator. Differential Revision: D67820571 |
1 similar comment
This pull request was exported from Phabricator. Differential Revision: D67820571 |
Summary:
Make expression fuzzer generate input vectors of valid JSON strings for the
json_parse function. To test corner cases, the JSON strings may be
randomly truncated or inserted with a space character.
Differential Revision: D67820571