Mavenomics / MavenWorks

Agile Dashboarding, anywhere
https://mavenworks.com
GNU General Public License v3.0
18 stars 2 forks source link

Root aggregate appears in flat GROUP BY queries #50

Closed quigleyj-mavenomics closed 4 years ago

quigleyj-mavenomics commented 5 years ago

A grouped query should be "flat" when the query omits WITH ROLLUP. This means that the root row should not be selected in this case.

The root row is a by-product of the row binning that occurs if a GROUP BY is present in the query. Internally, the engine builds out the full tree following the group selectors, and then at the end if WITH ROLLUP isn't present, the engine will strip all children below the first level.

Reproduction:

SELECT
  Avg(x),
  Sum(y)
FROM
  Lattice('x = 1 to 10 step 1, y = 1 to 10 step 1')
GROUP BY x % 3, y

The above query should result in a flat table (as it does on most SQL engines), but on MQL the table has a root row at the top:

Screenshot of current behavior

Historically, the C# engine also exhibited this issue. While we shouldn't use it as a gold standard, it's important for us to note that we would be intentionally breaking with the C# engine's behavior.

MavenScape behavior:

Screenshot of MavenScape's behavior