diff --git a/velox/exec/fuzzer/ResultVerifier.h b/velox/exec/fuzzer/ResultVerifier.h index bda5ccecc7f15..74611ce7cf75c 100644 --- a/velox/exec/fuzzer/ResultVerifier.h +++ b/velox/exec/fuzzer/ResultVerifier.h @@ -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. diff --git a/velox/exec/fuzzer/TransformResultVerifier.h b/velox/exec/fuzzer/TransformResultVerifier.h index 15776275103b1..e379d59dd4ec3 100644 --- a/velox/exec/fuzzer/TransformResultVerifier.h +++ b/velox/exec/fuzzer/TransformResultVerifier.h @@ -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 { @@ -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(); } diff --git a/velox/functions/prestosql/fuzzer/ApproxDistinctResultVerifier.h b/velox/functions/prestosql/fuzzer/ApproxDistinctResultVerifier.h index a3a98379776e5..ede1a228b5ada 100644 --- a/velox/functions/prestosql/fuzzer/ApproxDistinctResultVerifier.h +++ b/velox/functions/prestosql/fuzzer/ApproxDistinctResultVerifier.h @@ -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 { @@ -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 @@ -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 diff --git a/velox/functions/prestosql/fuzzer/ApproxPercentileResultVerifier.h b/velox/functions/prestosql/fuzzer/ApproxPercentileResultVerifier.h index 0ef745d8d50b0..76732d214127f 100644 --- a/velox/functions/prestosql/fuzzer/ApproxPercentileResultVerifier.h +++ b/velox/functions/prestosql/fuzzer/ApproxPercentileResultVerifier.h @@ -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 { @@ -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; @@ -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(); } diff --git a/velox/functions/prestosql/fuzzer/ArbitraryResultVerifier.h b/velox/functions/prestosql/fuzzer/ArbitraryResultVerifier.h index 3d92029eacded..50478dec3f6ce 100644 --- a/velox/functions/prestosql/fuzzer/ArbitraryResultVerifier.h +++ b/velox/functions/prestosql/fuzzer/ArbitraryResultVerifier.h @@ -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 @@ -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(); } diff --git a/velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.cpp b/velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.cpp index c8c41e6e2a445..1b847697e24a5 100644 --- a/velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.cpp +++ b/velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.cpp @@ -15,6 +15,7 @@ */ #include "velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.h" +#include "velox/vector/tests/utils/VectorMaker.h" namespace facebook::velox::exec::test { @@ -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 MinMaxByResultVerifier::combine( const std::vector& op1, const std::vector& op2) { diff --git a/velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.h b/velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.h index a43aa2da5128e..a2546c1078673 100644 --- a/velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.h +++ b/velox/functions/prestosql/fuzzer/MinMaxByResultVerifier.h @@ -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();