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:
parent
001b78f704
commit
83c3d7a6cf
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue