Skip to content

Commit

Permalink
Generate random sort/null ordering in WindowFuzzer (facebookincubator…
Browse files Browse the repository at this point in the history
…#9258)

Summary: Pull Request resolved: facebookincubator#9258

Reviewed By: mbasmanova

Differential Revision: D56662277

Pulled By: kagamiori

fbshipit-source-id: d08990ca82a39e6ed4cadd939de003a627336e03
  • Loading branch information
pramodsatya authored and facebook-github-bot committed May 1, 2024
1 parent 8567d4d commit 714b747
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
23 changes: 8 additions & 15 deletions velox/exec/fuzzer/WindowFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ std::string WindowFuzzer::generateOrderByClause(
frame << ", ";
}
frame << sortingKeysAndOrders[i].key_ << " "
<< sortingKeysAndOrders[i].order_ << " "
<< sortingKeysAndOrders[i].nullsOrder_;
<< sortingKeysAndOrders[i].sortOrder_.toString();
}
return frame.str();
}
Expand All @@ -193,11 +192,10 @@ WindowFuzzer::generateSortingKeysAndOrders(
std::vector<TypePtr>& types) {
auto keys = generateSortingKeys(prefix, names, types);
std::vector<SortingKeyAndOrder> results;
// TODO: allow randomly generating orders.
for (auto i = 0; i < keys.size(); ++i) {
std::string order = "asc";
std::string nullsOrder = "nulls last";
results.push_back(SortingKeyAndOrder(keys[i], order, nullsOrder));
auto asc = vectorFuzzer_.coinToss(0.5);
auto nullsFirst = vectorFuzzer_.coinToss(0.5);
results.emplace_back(keys[i], core::SortOrder(asc, nullsFirst));
}
return results;
}
Expand Down Expand Up @@ -250,8 +248,7 @@ void WindowFuzzer::go() {
// If the function is order-dependent or uses "rows" frame, sort all input
// rows by row_number additionally.
if (requireSortedInput || isRowsFrame) {
sortingKeysAndOrders.push_back(
SortingKeyAndOrder("row_number", "asc", "nulls last"));
sortingKeysAndOrders.emplace_back("row_number", core::kAscNullsLast);
++stats_.numSortedInputs;
}

Expand Down Expand Up @@ -306,15 +303,11 @@ void WindowFuzzer::testAlternativePlans(

std::vector<std::string> allKeys;
for (const auto& key : partitionKeys) {
allKeys.push_back(key + " NULLS FIRST");
allKeys.emplace_back(key + " NULLS FIRST");
}
for (const auto& keyAndOrder : sortingKeysAndOrders) {
allKeys.push_back(folly::to<std::string>(
keyAndOrder.key_,
" ",
keyAndOrder.order_,
" ",
keyAndOrder.nullsOrder_));
allKeys.emplace_back(fmt::format(
"{} {}", keyAndOrder.key_, keyAndOrder.sortOrder_.toString()));
}

// Streaming window from values.
Expand Down
19 changes: 5 additions & 14 deletions velox/exec/fuzzer/WindowFuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,11 @@ class WindowFuzzer : public AggregationFuzzerBase {

private:
struct SortingKeyAndOrder {
std::string key_;
std::string order_;
std::string nullsOrder_;

SortingKeyAndOrder() = delete;

SortingKeyAndOrder(
const std::string& key,
const std::string& order,
const std::string& nullsOrder) {
key_ = key;
order_ = order;
nullsOrder_ = nullsOrder;
}
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);
Expand Down

0 comments on commit 714b747

Please sign in to comment.