-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Support Grouping Sets, Rollup and Cube to extend group by statement #2039
Labels
area/sql/compatibility
Issues or PRs related to the SQL compatibililty
kind/feature
Categorizes issue or PR as related to a new feature.
need more test
Add more test
Milestone
Comments
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Oct 29, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Oct 29, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Oct 31, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Oct 31, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 7, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 7, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 7, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 7, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 7, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 11, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 11, 2019
…pache#2039) compatible with hive grouping clause (apache#2039) add unit test fix group by will throw null pointer exception Support Grouping Sets, Rollup and Cube to extend group by statement (apache#2039) add grouping function parser implements grouping function fix some code style add parameter check to grouping_id function (apache#2039) fix unit test failed (apache#2039) support grouping functions in expr like grouping(a) + grouping(b) (apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 11, 2019
…pache#2039) compatible with hive grouping clause (apache#2039) add unit test fix group by will throw null pointer exception Support Grouping Sets, Rollup and Cube to extend group by statement (apache#2039) add grouping function parser implements grouping function fix some code style add parameter check to grouping_id function (apache#2039) fix unit test failed (apache#2039) support grouping functions in expr like grouping(a) + grouping(b) (apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 11, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 12, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 12, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 13, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 13, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 13, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 14, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 14, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 14, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 15, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 15, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 15, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 15, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 15, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 18, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 19, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 25, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 25, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 25, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 25, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 25, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 26, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Nov 27, 2019
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Dec 9, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039)
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Dec 9, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039) clean some code style clean some code style [FIX] fix grouping functions not substitute in subquery(apache#2039) [ADD] add design docs [FIX] fix expr in groupby clause remove duplicate error[apache#2039] [FIX] fix code style problems add some comments [ADD] add fe unit test [FIX] fix according comments and add syntax check in where clause remve unused code fix by comments
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Dec 9, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039) clean some code style clean some code style [FIX] fix grouping functions not substitute in subquery(apache#2039) [ADD] add design docs [FIX] fix expr in groupby clause remove duplicate error[apache#2039] [FIX] fix code style problems add some comments [ADD] add fe unit test [FIX] fix according comments and add syntax check in where clause remve unused code fix by comments fix by comments fix by comments
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Dec 16, 2019
� This is the 1st commit message: Support Grouping Sets, Rollup and Cube to extend group by statement (apache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039) � This is the commit message apache#2: Support Grouping Sets, Rollup and Cube to extend group by statement (apache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039) clean some code style clean some code style [FIX] fix grouping functions not substitute in subquery(apache#2039) [ADD] add design docs [FIX] fix expr in groupby clause remove duplicate error[apache#2039] [FIX] fix code style problems add some comments [ADD] add fe unit test [FIX] fix according comments and add syntax check in where clause remve unused code fix by comments
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Dec 16, 2019
…pache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039) Support Grouping Sets, Rollup and Cube to extend group by statement (apache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039) clean some code style clean some code style [FIX] fix grouping functions not substitute in subquery(apache#2039) [ADD] add design docs [FIX] fix expr in groupby clause remove duplicate error[apache#2039] [FIX] fix code style problems add some comments [ADD] add fe unit test [FIX] fix according comments and add syntax check in where clause remve unused code fix by comments Support Grouping Sets, Rollup and Cube to extend group by statement (apache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039) clean some code style clean some code style [FIX] fix grouping functions not substitute in subquery(apache#2039) [ADD] add design docs [FIX] fix expr in groupby clause remove duplicate error[apache#2039] [FIX] fix code style problems add some comments [ADD] add fe unit test [FIX] fix according comments and add syntax check in where clause remve unused code fix by comments fix by comments fix by comments Support Grouping Sets, Rollup and Cube to extend group by statement (apache#2039) [ADD] compatible with hive grouping clause (apache#2039) [ADD] support grouping functions in expr like grouping(a) + grouping(b) (apache#2039) [FIX] fix analyzer error in window function(apache#2039) clean some code style clean some code style [FIX] fix grouping functions not substitute in subquery(apache#2039) [ADD] add design docs [FIX] fix expr in groupby clause remove duplicate error[apache#2039] [FIX] fix code style problems add some comments [ADD] add fe unit test [FIX] fix according comments and add syntax check in where clause remve unused code fix by comments fix by comments fix by comments move some code to repeatnode support subquery in grouping sets rewrite select when using grouping set fix some check condition
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 3, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 3, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 3, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 6, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 6, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 6, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 7, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 9, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 10, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 14, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 16, 2020
yangzhg
added a commit
to yangzhg/doris
that referenced
this issue
Jan 17, 2020
morningman
pushed a commit
that referenced
this issue
Jan 17, 2020
…ment Support Grouping Sets, Rollup and Cube to extend group by statement support GROUPING SETS syntax ``` SELECT a, b, SUM( c ) FROM tab1 GROUP BY GROUPING SETS ( (a, b), (a), (b), ( ) ); ``` cube or rollup like ``` SELECT a, b,c, SUM( d ) FROM tab1 GROUP BY ROLLUP|CUBE(a,b,c) ``` [ADD] support grouping functions in expr like grouping(a) + grouping(b) (#2039) [FIX] fix analyzer error in window function(#2039)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area/sql/compatibility
Issues or PRs related to the SQL compatibililty
kind/feature
Categorizes issue or PR as related to a new feature.
need more test
Add more test
1. GROUPING SETS Background
The
CUBE
,ROLLUP
, andGROUPING
SETS
extensions to SQL make querying and reporting easier and faster.CUBE
,ROLLUP
, and grouping sets produce a single result set that is equivalent to aUNION
ALL
of differently grouped rows.ROLLUP
calculates aggregations such asSUM
,COUNT
,MAX
,MIN
, andAVG
at increasing levels of aggregation, from the most detailed up to a grand total.CUBE
is an extension similar toROLLUP
, enabling a single statement to calculate all possible combinations of aggregations. TheCUBE
,ROLLUP
, and theGROUPING
SETS
extension lets you specify just the groupings needed in theGROUP
BY
clause. This allows efficient analysis across multiple dimensions without performing aCUBE
operation. Computing aCUBE
creates a heavy processing load, so replacing cubes with grouping sets can significantly increase performance.To enhance performance,
CUBE
,ROLLUP
, andGROUPING SETS
can be parallelized: multiple processes can simultaneously execute all of these statements. These capabilities make aggregate calculations more efficient, thereby enhancing database performance, and scalability.The three
GROUPING
functions help you identify the group each row belongs to and enable sorting subtotal rows and filtering results.1.1 GROUPING SETS Syntax
GROUPING SETS
syntax lets you define multiple groupings in the same query.GROUP BY
computes all the groupings specified and combines them withUNION ALL
. For example, consider the following statement:This statement is equivalent to:
This is an example of real query:
1.2 ROLLUP Syntax
ROLLUP
enables aSELECT
statement to calculate multiple levels of subtotals across a specified group of dimensions. It also calculates a grand total.ROLLUP
is a simple extension to theGROUP
BY
clause, so its syntax is extremely easy to use. TheROLLUP
extension is highly efficient, adding minimal overhead to a query.ROLLUP
appears in theGROUP
BY
clause in aSELECT
statement. Its form is:This statement is equivalent to GROUPING SETS as followed:
1.3 CUBE Syntax
Like
ROLLUP
CUBE
generates all the subtotals that could be calculated for a data cube with the specified dimensions.e.g. CUBE ( a, b, c ) is equivalent to GROUPING SETS as followed:
1.4 GROUPING_ID() Function
GROUPING_ID
describes which of a list of expressions are grouped in a row produced by aGROUP BY
query. TheGROUPING_ID
function simply returns the decimal equivalent of the binary value formed as a result of the concatenation of the values returned by theGROUPING
functions.Each
GROUPING_ID
argument must be an element of theGROUP BY
list.GROUPING_ID ()
returns an integer bitmap whose lowest N bits may be lit. A lit bit indicates the corresponding argument is not a grouping column for the given output row. The lowest-order bit corresponds to argument N, and the N-1th lowest-order bit corresponds to argument 1. If the column is a grouping column the bit is 0 else is 1.For example:
grouping sets result:
1.5 GROUPING Function
Indicates whether a specified column expression in a
GROUP BY
list is aggregated or not.GROUPING
returns 1 for aggregated or 0 for not aggregated in the result set.GROUPING
can be used only in theSELECT
list,HAVING
, andORDER BY
clauses whenGROUP BY
is specified.2. Object
Support
GROUPING SETS
,ROLLUP
andCUBE
syntax,impliments 1.1, 1.2, 1.3 1.4, 1.52.1 GROUPING SETS Syntax
2.2 ROLLUP Syntax
2.3 CUBE Syntax
3. Implementation
3.1 Overall Design Approaches
For
GROUPING SET
is equivalent to theUNION
ofGROUP BY
. So we can expand input rows, and run an GROUP BY on these rows。For example:
Data in table src :
Base on GROUPING SETS , we can expend the input to:
And then use those row as input, then GROUP BY a, b, GROUPING_ID
3.2 Example
Table t:
for the query:
First,expand the input,every row expand into 4 rows ( the size of GROUPING SETS), and insert GROUPING_ID column
e.g. a, A, 1 expanded to:
Finally, all rows expended as follows (32 rows):
now GROUP BY k1, k2, GROUPING_ID(k1,k2):
The result is equivalent to the UNION ALL
3.3 FE
3.3.1 Tasks
3.3.2 Tuple
In order to add GROUPING_ID to groupingExprs in GroupByClause, need to create virtual SlotRef, also, need tot create a tuple for this slot, named GROUPING__ID Tuple.
For the plannode RepeatNode, it's input is all the tuple of it's children, It's output tuple is the repeat data and GROUPING_ID.
3.3.3 Expression and Function Substitution
expr -> if(bitand(pos, grouping_id)=0, expr, null) for expr in extension grouping clause
grouping_id() -> grouping_id(grouping_id) for grouping_id function
3.4 BE
3.4.1 Tasks
The text was updated successfully, but these errors were encountered: