Skip to content

Commit

Permalink
[GLUTEN-7090][VL] fix: Number of sorting keys must be greater than ze…
Browse files Browse the repository at this point in the history
…ro (#7089)

Closes #7090
  • Loading branch information
dcoliversun authored Sep 3, 2024
1 parent 7ca509f commit 22bb0b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ class VeloxWindowExpressionSuite extends WholeStageTransformerSuite {
}
}

test("test overlapping partition and sorting keys") {
runAndCompare(
"""
|WITH t AS (
|SELECT
| l_linenumber,
| row_number() over (partition by l_linenumber order by l_linenumber) as rn
|FROM lineitem
|)
|SELECT * FROM t WHERE rn = 1
|""".stripMargin
) {}
}

test("collect_list / collect_set") {
withTable("t") {
val data = Seq(
Expand Down
8 changes: 8 additions & 0 deletions cpp/velox/substrait/SubstraitToVeloxPlan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,14 @@ core::PlanNodePtr SubstraitToVeloxPlanConverter::toVeloxPlan(
}
}
const std::optional<std::string> rowNumberColumnName = std::nullopt;

if (sortingKeys.empty()) {
// Handle if all sorting keys are also used as partition keys.

return std::make_shared<core::RowNumberNode>(
nextPlanNodeId(), partitionKeys, rowNumberColumnName, (int32_t)windowGroupLimitRel.limit(), childNode);
}

return std::make_shared<core::TopNRowNumberNode>(
nextPlanNodeId(),
partitionKeys,
Expand Down

0 comments on commit 22bb0b3

Please sign in to comment.