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 17, 2024
1 parent 59087d2 commit 0d8f514
Show file tree
Hide file tree
Showing 7 changed files with 66 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
13 changes: 13 additions & 0 deletions velox/exec/fuzzer/TransformResultVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "velox/exec/tests/utils/AssertQueryBuilder.h"
#include "velox/exec/tests/utils/PlanBuilder.h"
#include "velox/vector/ComplexVector.h"
#include "velox/vector/tests/utils/VectorMaker.h"

namespace facebook::velox::exec::test {

Expand Down Expand Up @@ -65,10 +66,22 @@ class TransformResultVerifier : public ResultVerifier {
return assertEqualResults({transform(result)}, {transform(altResult)});
}

bool compare(const VectorPtr& result, const VectorPtr& altResult) override {
velox::test::VectorMaker resultVectorMaker(result->pool());
velox::test::VectorMaker altResultVectorMaker(altResult->pool());
return assertEqualResults(
{transform(resultVectorMaker.rowVector({result}))},
{transform(altResultVectorMaker.rowVector({altResult}))});
}

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

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

void reset() override {
projections_.clear();
}
Expand Down
11 changes: 11 additions & 0 deletions velox/functions/prestosql/fuzzer/ApproxDistinctResultVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "velox/exec/tests/utils/AssertQueryBuilder.h"
#include "velox/exec/tests/utils/PlanBuilder.h"
#include "velox/vector/ComplexVector.h"
#include "velox/vector/tests/utils/VectorMaker.h"

namespace facebook::velox::exec::test {

Expand Down Expand Up @@ -86,6 +87,11 @@ class ApproxDistinctResultVerifier : public ResultVerifier {
VELOX_UNSUPPORTED();
}

bool compare(const VectorPtr& /*result*/, const VectorPtr& /*altResult*/)
override {
VELOX_UNSUPPORTED();
}

bool verify(const RowVectorPtr& result) override {
// Union 'result' with 'expected_', group by on 'groupingKeys_' and produce
// pairs of actual and expected values per group. We cannot use join because
Expand Down Expand Up @@ -161,6 +167,11 @@ class ApproxDistinctResultVerifier : public ResultVerifier {
return largeGaps.empty();
}

bool verify(const VectorPtr& result) override {
velox::test::VectorMaker resultVectorMaker(result->pool());
return verify(resultVectorMaker.rowVector({result}));
}

// For approx_distinct in window operations, input sets for rows in the same
// partition are correlated. Since the error bound of approx_distinct only
// applies to independent input sets, we only take one max gap in each
Expand Down
11 changes: 11 additions & 0 deletions velox/functions/prestosql/fuzzer/ApproxPercentileResultVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "velox/exec/tests/utils/AssertQueryBuilder.h"
#include "velox/exec/tests/utils/PlanBuilder.h"
#include "velox/vector/ComplexVector.h"
#include "velox/vector/tests/utils/VectorMaker.h"

namespace facebook::velox::exec::test {

Expand Down Expand Up @@ -99,6 +100,11 @@ class ApproxPercentileResultVerifier : public ResultVerifier {
VELOX_UNSUPPORTED();
}

bool compare(const VectorPtr& /*result*/, const VectorPtr& /*altResult*/)
override {
VELOX_UNSUPPORTED();
}

bool verify(const RowVectorPtr& result) override {
// Compute acceptable ranges of percentiles for each value in 'result'.
RowVectorPtr ranges;
Expand Down Expand Up @@ -144,6 +150,11 @@ class ApproxPercentileResultVerifier : public ResultVerifier {
return true;
}

bool verify(const VectorPtr& result) override {
velox::test::VectorMaker resultVectorMaker(result->pool());
return verify(resultVectorMaker.rowVector({result}));
}

void reset() override {
allRanges_.reset();
}
Expand Down
10 changes: 10 additions & 0 deletions velox/functions/prestosql/fuzzer/ArbitraryResultVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class ArbitraryResultVerifier : public ResultVerifier {
VELOX_UNSUPPORTED();
}

bool compare(const VectorPtr& /*result*/, const VectorPtr& /*altResult*/)
override {
VELOX_UNSUPPORTED();
}

bool verify(const RowVectorPtr& result) override {
// Union 'result' with 'expected_', group by on 'groupingKeys_' and produce
// pairs of actual and expected values per group. We cannot use join because
Expand Down Expand Up @@ -125,6 +130,11 @@ class ArbitraryResultVerifier : public ResultVerifier {
return assertEqualResults({expectedRow}, {contains});
}

bool verify(const VectorPtr& result) override {
velox::test::VectorMaker resultVectorMaker(result->pool());
return verify(resultVectorMaker.rowVector({result}));
}

void reset() override {
expected_.reset();
}
Expand Down
6 changes: 6 additions & 0 deletions velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.h"
#include "velox/vector/tests/utils/VectorMaker.h"

namespace facebook::velox::exec::test {

Expand Down Expand Up @@ -323,6 +324,11 @@ bool MinMaxByResultVerifier::verify(const RowVectorPtr& result) {
return true;
}

bool MinMaxByResultVerifier::verify(const VectorPtr& result) {
velox::test::VectorMaker resultVectorMaker(result->pool());
return MinMaxByResultVerifier::verify(resultVectorMaker.rowVector({result}));
}

std::vector<std::string> MinMaxByResultVerifier::combine(
const std::vector<std::string>& op1,
const std::vector<std::string>& op2) {
Expand Down
7 changes: 7 additions & 0 deletions velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ class MinMaxByResultVerifier : public ResultVerifier {
VELOX_UNSUPPORTED();
}

bool compare(const VectorPtr& /*result*/, const VectorPtr& /*altResult*/)
override {
VELOX_UNSUPPORTED();
}

bool verify(const RowVectorPtr& result) override;

bool verify(const VectorPtr& result) override;

void reset() override {
expected_.reset();
groupingKeys_.clear();
Expand Down

0 comments on commit 0d8f514

Please sign in to comment.