Skip to content

Commit 0de1df5

Browse files
committed
Added missing tests
1 parent 9f39ad3 commit 0de1df5

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ _id:keyword
361361
scoresNonPushableFunctions
362362

363363
required_capability: metadata_score
364-
required_capability: full_text_functions_disjunctions_score
365364

366365
from books metadata _score
367366
| where length(title) > 100
@@ -370,8 +369,8 @@ from books metadata _score
370369
;
371370

372371
book_no:keyword | _score:double
373-
2924 | 0.0
374-
8678 | 0.0
372+
2924 | 1.0
373+
8678 | 1.0
375374
;
376375

377376
scoresPushableFunctions
@@ -423,6 +422,7 @@ book_no:keyword | _score:double
423422

424423
disjunctionScoresPushableNonPushableFunctions
425424

425+
required_capability: metadata_score
426426
required_capability: full_text_functions_disjunctions_score
427427

428428
from books metadata _score
@@ -443,6 +443,7 @@ book_no:keyword | _score:double
443443

444444
disjunctionScoresMultipleClauses
445445

446+
required_capability: metadata_score
446447
required_capability: full_text_functions_disjunctions_score
447448

448449
from books metadata _score

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/ScoringIT.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,48 @@ public void testDisjunctionScoring() {
9898
}
9999
}
100100

101+
public void testConjunctionPushableScoring() {
102+
var query = """
103+
FROM test METADATA _score
104+
| WHERE match(content, "fox") AND id > 4
105+
| KEEP id, _score
106+
| SORT _score DESC, id ASC
107+
""";
108+
109+
try (var resp = run(query)) {
110+
assertColumnNames(resp.columns(), List.of("id", "_score"));
111+
assertColumnTypes(resp.columns(), List.of("integer", "double"));
112+
List<List<Object>> values = getValuesList(resp);
113+
assertThat(values.size(), equalTo(1));
114+
115+
assertThat(values.get(0).get(0), equalTo(6));
116+
117+
// Matches full text query and pushable query
118+
assertThat((Double) values.get(0).get(1), greaterThan(1.0));
119+
}
120+
}
121+
122+
public void testConjunctionNonPushableScoring() {
123+
var query = """
124+
FROM test METADATA _score
125+
| WHERE match(content, "fox") AND length(content) < 20
126+
| KEEP id, _score
127+
| SORT _score DESC, id ASC
128+
""";
129+
130+
try (var resp = run(query)) {
131+
assertColumnNames(resp.columns(), List.of("id", "_score"));
132+
assertColumnTypes(resp.columns(), List.of("integer", "double"));
133+
List<List<Object>> values = getValuesList(resp);
134+
assertThat(values.size(), equalTo(1));
135+
136+
assertThat(values.get(0).get(0), equalTo(1));
137+
138+
// Matches full text query and pushable query
139+
assertThat((Double) values.get(0).get(1), greaterThan(1.0));
140+
}
141+
}
142+
101143
public void testDisjunctionScoringPushableFunctions() {
102144
var query = """
103145
FROM test METADATA _score

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ public final void test() throws Throwable {
284284
"CSV tests cannot currently handle the _source field mapping directives",
285285
testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.SOURCE_FIELD_MAPPING.capabilityName())
286286
);
287+
assumeFalse(
288+
"CSV tests cannot currently handle scoring that depends on Lucene",
289+
testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.METADATA_SCORE.capabilityName())
290+
);
291+
287292
if (Build.current().isSnapshot()) {
288293
assertThat(
289294
"Capability is not included in the enabled list capabilities on a snapshot build. Spelling mistake?",

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LocalPhysicalPlanOptimizerTests.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ public void testMatchWithFieldCasting() {
16661666
assertThat(queryBuilder.value(), is(123456));
16671667
}
16681668

1669-
public void testMatchFunctionWithPushableConjunction() {
1669+
public void testMatchFunctionWithNonPushableConjunction() {
16701670
String query = """
16711671
from test
16721672
| where match(last_name, "Smith") and length(first_name) > 10
@@ -1685,6 +1685,24 @@ public void testMatchFunctionWithPushableConjunction() {
16851685
assertThat(esQuery.query(), instanceOf(MatchQueryBuilder.class));
16861686
}
16871687

1688+
public void testMatchFunctionWithPushableConjunction() {
1689+
String query = """
1690+
from test metadata _score
1691+
| where match(last_name, "Smith") and salary > 10000
1692+
""";
1693+
var plan = plannerOptimizer.plan(query);
1694+
1695+
var limit = as(plan, LimitExec.class);
1696+
var exchange = as(limit.child(), ExchangeExec.class);
1697+
var project = as(exchange.child(), ProjectExec.class);
1698+
var fieldExtract = as(project.child(), FieldExtractExec.class);
1699+
var esQuery = as(fieldExtract.child(), EsQueryExec.class);
1700+
Source source = new Source(2, 38, "salary > 10000");
1701+
BoolQueryBuilder expected = new BoolQueryBuilder().must(new MatchQueryBuilder("last_name", "Smith").lenient(true))
1702+
.must(wrapWithSingleQuery(query, QueryBuilders.rangeQuery("salary").gt(10000), "salary", source));
1703+
assertThat(esQuery.query().toString(), equalTo(expected.toString()));
1704+
}
1705+
16881706
public void testMatchFunctionWithNonPushableDisjunction() {
16891707
String query = """
16901708
from test
@@ -1716,7 +1734,6 @@ public void testMatchFunctionWithPushableDisjunction() {
17161734
var project = as(exchange.child(), ProjectExec.class);
17171735
var fieldExtract = as(project.child(), FieldExtractExec.class);
17181736
var esQuery = as(fieldExtract.child(), EsQueryExec.class);
1719-
var boolQuery = as(esQuery.query(), BoolQueryBuilder.class);
17201737
Source source = new Source(2, 37, "emp_no > 10");
17211738
BoolQueryBuilder expected = new BoolQueryBuilder().should(new MatchQueryBuilder("last_name", "Smith").lenient(true))
17221739
.should(wrapWithSingleQuery(query, QueryBuilders.rangeQuery("emp_no").gt(10), "emp_no", source));

0 commit comments

Comments
 (0)