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

refactor(fuzzer): Abstract common logVectors method for reuse in fuzzers #12300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions velox/exec/fuzzer/AggregationFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
#include "velox/exec/tests/utils/TempDirectoryPath.h"

#include "velox/exec/PartitionFunction.h"
#include "velox/exec/fuzzer/AggregationFuzzerBase.h"
#include "velox/exec/fuzzer/FuzzerUtil.h"
#include "velox/expression/fuzzer/FuzzerToolkit.h"
#include "velox/vector/VectorSaver.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"

DEFINE_bool(
enable_sorted_aggregations,
Expand Down
13 changes: 0 additions & 13 deletions velox/exec/fuzzer/AggregationFuzzerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,19 +486,6 @@ void AggregationFuzzerBase::printSignatureStats() {
}
}

void AggregationFuzzerBase::logVectors(
const std::vector<RowVectorPtr>& vectors) {
if (!VLOG_IS_ON(1)) {
return;
}
for (auto i = 0; i < vectors.size(); ++i) {
VLOG(1) << "Input batch " << i << ":";
for (auto j = 0; j < vectors[i]->size(); ++j) {
VLOG(1) << "\tRow " << j << ": " << vectors[i]->toString(j);
}
}
}

velox::fuzzer::ResultOrError AggregationFuzzerBase::execute(
const core::PlanNodePtr& plan,
const std::vector<exec::Split>& splits,
Expand Down
2 changes: 0 additions & 2 deletions velox/exec/fuzzer/AggregationFuzzerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ class AggregationFuzzerBase {

void printSignatureStats();

void logVectors(const std::vector<RowVectorPtr>& vectors);

const std::unordered_map<std::string, std::shared_ptr<ResultVerifier>>
customVerificationFunctions_;
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>
Expand Down
12 changes: 12 additions & 0 deletions velox/exec/fuzzer/FuzzerUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,18 @@ std::unique_ptr<ReferenceQueryRunner> setupReferenceQueryRunner(
}
}

void logVectors(const std::vector<RowVectorPtr>& vectors) {
if (!VLOG_IS_ON(1)) {
return;
}
for (auto i = 0; i < vectors.size(); ++i) {
VLOG(1) << "Input batch " << i << ":";
for (auto j = 0; j < vectors[i]->size(); ++j) {
VLOG(1) << "\tRow " << j << ": " << vectors[i]->toString(j);
}
}
}

std::pair<std::optional<MaterializedRowMultiset>, ReferenceQueryErrorCode>
computeReferenceResults(
const core::PlanNodePtr& plan,
Expand Down
3 changes: 3 additions & 0 deletions velox/exec/fuzzer/FuzzerUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ std::unique_ptr<ReferenceQueryRunner> setupReferenceQueryRunner(
const std::string& runnerName,
const uint32_t& reqTimeoutMs);

// Logs the input vectors if verbose logging is turned on.
void logVectors(const std::vector<RowVectorPtr>& vectors);

// Converts 'plan' into an SQL query and runs in the reference DB.
// Result is returned as a MaterializedRowMultiset with the
// ReferenceQueryErrorCode::kSuccess if successful, or an std::nullopt with a
Expand Down
22 changes: 1 addition & 21 deletions velox/exec/fuzzer/RowNumberFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,6 @@ bool isDone(size_t i, T startTime) {
return i >= FLAGS_steps;
}

std::vector<RowVectorPtr> flatten(const std::vector<RowVectorPtr>& vectors) {
std::vector<RowVectorPtr> flatVectors;
for (const auto& vector : vectors) {
auto flat = BaseVector::create<RowVector>(
vector->type(), vector->size(), vector->pool());
flat->copy(vector.get(), 0, 0, vector->size());
flatVectors.push_back(flat);
}

return flatVectors;
}

std::pair<std::vector<std::string>, std::vector<TypePtr>>
RowNumberFuzzer::generatePartitionKeys() {
const auto numKeys = randInt(1, 3);
Expand Down Expand Up @@ -404,15 +392,7 @@ void RowNumberFuzzer::addPlansWithTableScan(
void RowNumberFuzzer::verify() {
const auto [keyNames, keyTypes] = generatePartitionKeys();
const auto input = generateInput(keyNames, keyTypes);

if (VLOG_IS_ON(1)) {
// Flatten inputs.
const auto flatInput = flatten(input);
VLOG(1) << "Input: " << input[0]->toString();
for (const auto& v : flatInput) {
VLOG(1) << std::endl << v->toString(0, v->size());
}
}
test::logVectors(input);

auto defaultPlan = makeDefaultPlan(keyNames, input);
const auto expected = execute(defaultPlan, /*injectSpill=*/false);
Expand Down
Loading