Skip to content

Commit 4787a99

Browse files
kagamiorifacebook-github-bot
authored andcommitted
feat(fuzzer): Allow functions to be tested only with sorted input in aggregation fuzzer (facebookincubator#12392)
Summary: Pull Request resolved: facebookincubator#12392 The tdigest_agg() function needs to be tested only with input of determined order so that Velox result is comparable with Presto's. This is because different ordering of input values affects the content in TDigest. Therefore, this diff makes it possible to specify a set of functions to be tested only with ordered inputs in aggregation fuzzer. Aggregation fuzzer will then use `order by arg0, arg1, ...` inside the aggregaiton function calls of this function. Reviewed By: natashasehgal Differential Revision: D69886108 fbshipit-source-id: 304d13ae41cbc14df330a02cc2a775c731929637
1 parent 71a1d78 commit 4787a99

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

velox/exec/fuzzer/AggregationFuzzer.cpp

+28-13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class AggregationFuzzer : public AggregationFuzzerBase {
4848
AggregationFuzzer(
4949
AggregateFunctionSignatureMap signatureMap,
5050
size_t seed,
51+
const std::unordered_set<std::string>& functionsRequireSortedInput,
5152
const std::unordered_map<std::string, std::shared_ptr<ResultVerifier>>&
5253
customVerificationFunctions,
5354
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&
@@ -183,14 +184,18 @@ class AggregationFuzzer : public AggregationFuzzerBase {
183184
}
184185
}
185186

187+
bool mustSortInput(const CallableSignature& signature) const;
188+
186189
Stats stats_;
187190
const std::unordered_map<std::string, DataSpec> functionDataSpec_;
191+
const std::unordered_set<std::string> functionsRequireSortedInput_;
188192
};
189193
} // namespace
190194

