Skip to content

Commit 1a1a56c

Browse files
tteofiliMax Hniebergall
authored andcommitted
_score should not be a reserved attribute in ES|QL (#118435) (#118568)
(cherry picked from commit 7573312)
1 parent 998e0e0 commit 1a1a56c

File tree

5 files changed

+42
-37
lines changed

5 files changed

+42
-37
lines changed

docs/changelog/118435.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 118435
2+
summary: '`_score` should not be a reserved attribute in ES|QL'
3+
area: ES|QL
4+
type: enhancement
5+
issues:
6+
- 118460

muted-tests.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,11 @@ tests:
382382
- class: "org.elasticsearch.xpack.esql.qa.mixed.MixedClusterEsqlSpecIT"
383383
method: "test {scoring.*}"
384384
issue: https://github.com/elastic/elasticsearch/issues/117641
385-
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
386-
method: test {scoring.QstrWithFieldAndScoringSortedEval}
385+
- class: "org.elasticsearch.xpack.esql.qa.mixed.MultilusterEsqlSpecIT"
386+
method: "test {scoring.*}"
387+
issue: https://github.com/elastic/elasticsearch/issues/118460
388+
- class: "org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT"
389+
method: "test {scoring.*}"
387390
issue: https://github.com/elastic/elasticsearch/issues/117751
388391
- class: org.elasticsearch.search.ccs.CrossClusterIT
389392
method: testCancel
@@ -463,4 +466,4 @@ tests:
463466
issue: https://github.com/elastic/elasticsearch/issues/118514
464467
- class: org.elasticsearch.xpack.esql.qa.mixed.MixedClusterEsqlSpecIT
465468
method: test {grok.OverwriteNameWhere SYNC}
466-
issue: https://github.com/elastic/elasticsearch/issues/118638
469+
issue: https://github.com/elastic/elasticsearch/issues/118638

x-pack/plugin/esql/qa/testFixtures/src/main/resources/scoring.csv-spec

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,33 @@ book_no:keyword | c_score:double
283283
7350 | 2.0
284284
7140 | 3.0
285285
;
286+
287+
QstrScoreManipulation
288+
required_capability: metadata_score
289+
required_capability: qstr_function
290+
291+
from books metadata _score
292+
| where qstr("title:rings")
293+
| eval _score = _score + 1
294+
| keep book_no, title, _score
295+
| limit 2;
296+
297+
book_no:keyword | title:text | _score:double
298+
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings | 2.6404519081115723
299+
2714 | Return of the King Being the Third Part of The Lord of the Rings | 2.9239964485168457
300+
;
301+
302+
QstrScoreOverride
303+
required_capability: metadata_score
304+
required_capability: qstr_function
305+
306+
from books metadata _score
307+
| where qstr("title:rings")
308+
| eval _score = "foobar"
309+
| keep book_no, title, _score
310+
| limit 2;
311+
312+
book_no:keyword | title:text | _score:keyword
313+
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings | foobar
314+
2714 | Return of the King Being the Third Part of The Lord of the Rings | foobar
315+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Verifier.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.xpack.esql.core.expression.Expression;
1919
import org.elasticsearch.xpack.esql.core.expression.Expressions;
2020
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
21-
import org.elasticsearch.xpack.esql.core.expression.MetadataAttribute;
2221
import org.elasticsearch.xpack.esql.core.expression.NamedExpression;
2322
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
2423
import org.elasticsearch.xpack.esql.core.expression.function.Function;
@@ -208,7 +207,6 @@ else if (p instanceof Lookup lookup) {
208207
checkJoin(p, failures);
209208
});
210209
checkRemoteEnrich(plan, failures);
211-
checkMetadataScoreNameReserved(plan, failures);
212210

213211
if (failures.isEmpty()) {
214212
checkLicense(plan, licenseState, failures);
@@ -222,13 +220,6 @@ else if (p instanceof Lookup lookup) {
222220
return failures;
223221
}
224222

225-
private static void checkMetadataScoreNameReserved(LogicalPlan p, Set<Failure> failures) {
226-
// _score can only be set as metadata attribute
227-
if (p.inputSet().stream().anyMatch(a -> MetadataAttribute.SCORE.equals(a.name()) && (a instanceof MetadataAttribute) == false)) {
228-
failures.add(fail(p, "`" + MetadataAttribute.SCORE + "` is a reserved METADATA attribute"));
229-
}
230-
}
231-
232223
private void checkSort(LogicalPlan p, Set<Failure> failures) {
233224
if (p instanceof OrderBy ob) {
234225
ob.order().forEach(o -> {

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.test.ESTestCase;
1313
import org.elasticsearch.xpack.esql.VerificationException;
1414
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
15-
import org.elasticsearch.xpack.esql.core.expression.Attribute;
1615
import org.elasticsearch.xpack.esql.core.type.DataType;
1716
import org.elasticsearch.xpack.esql.core.type.EsField;
1817
import org.elasticsearch.xpack.esql.core.type.InvalidMappedField;
@@ -22,7 +21,6 @@
2221
import org.elasticsearch.xpack.esql.parser.EsqlParser;
2322
import org.elasticsearch.xpack.esql.parser.QueryParam;
2423
import org.elasticsearch.xpack.esql.parser.QueryParams;
25-
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
2624

2725
import java.util.ArrayList;
2826
import java.util.LinkedHashMap;
@@ -1805,29 +1803,6 @@ public void testToDatePeriodToTimeDurationWithInvalidType() {
18051803
);
18061804
}
18071805

1808-
public void testNonMetadataScore() {
1809-
assumeTrue("'METADATA _score' is disabled", EsqlCapabilities.Cap.METADATA_SCORE.isEnabled());
1810-
assertEquals("1:12: `_score` is a reserved METADATA attribute", error("from foo | eval _score = 10"));
1811-
1812-
assertEquals(
1813-
"1:48: `_score` is a reserved METADATA attribute",
1814-
error("from foo metadata _score | where qstr(\"bar\") | eval _score = _score + 1")
1815-
);
1816-
}
1817-
1818-
public void testScoreRenaming() {
1819-
assumeTrue("'METADATA _score' is disabled", EsqlCapabilities.Cap.METADATA_SCORE.isEnabled());
1820-
assertEquals("1:33: `_score` is a reserved METADATA attribute", error("from foo METADATA _id, _score | rename _id as _score"));
1821-
1822-
assertTrue(passes("from foo metadata _score | rename _score as foo").stream().anyMatch(a -> a.name().equals("foo")));
1823-
}
1824-
1825-
private List<Attribute> passes(String query) {
1826-
LogicalPlan logicalPlan = defaultAnalyzer.analyze(parser.createStatement(query));
1827-
assertTrue(logicalPlan.resolved());
1828-
return logicalPlan.output();
1829-
}
1830-
18311806
public void testIntervalAsString() {
18321807
// DateTrunc
18331808
for (String interval : List.of("1 minu", "1 dy", "1.5 minutes", "0.5 days", "minutes 1", "day 5")) {

0 commit comments

Comments
 (0)