SQL: Fix incorrect HAVING equality (#31820)
Fix bug that causes `HAVING a = b` to be translated ad-litteram in Painless which uses `==` for equality checks not `=`. Close #31796
This commit is contained in:
parent
cce7dc20ad
commit
89cb0872cf
|
@ -27,6 +27,7 @@ public class Equals extends BinaryComparison {
|
|||
return new Equals(location(), newLeft, newRight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fold() {
|
||||
return Objects.equals(left().fold(), right().fold());
|
||||
}
|
||||
|
@ -38,6 +39,6 @@ public class Equals extends BinaryComparison {
|
|||
|
||||
@Override
|
||||
public String symbol() {
|
||||
return "=";
|
||||
return "==";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class CliExplainIT extends CliIntegrationTestCase {
|
|||
assertThat(readLine(), startsWith("----------"));
|
||||
assertThat(readLine(), startsWith("With[{}]"));
|
||||
assertThat(readLine(), startsWith("\\_Project[[?*]]"));
|
||||
assertThat(readLine(), startsWith(" \\_Filter[?i = 2]"));
|
||||
assertThat(readLine(), startsWith(" \\_Filter[?i == 2]"));
|
||||
assertThat(readLine(), startsWith(" \\_UnresolvedRelation[[][index=test],null,Unknown index [test]]"));
|
||||
assertEquals("", readLine());
|
||||
|
||||
|
|
|
@ -80,6 +80,8 @@ SELECT COUNT(DISTINCT hire_date) AS count FROM test_emp;
|
|||
// Conditional COUNT
|
||||
aggCountAndHaving
|
||||
SELECT gender g, COUNT(*) c FROM "test_emp" GROUP BY g HAVING COUNT(*) > 10 ORDER BY gender;
|
||||
aggCountAndHavingEquality
|
||||
SELECT gender g, COUNT(*) c FROM "test_emp" GROUP BY g HAVING COUNT(*) = 10 ORDER BY gender;
|
||||
aggCountOnColumnAndHaving
|
||||
SELECT gender g, COUNT(gender) c FROM "test_emp" GROUP BY g HAVING COUNT(gender) > 10 ORDER BY gender;
|
||||
// NOT supported yet since Having introduces a new agg
|
||||
|
@ -91,6 +93,8 @@ aggCountOnColumnAndHavingOnAlias
|
|||
SELECT gender g, COUNT(gender) c FROM "test_emp" GROUP BY g HAVING c > 10 ORDER BY gender;
|
||||
aggCountOnColumnAndMultipleHaving
|
||||
SELECT gender g, COUNT(gender) c FROM "test_emp" GROUP BY g HAVING c > 10 AND c < 70 ORDER BY gender ;
|
||||
aggCountOnColumnAndMultipleHavingEquals
|
||||
SELECT gender g, COUNT(gender) c FROM "test_emp" GROUP BY g HAVING c > 10 AND c = 63 ORDER BY gender ;
|
||||
aggCountOnColumnAndMultipleHavingWithLimit
|
||||
SELECT gender g, COUNT(gender) c FROM "test_emp" GROUP BY g HAVING c > 10 AND c < 70 ORDER BY gender LIMIT 1;
|
||||
aggCountOnColumnAndHavingBetween
|
||||
|
@ -145,6 +149,7 @@ SELECT gender g, MIN(emp_no) m FROM "test_emp" GROUP BY g HAVING m BETWEEN 10 AN
|
|||
aggMinWithMultipleHavingOnAliasAndFunction
|
||||
SELECT gender g, MIN(emp_no) m FROM "test_emp" GROUP BY g HAVING m > 10 AND MIN(emp_no) < 99999 ORDER BY gender;
|
||||
|
||||
|
||||
// MAX
|
||||
aggMaxImplicit
|
||||
// tag::max
|
||||
|
|
Loading…
Reference in New Issue