forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuzzer): Add input generator for json_parse in expression fuzzer (…
…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
- Loading branch information
1 parent
788555c
commit 9cf9fb0
Showing
18 changed files
with
396 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "velox/expression/fuzzer/ArgsOverrideFunctions.h" | ||
|
||
#include "velox/common/fuzzer/ConstrainedGenerators.h" | ||
#include "velox/common/fuzzer/Utils.h" | ||
#include "velox/core/Expressions.h" | ||
#include "velox/vector/fuzzer/VectorFuzzer.h" | ||
|
||
namespace facebook::velox::fuzzer { | ||
|
||
std::vector<core::TypedExprPtr> generateJsonParseArgs::generate( | ||
const CallableSignature& signature, | ||
const VectorFuzzer::Options& options, | ||
FuzzerGenerator& rng, | ||
ExpressionFuzzerState& 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; | ||
} | ||
|
||
/*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; | ||
}*/ | ||
|
||
} // namespace facebook::velox::fuzzer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include "velox/expression/fuzzer/FuzzerToolkit.h" | ||
|
||
namespace facebook::velox::fuzzer { | ||
|
||
class generateJsonParseArgs : public ArgValuesGenerator { | ||
public: | ||
~generateJsonParseArgs() override = default; | ||
|
||
std::vector<core::TypedExprPtr> generate( | ||
const CallableSignature& signature, | ||
const VectorFuzzer::Options& options, | ||
FuzzerGenerator& rng, | ||
ExpressionFuzzerState& state) override; | ||
}; | ||
|
||
} // namespace facebook::velox::fuzzer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.