191195
void aggregateFuzzer(
192196
AggregateFunctionSignatureMap signatureMap,
193197
size_t seed,
198+
const std::unordered_set<std::string>& functionsRequireSortedInput,
194199
const std::unordered_map<std::string, std::shared_ptr<ResultVerifier>>&
195200
customVerificationFunctions,
196201
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&
@@ -205,6 +210,7 @@ void aggregateFuzzer(
205210
auto aggregationFuzzer = AggregationFuzzer(
206211
std::move(signatureMap),
207212
seed,
213+
functionsRequireSortedInput,
208214
customVerificationFunctions,
209215
customInputGenerators,
210216
functionDataSpec,
@@ -222,6 +228,7 @@ namespace {
222228
AggregationFuzzer::AggregationFuzzer(
223229
AggregateFunctionSignatureMap signatureMap,
224230
size_t seed,
231+
const std::unordered_set<std::string>& functionsRequireSortedInput,
225232
const std::unordered_map<std::string, std::shared_ptr<ResultVerifier>>&
226233
customVerificationFunctions,
227234
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&
@@ -233,7 +240,8 @@ AggregationFuzzer::AggregationFuzzer(
233240
bool orderableGroupKeys,
234241
std::unique_ptr<ReferenceQueryRunner> referenceQueryRunner)
235242
: AggregationFuzzerBase{seed, customVerificationFunctions, customInputGenerators, timestampPrecision, queryConfigs, hiveConfigs, orderableGroupKeys, std::move(referenceQueryRunner)},
236-
functionDataSpec_{functionDataSpec} {
243+
functionDataSpec_{functionDataSpec},
244+
functionsRequireSortedInput_{functionsRequireSortedInput} {
237245
VELOX_CHECK(!signatureMap.empty(), "No function signatures available.");
238246

239247
if (persistAndRunOnce_ && reproPersistPath_.empty()) {
@@ -309,6 +317,11 @@ bool supportsDistinctInputs(
309317
return arg->isComparable();
310318
}
311319

320+
bool AggregationFuzzer::mustSortInput(
321+
const CallableSignature& signature) const {
322+
return functionsRequireSortedInput_.count(signature.name) > 0;
323+
}
324+
312325
void AggregationFuzzer::go() {
313326
VELOX_CHECK(
314327
FLAGS_steps > 0 || FLAGS_duration_sec > 0,
@@ -338,6 +351,13 @@ void AggregationFuzzer::go() {
338351
} else {
339352
// Pick a random signature.
340353
auto signatureWithStats = pickSignature();
354+
auto signature = signatureWithStats.first;
355+
if (mustSortInput(signature) &&
356+
!(FLAGS_enable_sorted_aggregations && canSortInputs(signature))) {
357+
continue;
358+
}
359+
signatureWithStats.second.numRuns++;
360+
stats_.functionNames.insert(signature.name);
341361

342362
if (functionDataSpec_.count(signatureWithStats.first.name) > 0) {
343363
vectorOptions.dataSpec =
@@ -347,19 +367,10 @@ void AggregationFuzzer::go() {
347367
vectorOptions.dataSpec = {true, true};
348368
}
349369
vectorFuzzer_.setOptions(vectorOptions);
350-
signatureWithStats.second.numRuns++;
351370

352-
auto signature = signatureWithStats.first;
353-
stats_.functionNames.insert(signature.name);
354-
355-
const bool customVerification =
356-
customVerificationFunctions_.count(signature.name) != 0;
357-
358-
std::vector<TypePtr> argTypes = signature.args;
359-
std::vector<std::string> argNames = makeNames(argTypes.size());
360-
361-
const bool sortedInputs = FLAGS_enable_sorted_aggregations &&
362-
canSortInputs(signature) && vectorFuzzer_.coinToss(0.2);
371+
const bool sortedInputs = mustSortInput(signature) ||
372+
(FLAGS_enable_sorted_aggregations && canSortInputs(signature) &&
373+
vectorFuzzer_.coinToss(0.2));
363374

364375
// Exclude approx_xxx aggregations since their verifiers may not be able
365376
// to verify the results. The approx_percentile verifier would discard
@@ -372,6 +383,8 @@ void AggregationFuzzer::go() {
372383
supportsDistinctInputs(signature, orderableGroupKeys_) &&
373384
vectorFuzzer_.coinToss(0.2);
374385

386+
std::vector<TypePtr> argTypes = signature.args;
387+
std::vector<std::string> argNames = makeNames(argTypes.size());
375388
auto call = makeFunctionCall(
376389
signature.name, argNames, sortedInputs, distinctInputs);
377390

@@ -398,6 +411,8 @@ void AggregationFuzzer::go() {
398411

399412
logVectors(input);
400413

414+
const bool customVerification =
415+
customVerificationFunctions_.count(signature.name) != 0;
401416
std::shared_ptr<ResultVerifier> customVerifier;
402417
if (customVerification) {
403418
customVerifier = customVerificationFunctions_.at(signature.name);

velox/exec/fuzzer/AggregationFuzzer.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace facebook::velox::exec::test {
3737
void aggregateFuzzer(
3838
AggregateFunctionSignatureMap signatureMap,
3939
size_t seed,
40+
const std::unordered_set<std::string>& functionsRequireSortedInput,
4041
const std::unordered_map<std::string, std::shared_ptr<ResultVerifier>>&
4142
orderDependentFunctions,
4243
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&

velox/exec/fuzzer/AggregationFuzzerOptions.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ struct AggregationFuzzerOptions {
2929
/// Set of functions to not test.
3030
std::unordered_set<std::string> skipFunctions;
3131

32+
/// Set of functions that should only be tested with sorted input.
33+
std::unordered_set<std::string> functionsRequireSortedInput;
34+
3235
/// Set of functions whose results are non-deterministic. These can be
3336
/// order-dependent functions whose results depend on the order of input
3437
/// rows, or functions that return complex-typed results containing

velox/exec/fuzzer/AggregationFuzzerRunner.h

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class AggregationFuzzerRunner {
124124
facebook::velox::exec::test::aggregateFuzzer(
125125
filteredSignatures,
126126
seed,
127+
options.functionsRequireSortedInput,
127128
options.customVerificationFunctions,
128129
options.customInputGenerators,
129130
aggregationFunctionDataSpecs,

velox/functions/prestosql/fuzzer/AggregationFuzzerTest.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ int main(int argc, char** argv) {
133133
"any_value",
134134
};
135135

136+
static const std::unordered_set<std::string> functionsRequireSortedInput = {
137+
"tdigest_agg",
138+
};
139+
136140
using facebook::velox::exec::test::ApproxDistinctResultVerifier;
137141
using facebook::velox::exec::test::ApproxPercentileResultVerifier;
138142
using facebook::velox::exec::test::ArbitraryResultVerifier;
@@ -195,6 +199,7 @@ int main(int argc, char** argv) {
195199
Options options;
196200
options.onlyFunctions = FLAGS_only;
197201
options.skipFunctions = skipFunctions;
202+
options.functionsRequireSortedInput = functionsRequireSortedInput;
198203
options.customVerificationFunctions = customVerificationFunctions;
199204
options.customInputGenerators =
200205
facebook::velox::exec::test::getCustomInputGenerators();

0 commit comments

Comments
 (0)