Skip to content

Commit 5951ded

Browse files
GroupingSets Unary Logical Operator
1 parent 6171a5e commit 5951ded

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

docs/logical-operators/GroupingSets.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,50 @@ title: GroupingSets
44

55
# GroupingSets Unary Logical Operator
66

7+
`GroupingSets` is a `BaseGroupingSets` that represents the following high-level SQL-only operators (in a logical query plan):
8+
9+
* [GROUPING SETS](../sql/AstBuilder.md#visitGroupingAnalytics) SQL statement
10+
* [GROUP BY ... GROUPING SETS](../sql/AstBuilder.md#withAggregationClause) SQL statement
11+
12+
!!! note
13+
`grouping` and `grouping_id` standard functions can only be used with grouping analytics clauses (incl. `GroupingSets`).
14+
15+
??? note "Spark Structured Streaming Not Supported"
16+
Grouping Sets is not supported on streaming DataFrames (that is enforced by `UnsupportedOperationChecker`).
17+
18+
## Creating Instance
19+
20+
`GroupingSets` takes the following to be created:
21+
22+
* <span id="groupingSetIndexes"> GroupingSets Indicies
23+
* <span id="flatGroupingSets"> Flat GroupingSets [Expression](../expressions/Expression.md)s
24+
* <span id="userGivenGroupByExprs"> User-Specified GroupBy [Expression](../expressions/Expression.md)s
25+
26+
`GroupingSets` is created using [apply](#apply) utility only.
27+
28+
## Creating GroupingSets { #apply }
29+
30+
```scala
31+
apply(
32+
groupingSets: Seq[Seq[Expression]]): GroupingSets // (1)!
33+
apply(
34+
groupingSets: Seq[Seq[Expression]],
35+
userGivenGroupByExprs: Seq[Expression]): GroupingSets
36+
```
37+
38+
1. `userGivenGroupByExprs` is an empty collection (`Nil`)
39+
40+
`apply` computes the [GroupingSet indicies](#groupingSetIndexes) and creates a [GroupingSets](#creating-instance).
41+
42+
---
43+
44+
`apply` is used when:
45+
46+
* `AstBuilder` is requested to parse [GROUPING SETS](../sql/AstBuilder.md#visitGroupingAnalytics) or [GROUP BY ... GROUPING SETS](../sql/AstBuilder.md#withAggregationClause) SQL statements
47+
48+
<!---
49+
## Review Me
50+
751
`GroupingSets` is a spark-sql-LogicalPlan.md#UnaryNode[unary logical operator] that represents SQL's sql/AstBuilder.md#withAggregation[GROUPING SETS] variant of `GROUP BY` clause.
852
953
```text
@@ -66,12 +110,4 @@ scala> println(plan.numberedTreeString)
66110
67111
// FIXME Show the evaluation rules to get rid of the unresolvable parts
68112
----
69-
70-
=== [[creating-instance]] Creating GroupingSets Instance
71-
72-
`GroupingSets` takes the following when created:
73-
74-
* [[selectedGroupByExprs]] expressions/Expression.md[Expressions] from `GROUPING SETS` clause
75-
* [[groupByExprs]] Grouping expressions/Expression.md[expressions] from `GROUP BY` clause
76-
* [[child]] Child spark-sql-LogicalPlan.md[logical plan]
77-
* [[aggregations]] Aggregate expressions/NamedExpression.md[named expressions]
113+
-->

0 commit comments

Comments
 (0)