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

[GLUTEN-6377][CH] Support window function percent_rank #6386

Merged
merged 1 commit into from
Jul 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ object CHBackendSettings extends BackendSettingsApi with Logging {
}

wExpression.windowFunction match {
case _: RowNumber | _: AggregateExpression | _: Rank | _: DenseRank | _: NTile =>
case _: RowNumber | _: AggregateExpression | _: Rank | _: DenseRank | _: PercentRank |
_: NTile =>
allSupported = allSupported
case l: Lag =>
checkLagOrLead(l.third)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ class CHSparkPlanExecApi extends SparkPlanExecApi {
val columnName = s"${aliasExpr.name}_${aliasExpr.exprId.id}"
val wExpression = aliasExpr.child.asInstanceOf[WindowExpression]
wExpression.windowFunction match {
case wf @ (RowNumber() | Rank(_) | DenseRank(_)) =>
case wf @ (RowNumber() | Rank(_) | DenseRank(_) | PercentRank(_)) =>
val aggWindowFunc = wf.asInstanceOf[AggregateWindowFunction]
val frame = aggWindowFunc.frame.asInstanceOf[SpecifiedWindowFrame]
val windowFunctionNode = ExpressionBuilder.makeWindowFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,17 @@ class GlutenClickHouseTPCHSaltNullParquetSuite extends GlutenClickHouseTPCHAbstr
compareResultsAgainstVanillaSpark(sql, true, { _ => })
}

test("window percent_rank") {
val sql =
"""
|select n_regionkey, n_nationkey,
| percent_rank(n_nationkey) OVER (PARTITION BY n_regionkey ORDER BY n_nationkey) as n_rank
|from nation
|order by n_regionkey, n_nationkey
|""".stripMargin
compareResultsAgainstVanillaSpark(sql, true, { _ => })
}

test("window ntile") {
val sql =
"""
Expand Down
1 change: 1 addition & 0 deletions cpp-ch/local-engine/Parser/WindowRelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ WindowRelParser::parseWindowFrameType(const std::string & function_name, const s
static const std::unordered_map<std::string, substrait::WindowType> special_function_frame_type = {
{"rank", substrait::RANGE},
{"dense_rank", substrait::RANGE},
{"percent_rank", substrait::RANGE}
};

substrait::WindowType frame_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ REGISTER_COMMON_AGGREGATE_FUNCTION_PARSER(FirstIgnoreNull, first_ignore_null, fi
REGISTER_COMMON_AGGREGATE_FUNCTION_PARSER(Last, last, last_value_respect_nulls)
REGISTER_COMMON_AGGREGATE_FUNCTION_PARSER(LastIgnoreNull, last_ignore_null, last_value)
REGISTER_COMMON_AGGREGATE_FUNCTION_PARSER(DenseRank, dense_rank, dense_rank)
REGISTER_COMMON_AGGREGATE_FUNCTION_PARSER(PercentRank, percent_rank, percent_rank)
REGISTER_COMMON_AGGREGATE_FUNCTION_PARSER(Rank, rank, rank)
REGISTER_COMMON_AGGREGATE_FUNCTION_PARSER(RowNumber, row_number, row_number)
REGISTER_COMMON_AGGREGATE_FUNCTION_PARSER(CountDistinct, count_distinct, uniqExact)
Expand Down
Loading