Skip to content

Commit 340363b

Browse files
author
Marios Trivyzas
authored
SQL: Fix null handling for IN => painless script (#35124)
Include `null` literals when generating the painless script for `IN` expressions. Previously, they were skipped, because of an issue that had been fixed with #35108. Fixes: #35122
1 parent b432cbd commit 340363b

File tree

2 files changed

+5
-5
lines changed
  • x-pack/plugin/sql/src

2 files changed

+5
-5
lines changed

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/operator/comparison/In.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public Attribute toAttribute() {
107107
@Override
108108
public ScriptTemplate asScript() {
109109
ScriptTemplate leftScript = asScript(value);
110-
// remove duplicates
110+
111+
// fold & remove duplicates
111112
List<Object> values = new ArrayList<>(new LinkedHashSet<>(Foldables.valuesOf(list, value.dataType())));
112-
values.removeIf(Objects::isNull);
113113

114114
return new ScriptTemplate(
115115
formatTemplate(String.format(Locale.ROOT, "{sql}.in(%s, {})", leftScript.template())),
@@ -141,6 +141,6 @@ public boolean equals(Object obj) {
141141

142142
In other = (In) obj;
143143
return Objects.equals(value, other.value)
144-
&& Objects.equals(list, other.list);
144+
&& Objects.equals(list, other.list);
145145
}
146146
}

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/planner/QueryTranslatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void testTranslateInExpression_WhereClause_Painless() {
213213
assertEquals("InternalSqlScriptUtils.nullSafeFilter(InternalSqlScriptUtils.in(" +
214214
"InternalSqlScriptUtils.power(InternalSqlScriptUtils.docValue(doc,params.v0),params.v1), params.v2))",
215215
sc.script().toString());
216-
assertEquals("[{v=int}, {v=2}, {v=[10.0, 20.0]}]", sc.script().params().toString());
216+
assertEquals("[{v=int}, {v=2}, {v=[10.0, null, 20.0]}]", sc.script().params().toString());
217217
}
218218

219219
public void testTranslateInExpression_HavingClause_Painless() {
@@ -259,6 +259,6 @@ public void testTranslateInExpression_HavingClause_PainlessAndNullHandling() {
259259
assertEquals("InternalSqlScriptUtils.nullSafeFilter(InternalSqlScriptUtils.in(params.a0, params.v0))",
260260
aggFilter.scriptTemplate().toString());
261261
assertThat(aggFilter.scriptTemplate().params().toString(), startsWith("[{a=MAX(int){a->"));
262-
assertThat(aggFilter.scriptTemplate().params().toString(), endsWith(", {v=[10, 20, 30]}]"));
262+
assertThat(aggFilter.scriptTemplate().params().toString(), endsWith(", {v=[10, null, 20, 30]}]"));
263263
}
264264
}

0 commit comments

Comments
 (0)