http://git-wip-us.apache.org/repos/asf/calcite/blob/7bc9f140/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java
----------------------------------------------------------------------
diff --git 
a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java 
b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java
index c385c02..b6a7270 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java
@@ -595,13 +595,12 @@ public class DruidRules {
 
       // Erase references to filters
       for (AggregateCall aggCall : aggregate.getAggCallList()) {
-        int newFilterArg = aggCall.filterArg;
-        if (!aggCall.hasFilter()
-                || (uniqueFilterRefs.size() == 1 && allHaveFilters) // filters 
get extracted
-                || project.getProjects().get(newFilterArg).isAlwaysTrue()) {
-          newFilterArg = -1;
+        if ((uniqueFilterRefs.size() == 1
+                && allHaveFilters) // filters get extracted
+            || project.getProjects().get(aggCall.filterArg).isAlwaysTrue()) {
+          aggCall = aggCall.copy(aggCall.getArgList(), -1, aggCall.collation);
         }
-        newCalls.add(aggCall.copy(aggCall.getArgList(), newFilterArg));
+        newCalls.add(aggCall);
       }
       aggregate = aggregate.copy(aggregate.getTraitSet(), aggregate.getInput(),
               aggregate.indicator, aggregate.getGroupSet(), 
aggregate.getGroupSets(),

http://git-wip-us.apache.org/repos/asf/calcite/blob/7bc9f140/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 98fd037..4d238ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -134,7 +134,7 @@ limitations under the License.
     <slf4j.version>1.7.13</slf4j.version>
     <log4j2.version>2.11.0</log4j2.version>
     <spark.version>2.2.0</spark.version>
-    <sqlline.version>1.5.0</sqlline.version>
+    <sqlline.version>1.6.0-SNAPSHOT</sqlline.version>
     <tpcds.version>1.2</tpcds.version>
     <xalan.version>2.7.1</xalan.version>
     <xerces.version>2.9.1</xerces.version>

http://git-wip-us.apache.org/repos/asf/calcite/blob/7bc9f140/site/_docs/algebra.md
----------------------------------------------------------------------
diff --git a/site/_docs/algebra.md b/site/_docs/algebra.md
index e5b505b..8ff2339 100644
--- a/site/_docs/algebra.md
+++ b/site/_docs/algebra.md
@@ -216,7 +216,7 @@ If you have a particular `RelNode` instance, you can rely 
on the field names not
 changing. In fact, the whole relational expression is immutable.
 
 But if a relational expression has passed through several rewrite rules (see
-([RelOptRule]({{ site.apiRoot }}/org/apache/calcite/plan/RelOptRule.html)), 
the field
+[RelOptRule]({{ site.apiRoot }}/org/apache/calcite/plan/RelOptRule.html)), the 
field
 names of the resulting expression might not look much like the originals.
 At that point it is better to reference fields by ordinal.
 
@@ -315,7 +315,7 @@ expression on the stack:
 | `as(alias)`         | Assigns a table alias to the top relational expression 
on the stack
 | `variable(varHolder)` | Creates a correlation variable referencing the top 
relational expression
 
-### Stack methods
+#### Stack methods
 
 | Method              | Description
 |:------------------- |:-----------
@@ -372,7 +372,7 @@ The following methods return patterns for use in `match`.
 | `patternPermute(pattern...)` | Permutes a pattern
 | `patternExclude(pattern)` | Excludes a pattern
 
-### Group key methods
+#### Group key methods
 
 The following methods return a
 [RelBuilder.GroupKey]({{ site.apiRoot 
}}/org/apache/calcite/tools/RelBuilder.GroupKey.html).
@@ -383,28 +383,28 @@ The following methods return a
 | `groupKey(exprList, exprListList)` | Creates a group key of the given 
expressions with grouping sets
 | `groupKey(bitSet [, bitSets])` | Creates a group key of the given input 
columns, with multiple grouping sets if `bitSets` is specified
 
-### Aggregate call methods
+#### Aggregate call methods
 
 The following methods return an
 [RelBuilder.AggCall]({{ site.apiRoot 
}}/org/apache/calcite/tools/RelBuilder.AggCall.html).
 
 | Method              | Description
 |:------------------- |:-----------
-| `aggregateCall(op, distinct, approximate, filter, orderKeys, alias, 
expr...)`<br/>`aggregateCall(op, distinct, approximate, filter, orderKeys, 
alias, exprList)` | Creates a call to a given aggregate function, with an 
optional filter expression and a list of optional ordering keys (for sorting 
input values before aggregation)
-| `count( [ distinct, alias, ] expr...)` | Creates a call to the COUNT 
aggregate function
-| `countStar(alias)` | Creates a call to the COUNT(*) aggregate function
-| `sum( [ distinct, alias, ] expr)` | Creates a call to the SUM aggregate 
function
-| `min( [ alias, ] expr)` | Creates a call to the MIN aggregate function
-| `max( [ alias, ] expr)` | Creates a call to the MAX aggregate function
+| `aggregateCall(op, expr...)`<br/>`aggregateCall(op, exprList)` | Creates a 
call to a given aggregate function
+| `count([ distinct, alias, ] expr...)`<br/>`count([ distinct, alias, ] 
exprList)` | Creates a call to the `COUNT` aggregate function
+| `countStar(alias)` | Creates a call to the `COUNT(*)` aggregate function
+| `sum([ distinct, alias, ] expr)` | Creates a call to the `SUM` aggregate 
function
+| `min([ alias, ] expr)` | Creates a call to the `MIN` aggregate function
+| `max([ alias, ] expr)` | Creates a call to the `MAX` aggregate function
 
 To further modify the `AggCall`, call its methods:
 
 | Method               | Description
 |:-------------------- |:-----------
+| `approximate(approximate)` | Allows approximate value for the aggregate of 
`approximate`
+| `as(alias)`          | Assigns a column alias to this expression (see SQL 
`AS`)
 | `distinct()`         | Eliminates duplicate values before aggregating (see 
SQL `DISTINCT`)
 | `distinct(distinct)` | Eliminates duplicate values before aggregating if 
`distinct`
-| `as(alias)`          | Assigns a column alias to this expression (see SQL 
`AS`)
 | `filter(expr)`       | Filters rows before aggregating (see SQL `FILTER 
(WHERE ...)`)
-| `sort(expr, ...)`<br/>`sort(exprList)` | Sorts rows before aggregating (see 
SQL `WITHIN GROUP`)
-| `approximate(approximate)` | Allows approximate value for the aggregate of 
`approximate`
+| `sort(expr...)`<br/>`sort(exprList)` | Sorts rows before aggregating (see 
SQL `WITHIN GROUP`)
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/7bc9f140/site/_docs/reference.md
----------------------------------------------------------------------
diff --git a/site/_docs/reference.md b/site/_docs/reference.md
index 81d21c3..1e48292 100644
--- a/site/_docs/reference.md
+++ b/site/_docs/reference.md
@@ -1482,7 +1482,9 @@ Syntax:
 
 {% highlight sql %}
 aggregateCall:
-        agg( [ ALL | DISTINCT ] value [, value ]*) [ FILTER (WHERE condition) ]
+        agg( [ ALL | DISTINCT ] value [, value ]*)
+        [ WITHIN GROUP (ORDER BY orderItem [, orderItem ]*) ]
+        [ FILTER (WHERE condition) ]
     |   agg(*) [ FILTER (WHERE condition) ]
 {% endhighlight %}
 
@@ -1492,6 +1494,13 @@ If `FILTER` is present, the aggregate function only 
considers rows for which
 If `DISTINCT` is present, duplicate argument values are eliminated before being
 passed to the aggregate function.
 
+If `WITHIN GROUP` is present, the aggregate function sorts the input rows
+according to the `ORDER BY` clause inside `WITHIN GROUP` before aggregating
+values. `WITHIN GROUP` is only allowed for hypothetical set functions (`RANK`,
+`DENSE_RANK`, `PERCENT_RANK` and `CUME_DIST`), inverse distribution functions
+(`PERCENTILE_CONT` and `PERCENTILE_DISC`) and collection functions (`COLLECT`
+and `LISTAGG`).
+
 | Operator syntax                    | Description
 |:---------------------------------- |:-----------
 | COLLECT( [ ALL &#124; DISTINCT ] value)       | Returns a multiset of the 
values
@@ -1516,6 +1525,7 @@ passed to the aggregate function.
 
 Not implemented:
 
+* LISTAGG(string)
 * REGR_AVGX(numeric1, numeric2)
 * REGR_AVGY(numeric1, numeric2)
 * REGR_INTERCEPT(numeric1, numeric2)

Reply via email to