SQL: prevent duplicate generation for repeated aggs (#33252)

Prevent generation of duplicate aggs caused by repetitive functions,
leading to invalid query.

Fix #30287
This commit is contained in:
Costin Leau 2018-08-31 00:13:03 +03:00 committed by GitHub
parent 001b78f704
commit 83c3d7a6cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -112,6 +112,9 @@ public class Aggs {
}
public Aggs addAgg(LeafAgg agg) {
if (metricAggs.contains(agg)) {
return this;
}
return new Aggs(groups, combine(metricAggs, agg), pipelineAggs);
}

View File

@ -394,4 +394,12 @@ SELECT MIN(salary) min, MAX(salary) max, gender g, languages l, COUNT(*) c FROM
aggMultiWithHavingOnCount
SELECT MIN(salary) min, MAX(salary) max, gender g, COUNT(*) c FROM "test_emp" WHERE languages > 0 GROUP BY g HAVING c > 40 ORDER BY gender;
aggMultiGroupByMultiWithHavingOnCount
SELECT MIN(salary) min, MAX(salary) max, gender g, languages l, COUNT(*) c FROM "test_emp" WHERE languages > 0 GROUP BY g, languages HAVING c > 40 ORDER BY gender, languages;
SELECT MIN(salary) min, MAX(salary) max, gender g, languages l, COUNT(*) c FROM "test_emp" WHERE languages > 0 GROUP BY g, languages HAVING c > 40 ORDER BY gender, languages;
// repetion of same aggs to check whether the generated query contains duplicates or not
aggRepeatFunctionAcrossFields
SELECT MIN(emp_no) AS a, 1 + MIN(emp_no) AS b, ABS(MIN(emp_no)) AS c FROM test_emp;
aggRepeatFunctionBetweenSelectAndHaving
SELECT gender, COUNT(DISTINCT languages) AS c FROM test_emp GROUP BY gender HAVING count(DISTINCT languages) > 0 ORDER BY gender;