Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Support PERCENT_RANK aggregate function #288

Closed
jtaylor-sfdc opened this issue Jun 25, 2013 · 3 comments
Closed

Support PERCENT_RANK aggregate function #288

jtaylor-sfdc opened this issue Jun 25, 2013 · 3 comments

Comments

@jtaylor-sfdc
Copy link
Contributor

Support an aggregate function that calculates the percent rank of an expression like this:

SELECT PERCENT_RANK(<perc>) WITHIN GROUP (ORDER BY <expression> ASC)
FROM t

The PERCENT_RANK function would return a type of DECIMAL.

@ghost ghost assigned anoopsjohn Jun 25, 2013
@anoopsjohn
Copy link
Contributor

We need to support PERCENT_RANK() for every row as shown in here [See Analytic Example part] ?
Here the issue is, we don't support having a column in select which is not in the GROUP BY (ERROR 1018 (42Y27): Aggregate may not contain columns not in GROUP BY). Means we don't need support for PERCENT_RANK() to know the rank of every row column?

@jtaylor-sfdc
Copy link
Contributor Author

We'll need to treat the column reference in the WITHIN GROUP (ORDER BY salary DESC) as an aggregation even though it's not in the GROUP BY clause. To do this, you'll want to:

  • Define a new intermediate ParseNode, something like a PartitionedAggregateFunctionParseNode derived from AggregateFunctionParseNode and add an accept method implementation similar to the other ones.
  • In ParseNodeVisitor, add a visitEnter(PartitionedAggregateFunctionParseNode node) and a corresponding visitLeave. You'll need to fill in the implementation at various intermediate classes (just follow what's done for others), with the most important in ExpressionCompiler one being described below.
  • In ExpressionCompiler, for the implementation of visitEnter, you'd set the this.aggregateFunction to the PartitionedAggregateFunctionParseNode node and then clear it on the visitLeave (if it's set to the node). Then at compile time, Phoenix will treat that entire node as an aggregate expression.

anoopsjohn added a commit to anoopsjohn/phoenix that referenced this issue Jul 3, 2013
jtaylor-sfdc added a commit that referenced this issue Jul 4, 2013
@jtaylor-sfdc
Copy link
Contributor Author

Closing as fixed, as we now support PERCENTILE_RANK. Additional work is necessary to support the OLAP extensions, but this is covered by #23.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants