Skip to content

Commit eac33c1

Browse files
committed
improved tests
1 parent f0d3b76 commit eac33c1

File tree

1 file changed

+65
-36
lines changed
  • x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin

1 file changed

+65
-36
lines changed

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

Lines changed: 65 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
1616
import org.elasticsearch.xpack.kql.KqlPlugin;
1717
import org.junit.Before;
18-
import org.junit.Ignore;
1918

2019
import java.util.Collection;
2120
import java.util.List;
@@ -30,45 +29,52 @@ public void setupIndex() {
3029
createAndPopulateIndex();
3130
}
3231

33-
public void testSimpleWhereMatch() {
32+
33+
public void testScoreDifferentWhereMatch() {
3434
var query = """
3535
FROM test METADATA _score
36-
| WHERE match(content, "brown")
36+
| EVAL first_score = score(match(content, "brown"))
3737
| WHERE match(content, "fox")
38-
| KEEP id, _score
38+
| KEEP id, _score, first_score
3939
| SORT id
4040
""";
4141

4242
try (var resp = run(query)) {
43-
assertColumnNames(resp.columns(), List.of("id", "_score"));
44-
assertColumnTypes(resp.columns(), List.of("integer", "double"));
45-
assertValues(resp.values(), List.of(List.of(1, 1.4274532794952393), List.of(6, 1.1248724460601807)));
43+
assertColumnNames(resp.columns(), List.of("id", "_score", "first_score"));
44+
assertColumnTypes(resp.columns(), List.of("integer", "double", "double"));
45+
assertValues(
46+
resp.values(),
47+
List.of(List.of(1, 1.156558871269226, 0.2708943784236908), List.of(6, 0.9114001989364624, 0.21347221732139587))
48+
);
4649
}
4750
}
4851

49-
@Ignore
50-
public void testAlternativeWhereMatch() {
52+
public void testScoreMultipleWhereMatchMatch() {
5153
var query = """
5254
FROM test METADATA _score
53-
| EVAL s1 = score(match(content, "brown"))
54-
| WHERE s1 > 0
55+
| WHERE match(content, "brown")
5556
| WHERE match(content, "fox")
56-
| KEEP id, _score
57+
| EVAL first_score = score(match(content, "brown"))
58+
| KEEP id, _score, first_score
5759
| SORT id
5860
""";
5961

6062
try (var resp = run(query)) {
61-
assertColumnNames(resp.columns(), List.of("id", "_score"));
62-
assertColumnTypes(resp.columns(), List.of("integer", "double"));
63-
assertValues(resp.values(), List.of(List.of(1, 1.4274532794952393), List.of(6, 1.1248724460601807)));
63+
assertColumnNames(resp.columns(), List.of("id", "_score", "first_score"));
64+
assertColumnTypes(resp.columns(), List.of("integer", "double", "double"));
65+
assertValues(
66+
resp.values(),
67+
List.of(List.of(1, 1.4274532794952393, 0.2708943784236908), List.of(6, 1.1248724460601807, 0.21347221732139587))
68+
);
6469
}
6570
}
6671

67-
public void testSimpleScoreWhereMatch() {
72+
public void testScoreMultipleWhereKqlMatch() {
6873
var query = """
6974
FROM test METADATA _score
70-
| EVAL first_score = score(match(content, "brown"))
75+
| WHERE kql("brown")
7176
| WHERE match(content, "fox")
77+
| EVAL first_score = score(kql("brown"))
7278
| KEEP id, _score, first_score
7379
| SORT id
7480
""";
@@ -78,17 +84,17 @@ public void testSimpleScoreWhereMatch() {
7884
assertColumnTypes(resp.columns(), List.of("integer", "double", "double"));
7985
assertValues(
8086
resp.values(),
81-
List.of(List.of(1, 1.156558871269226, 0.2708943784236908), List.of(6, 0.9114001989364624, 0.21347221732139587))
87+
List.of(List.of(1, 1.4274532794952393, 0.2708943784236908), List.of(6, 1.1248724460601807, 0.21347221732139587))
8288
);
8389
}
8490
}
8591

86-
public void testScorePlusWhereMatch() {
92+
public void testScoreMultipleWhereQstrMatch() {
8793
var query = """
8894
FROM test METADATA _score
89-
| WHERE match(content, "brown")
95+
| WHERE qstr("brown")
9096
| WHERE match(content, "fox")
91-
| EVAL first_score = score(match(content, "brown"))
97+
| EVAL first_score = score(qstr("brown"))
9298
| KEEP id, _score, first_score
9399
| SORT id
94100
""";
@@ -103,12 +109,11 @@ public void testScorePlusWhereMatch() {
103109
}
104110
}
105111

106-
public void testScorePlusWhereKql() {
112+
public void testScoreSameWhereQstrAndMatch() {
107113
var query = """
108114
FROM test METADATA _score
109-
| WHERE kql("brown")
110-
| WHERE match(content, "fox")
111-
| EVAL first_score = score(kql("brown"))
115+
| WHERE qstr("brown") AND match(content, "fox")
116+
| EVAL first_score = score(qstr("brown") AND match(content, "fox"))
112117
| KEEP id, _score, first_score
113118
| SORT id
114119
""";
@@ -118,16 +123,15 @@ public void testScorePlusWhereKql() {
118123
assertColumnTypes(resp.columns(), List.of("integer", "double", "double"));
119124
assertValues(
120125
resp.values(),
121-
List.of(List.of(1, 1.4274532794952393, 0.2708943784236908), List.of(6, 1.1248724460601807, 0.21347221732139587))
126+
List.of(List.of(1, 1.4274532794952393, 1.4274532496929169), List.of(6, 1.1248724460601807, 1.1248724162578583))
122127
);
123128
}
124129
}
125130

126-
public void testScorePlusWhereQstr() {
131+
public void testScoreSingleWhereQstrAndMatch() {
127132
var query = """
128133
FROM test METADATA _score
129-
| WHERE qstr("brown")
130-
| WHERE match(content, "fox")
134+
| WHERE qstr("brown") AND match(content, "fox")
131135
| EVAL first_score = score(qstr("brown"))
132136
| KEEP id, _score, first_score
133137
| SORT id
@@ -143,11 +147,11 @@ public void testScorePlusWhereQstr() {
143147
}
144148
}
145149

146-
public void testScorePlusWhereQstrAndMatch() {
150+
public void testScoreSameWhereKqlAndMatch() {
147151
var query = """
148152
FROM test METADATA _score
149-
| WHERE qstr("brown") AND match(content, "fox")
150-
| EVAL first_score = score(qstr("brown") AND match(content, "fox"))
153+
| WHERE kql("brown") AND match(content, "fox")
154+
| EVAL first_score = score(kql("brown") AND match(content, "fox"))
151155
| KEEP id, _score, first_score
152156
| SORT id
153157
""";
@@ -162,11 +166,11 @@ public void testScorePlusWhereQstrAndMatch() {
162166
}
163167
}
164168

165-
public void testScorePlusWhereKqlAndMatch() {
169+
public void testScoreSingleWhereKqlAndMatch() {
166170
var query = """
167171
FROM test METADATA _score
168172
| WHERE kql("brown") AND match(content, "fox")
169-
| EVAL first_score = score(kql("brown") AND match(content, "fox"))
173+
| EVAL first_score = score(kql("brown"))
170174
| KEEP id, _score, first_score
171175
| SORT id
172176
""";
@@ -176,12 +180,12 @@ public void testScorePlusWhereKqlAndMatch() {
176180
assertColumnTypes(resp.columns(), List.of("integer", "double", "double"));
177181
assertValues(
178182
resp.values(),
179-
List.of(List.of(1, 1.4274532794952393, 1.4274532496929169), List.of(6, 1.1248724460601807, 1.1248724162578583))
183+
List.of(List.of(1, 1.4274532794952393, 0.2708943784236908), List.of(6, 1.1248724460601807, 0.21347221732139587))
180184
);
181185
}
182186
}
183187

184-
public void testScorePlusWhereQstrORMatch() {
188+
public void testScoreSameWhereQstrORMatch() {
185189
var query = """
186190
FROM test METADATA _score
187191
| WHERE qstr("brown") OR match(content, "fox")
@@ -206,6 +210,31 @@ public void testScorePlusWhereQstrORMatch() {
206210
}
207211
}
208212

213+
public void testScoreSingleWhereQstrORMatch() {
214+
var query = """
215+
FROM test METADATA _score
216+
| WHERE qstr("brown") OR match(content, "fox")
217+
| EVAL first_score = score(qstr("brown"))
218+
| KEEP id, _score, first_score
219+
| SORT id
220+
""";
221+
222+
try (var resp = run(query)) {
223+
assertColumnNames(resp.columns(), List.of("id", "_score", "first_score"));
224+
assertColumnTypes(resp.columns(), List.of("integer", "double", "double"));
225+
assertValues(
226+
resp.values(),
227+
List.of(
228+
List.of(1, 1.4274532794952393, 0.2708943784236908),
229+
List.of(2, 0.2708943784236908, 0.2708943784236908),
230+
List.of(3, 0.2708943784236908, 0.2708943784236908),
231+
List.of(4, 0.19301524758338928, 0.19301524758338928),
232+
List.of(6, 1.1248724460601807, 0.21347221732139587)
233+
)
234+
);
235+
}
236+
}
237+
209238
public void testSimpleScoreAlone() {
210239
var query = """
211240
FROM test METADATA _score

0 commit comments

Comments
 (0)