Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VL] [Test] Test rebasing upstream velox 11_8 #3642

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cpp/velox/substrait/SubstraitToVeloxPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ class SubstraitToVeloxPlanConverter {
/// Get aggregation step from AggregateRel.
core::AggregationNode::Step toAggregationStep(const ::substrait::AggregateRel& sAgg);

/// Helper Function to convert Substrait sortField to Velox sortingKeys and
/// sortingOrders.
std::pair<std::vector<core::FieldAccessTypedExprPtr>, std::vector<core::SortOrder>> processSortField(
const ::google::protobuf::RepeatedPtrField<::substrait::SortField>& sortField,
const RowTypePtr& inputType);

private:
/// Integrate Substrait emit feature. Here a given 'substrait::RelCommon'
/// is passed and check if emit is defined for this relation. Basically a
Expand Down Expand Up @@ -328,12 +334,6 @@ class SubstraitToVeloxPlanConverter {
std::vector<variant> values_;
};

/// Helper Function to convert Substrait sortField to Velox sortingKeys and
/// sortingOrders.
std::pair<std::vector<core::FieldAccessTypedExprPtr>, std::vector<core::SortOrder>> processSortField(
const ::google::protobuf::RepeatedPtrField<::substrait::SortField>& sortField,
const RowTypePtr& inputType);

/// Returns unique ID to use for plan node. Produces sequential numbers
/// starting from zero.
std::string nextPlanNodeId();
Expand Down
28 changes: 28 additions & 0 deletions cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,34 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::FetchRel& fetchR
logValidateMsg("native validation failed due to: Offset and count should be valid in FetchRel.");
return false;
}

core::PlanNodePtr childNode;
// Check the input of fetchRel, if it's sortRel, we need to check whether the sorting key is duplicated.
::substrait::SortRel sortRel;
bool topNFlag = false;
if (fetchRel.has_input()) {
topNFlag = fetchRel.input().has_sort();
if (topNFlag) {
sortRel = fetchRel.input().sort();
childNode = planConverter_.toVeloxPlan(sortRel.input());
} else {
childNode = planConverter_.toVeloxPlan(fetchRel.input());
}
}

if (topNFlag) {
auto [sortingKeys, sortingOrders] = planConverter_.processSortField(sortRel.sorts(), childNode->outputType());

folly::F14FastSet<std::string> sortingKeyNames;
for (const auto& sortingKey : sortingKeys) {
auto result = sortingKeyNames.insert(sortingKey->name());
if (!result.second) {
logValidateMsg(
"native validation failed due to: if the input of fetchRel is a SortRel, we will convert it to a TopNNode. In Velox, it is important to ensure unique sorting keys. However, duplicate keys were found in this case.");
return false;
}
}
}
return true;
}

Expand Down