The key word is "sets". I think you will agree that

  ((5,3), (5), ())

is a rollup. Well, it is equivalent to

  ((3, 5), (5), ())

because each grouping set is a SET, and therefore the order of
elements does not matter: (3, 5) is the same as (5, 3).

Now, if you're using MySQL, for instance, I can see how you might be
confused. In MySQL, if you compute

 GROUP BY x, y, z WITH ROLLUP

then MySQL guarantee that the result will be ordered by x, y, z, and
therefore the result is different than

  GROUP BY z, y, x WITH ROLLUP

if you consider order. But Calcite's rollup operator (inside
Aggregate) does not guarantee any order.

On Tue, Aug 13, 2019 at 5:27 AM Muhammad Gelbana <m.gelb...@gmail.com> wrote:
>
> Based on those pages [1], [2], I understand that for group sets to be a
> rollup, all groups in the group set must be the same as the union set of
> groups but with gradually one less group removed from the end. For example,
> the following are valid rollup groups (The union set of groups is *(G1, G2,
> G3)*):
> ((G1, G2, G3), (G1, G2), (G1), () )
>
> While the following isn't
> ((G1, G2, G3), *(G1, G3)*, (G1), () )
> - because the second group skipped *G2* and took *G3* instead.
> or
> ((G1, G2, G3), *(G2, G3)*, (G1), () )
> - because the second group didn't start from *G1*, but started from *G2*.
>
> I'm saying this because I believe this method [3] isn't functioning
> correctly because it considers the group sets ({3, 5}, {5}, {}) to be a
> rollup although the second group started with "5" and not "3".
>
> Or am I missing something?
>
> [1]
> https://www.postgresql.org/docs/devel/queries-table-expressions.html#QUERIES-GROUPING-SETS
> [2] http://www.sqlservertutorial.net/sql-server-basics/sql-server-rollup/
> [3]
> https://github.com/apache/calcite/blob/5ec3a2a503dcf26fe1b3cad8a5a9467264213dcf/core/src/main/java/org/apache/calcite/rel/core/Aggregate.java#L496
>
> Thanks,
> Gelbana

Reply via email to