Skip to content

Commit

Permalink
Overload compare and verify methods in ResultVerifier (facebookincuba…
Browse files Browse the repository at this point in the history
…tor#10481)

Summary:
Pull Request resolved: facebookincubator#10481

This will enable comparisons between individial Vectors to help the aggregation fuzzer perform verifications for custom verifiers, specfic to the result of certain aggregates.

Differential Revision: D59829965
  • Loading branch information
Daniel Hunte authored and facebook-github-bot committed Jul 16, 2024
1 parent 3598307 commit 6aaf9a4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions velox/exec/fuzzer/ResultVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ class ResultVerifier {
const RowVectorPtr& result,
const RowVectorPtr& otherResult) = 0;

/// Same as above but takes a VectorPtr and converts it to a RowVectorPtr in
/// implementation.
virtual bool compare(const VectorPtr& result, const VectorPtr& altResult) = 0;

/// Verifies results of a Velox plan or reference DB query.
///
/// 'initialize' must be called first. 'verify' may be called multiple times
/// after single 'initialize' call.
virtual bool verify(const RowVectorPtr& result) = 0;

/// Same as above but takes a VectorPtr and converts it to a RowVectorPtr in
/// implementation.
virtual bool verify(const VectorPtr& result) = 0;

/// Clears internal state after possibly multiple calls to 'compare' and
/// 'verify'. 'initialize' must be called again after 'reset' to allow calling
/// 'compare' or 'verify' again.
Expand Down
20 changes: 20 additions & 0 deletions velox/exec/fuzzer/TransformResultVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ class TransformResultVerifier : public ResultVerifier {
return assertEqualResults({transform(result)}, {transform(altResult)});
}

bool compare(const VectorPtr& result, const VectorPtr& altResult) override {
return assertEqualResults(
{transform(castToRowVector(result))},
{transform(castToRowVector(altResult))});
}

bool verify(const RowVectorPtr& /*result*/) override {
VELOX_UNSUPPORTED();
}

bool verify(const VectorPtr& /*result*/) override {
VELOX_UNSUPPORTED();
}

void reset() override {
projections_.clear();
}
Expand All @@ -80,6 +90,16 @@ class TransformResultVerifier : public ResultVerifier {
return AssertQueryBuilder(plan).copyResults(data->pool());
}

RowVectorPtr castToRowVector(const VectorPtr& input) {
auto rowVector = std::make_shared<RowVector>(
input->pool(),
ROW({input->type()}),
nullptr,
1,
std::vector<VectorPtr>{input});
return rowVector;
}

const std::string transform_;

std::vector<std::string> projections_;
Expand Down

0 comments on commit 6aaf9a4

Please sign in to comment.