Skip to content

Commit

Permalink
Extend ApproxPercentileResultVerifier for window fuzzer (facebookincu…
Browse files Browse the repository at this point in the history
…bator#10367)

Summary: Pull Request resolved: facebookincubator#10367

Differential Revision: D59257657
  • Loading branch information
kagamiori authored and facebook-github-bot committed Jul 2, 2024
1 parent f6b6087 commit 48450bc
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 33 deletions.
10 changes: 10 additions & 0 deletions velox/exec/fuzzer/FuzzerUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include "velox/core/PlanNode.h"
#include "velox/exec/Split.h"

namespace facebook::velox::exec::test {
const std::string kHiveConnectorId = "test-hive";

struct SortingKeyAndOrder {
const std::string key_;
const core::SortOrder sortOrder_;

SortingKeyAndOrder(std::string key, core::SortOrder sortOrder)
: key_(std::move(key)), sortOrder_(std::move(sortOrder)) {}
};

/// Write the vector to the path.
void writeToFile(
const std::string& path,
Expand Down
2 changes: 2 additions & 0 deletions velox/exec/fuzzer/ResultVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string>

#include "velox/core/PlanNode.h"
#include "velox/exec/fuzzer/FuzzerUtil.h"
#include "velox/vector/ComplexVector.h"

namespace facebook::velox::exec::test {
Expand Down Expand Up @@ -61,6 +62,7 @@ class ResultVerifier {
virtual void initializeWindow(
const std::vector<RowVectorPtr>& /*input*/,
const std::vector<std::string>& /*partitionByKeys*/,
const std::vector<SortingKeyAndOrder>& /*sortingKeysAndOrders*/,
const core::WindowNode::Function& /*function*/,
const std::string& /*frame*/,
const std::string& /*windowName*/) {
Expand Down
19 changes: 15 additions & 4 deletions velox/exec/fuzzer/WindowFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ std::string WindowFuzzer::getFrame(
return frame.str();
}

std::vector<WindowFuzzer::SortingKeyAndOrder>
WindowFuzzer::generateSortingKeysAndOrders(
std::vector<SortingKeyAndOrder> WindowFuzzer::generateSortingKeysAndOrders(
const std::string& prefix,
std::vector<std::string>& names,
std::vector<TypePtr>& types) {
Expand Down Expand Up @@ -359,11 +358,17 @@ void initializeVerifier(
const std::shared_ptr<ResultVerifier>& customVerifier,
const std::vector<RowVectorPtr>& input,
const std::vector<std::string>& partitionKeys,
const std::vector<SortingKeyAndOrder>& sortingKeysAndOrders,
const std::string& frame) {
const auto& windowNode =
std::dynamic_pointer_cast<const core::WindowNode>(plan);
customVerifier->initializeWindow(
input, partitionKeys, windowNode->windowFunctions()[0], frame, "w0");
input,
partitionKeys,
sortingKeysAndOrders,
windowNode->windowFunctions()[0],
frame,
"w0");
}
} // namespace

Expand Down Expand Up @@ -424,7 +429,13 @@ bool WindowFuzzer::verifyWindow(
VELOX_CHECK(
customVerifier->supportsVerify(),
"Window fuzzer only uses custom verify() methods.");
initializeVerifier(plan, customVerifier, input, partitionKeys, frame);
initializeVerifier(
plan,
customVerifier,
input,
partitionKeys,
sortingKeysAndOrders,
frame);
customVerifier->verify(resultOrError.result);
}
}
Expand Down
9 changes: 1 addition & 8 deletions velox/exec/fuzzer/WindowFuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "velox/exec/Aggregate.h"
#include "velox/exec/WindowFunction.h"
#include "velox/exec/fuzzer/AggregationFuzzerBase.h"
#include "velox/exec/fuzzer/FuzzerUtil.h"
#include "velox/exec/fuzzer/PrestoQueryRunner.h"
#include "velox/exec/fuzzer/ReferenceQueryRunner.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"
Expand Down Expand Up @@ -76,14 +77,6 @@ class WindowFuzzer : public AggregationFuzzerBase {
void go(const std::string& planPath);

private:
struct SortingKeyAndOrder {
const std::string key_;
const core::SortOrder sortOrder_;

SortingKeyAndOrder(std::string key, core::SortOrder sortOrder)
: key_(std::move(key)), sortOrder_(std::move(sortOrder)) {}
};

void addWindowFunctionSignatures(const WindowFunctionMap& signatureMap);

// Return a randomly generated frame clause string together with a boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ApproxDistinctResultVerifier : public ResultVerifier {
void initializeWindow(
const std::vector<RowVectorPtr>& input,
const std::vector<std::string>& partitionByKeys,
const std::vector<SortingKeyAndOrder>& sortingKeysAndOrders,
const core::WindowNode::Function& function,
const std::string& frame,
const std::string& windowName) override {
Expand Down
Loading

0 comments on commit 48450bc

Please sign in to comment.