Skip to content

Commit

Permalink
Deduplicate sorting keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses-you committed Jul 4, 2024
1 parent 2cd7491 commit cc47158
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1911,4 +1911,10 @@ class TestOperator extends VeloxWholeStageTransformerSuite with AdaptiveSparkPla
val resultLength = df.collect().length
assert(resultLength > 25000 && resultLength < 35000)
}

test("Deduplicate sorting keys") {
runQueryAndCompare("select * from lineitem order by l_orderkey, l_orderkey") {
checkGlutenOperatorMatch[SortExecTransformer]
}
}
}
16 changes: 7 additions & 9 deletions cpp/velox/substrait/SubstraitToVeloxPlan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1046,17 +1046,15 @@ SubstraitToVeloxPlanConverter::processSortField(
const RowTypePtr& inputType) {
std::vector<core::FieldAccessTypedExprPtr> sortingKeys;
std::vector<core::SortOrder> sortingOrders;
sortingKeys.reserve(sortFields.size());
sortingOrders.reserve(sortFields.size());

std::unordered_set<std::string> uniqueKeys;
for (const auto& sort : sortFields) {
sortingOrders.emplace_back(toSortOrder(sort));

if (sort.has_expr()) {
auto expression = exprConverter_->toVeloxExpr(sort.expr(), inputType);
auto fieldExpr = std::dynamic_pointer_cast<const core::FieldAccessTypedExpr>(expression);
VELOX_USER_CHECK_NOT_NULL(fieldExpr, "Sort Operator only supports field sorting key");
GLUTEN_CHECK(sort.has_expr(), "Sort field must have expr");
auto expression = exprConverter_->toVeloxExpr(sort.expr(), inputType);
auto fieldExpr = std::dynamic_pointer_cast<const core::FieldAccessTypedExpr>(expression);
VELOX_USER_CHECK_NOT_NULL(fieldExpr, "Sort Operator only supports field sorting key");
if (uniqueKeys.insert(fieldExpr->name()).second) {
sortingKeys.emplace_back(fieldExpr);
sortingOrders.emplace_back(toSortOrder(sort));
}
}
return {sortingKeys, sortingOrders};
Expand Down
1 change: 1 addition & 0 deletions cpp/velox/substrait/SubstraitToVeloxPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class SubstraitToVeloxPlanConverter {

/// Helper Function to convert Substrait sortField to Velox sortingKeys and
/// sortingOrders.
/// Note that, this method would deduplicate the sorting keys which have the same field name.
std::pair<std::vector<core::FieldAccessTypedExprPtr>, std::vector<core::SortOrder>> processSortField(
const ::google::protobuf::RepeatedPtrField<::substrait::SortField>& sortField,
const RowTypePtr& inputType);
Expand Down
2 changes: 1 addition & 1 deletion ep/build-velox/src/get_velox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
set -exu

VELOX_REPO=https://github.com/oap-project/velox.git
VELOX_BRANCH=2024_07_03
VELOX_BRANCH=2024_07_04
VELOX_HOME=""

#Set on run gluten on HDFS
Expand Down

0 comments on commit cc47158

Please sign in to comment.