Skip to content

Commit d5c9d91

Browse files
committed
Start adding CSV tests
1 parent 675e78b commit d5c9d91

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
###############################################
2+
# Tests for ExtractSnippets function
3+
#
4+
5+
extractSnippetsWithField
6+
required_capability: extract_snippets_function
7+
8+
// tag::extract-snippets-with-field[]
9+
FROM books
10+
| WHERE MATCH(description, "hobbit")
11+
| EVAL snippets = extract_snippets(description, "hobbit", 1, 25)
12+
// end::extract-snippets-with-field[]
13+
| KEEP book_no, author, title, snippets
14+
| SORT book_no
15+
| LIMIT 5
16+
;
17+
18+
// tag::extract-snippets-with-field-result[]
19+
book_no:keyword | author:text | title:text | snippets:keyword
20+
1463 | J. R. R. Tolkien | Realms of Tolkien: Images of Middle-earth | appropriate passage from The Hobbit
21+
2301 | John Ronald Reuel Tolkien | Smith of Wootton Major & Farmer Giles of Ham | beloved author of THE HOBBIT
22+
2675 | J.R.R. Tolkien | The Lord of the Rings - Boxed Set | Bilbo Baggins is a hobbit
23+
2714 | J. R. R. Tolkien | Return of the King Being the Third Part of The Lord of the Rings | the story begun in The Hobbit
24+
2936 | John Ronald Reuel Tolkien | Fellowship of the Ring 2ND Edition | into the hands of the hobbit
25+
// end::extract-snippets-with-field-result[]
26+
;
27+
28+
extractMultipleSnippetsWithField
29+
required_capability: extract_snippets_function
30+
31+
FROM books
32+
| WHERE MATCH(description, "hobbit")
33+
| EVAL snippets = extract_snippets(description, "hobbit", 3, 25)
34+
| KEEP book_no, author, title, snippets
35+
| SORT book_no
36+
| LIMIT 5
37+
;
38+
39+
book_no:keyword | author:text | title:text | snippets:keyword
40+
1463 | J. R. R. Tolkien | Realms of Tolkien: Images of Middle-earth | appropriate passage from The Hobbit
41+
2301 | John Ronald Reuel Tolkien | Smith of Wootton Major & Farmer Giles of Ham | beloved author of THE HOBBIT
42+
2675 | J.R.R. Tolkien | The Lord of the Rings - Boxed Set | [Bilbo Baggins is a hobbit, beautiful gift edition of The Hobbit, Tolkien's own children, The Hobbit]
43+
2714 | J. R. R. Tolkien | Return of the King Being the Third Part of The Lord of the Rings | [the story begun in The Hobbit, , THE HOBBIT: AN UNEXPECTED, film adaptation of The Hobbit]
44+
2936 | John Ronald Reuel Tolkien | Fellowship of the Ring 2ND Edition | into the hands of the hobbit
45+
;
46+
47+
48+
extractMultipleSnippetsWithFieldMvExpand
49+
required_capability: extract_snippets_function
50+
51+
FROM books
52+
| WHERE MATCH(description, "hobbit")
53+
| EVAL snippets = extract_snippets(description, "hobbit", 3, 25)
54+
| MV_EXPAND snippets
55+
| KEEP book_no, author, title, snippets
56+
| SORT book_no
57+
| LIMIT 5
58+
;
59+
60+
book_no:keyword | author:text | title:text | snippets:keyword
61+
1463 | J. R. R. Tolkien | Realms of Tolkien: Images of Middle-earth | appropriate passage from The Hobbit
62+
2301 | John Ronald Reuel Tolkien | Smith of Wootton Major & Farmer Giles of Ham | beloved author of THE HOBBIT
63+
2675 | J.R.R. Tolkien | The Lord of the Rings - Boxed Set | beautiful gift edition of The Hobbit
64+
2675 | J.R.R. Tolkien | The Lord of the Rings - Boxed Set | Tolkien's own children, The Hobbit
65+
2675 | J.R.R. Tolkien | The Lord of the Rings - Boxed Set | Bilbo Baggins is a hobbit
66+
;
67+
68+
extractMultipleSnippetsWithSomeNoMatches
69+
required_capability: extract_snippets_function
70+
71+
FROM books
72+
| WHERE MATCH(author, "Faulkner")
73+
| EVAL snippets = extract_snippets(description, "slavery", 1, 10)
74+
| KEEP book_no, author, title, snippets
75+
| SORT book_no
76+
| LIMIT 5
77+
;
78+
79+
book_no:keyword | author:text | title:text | snippets:keyword
80+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott] | Selected Letters of Lucretia Coffin Mott (Women in American History) | abolition of slavery
81+
2713 | William Faulkner | Collected Stories of William Faulkner | null
82+
2847 | Colleen Faulkner | To Love A Dark Stranger (Lovegram Historical Romance) | null
83+
2883 | William Faulkner | A Summer of Faulkner: As I Lay Dying/The Sound and the Fury/Light in August (Oprah's Book Club) | null
84+
3293 | Danny Faulkner | Universe by Design | null
85+
;
86+
87+
88+
extractSnippetsWithDefaultNumSnippetsAndLength
89+
required_capability: extract_snippets_function
90+
91+
extractSnippetsCalledMultipleTimes
92+
required_capability: extract_snippets_function

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,12 @@ public enum Cap {
13451345
/**
13461346
* Support correct counting of skipped shards.
13471347
*/
1348-
CORRECT_SKIPPED_SHARDS_COUNT;
1348+
CORRECT_SKIPPED_SHARDS_COUNT,
1349+
1350+
/**
1351+
* Support for the EXTRACT_SNIPPETS function.
1352+
*/
1353+
EXTRACT_SNIPPETS_FUNCTION(Build.current().isSnapshot());
13491354

13501355
private final boolean enabled;
13511356

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ public final void test() throws Throwable {
335335
"CSV tests cannot currently handle multi_match function that depends on Lucene",
336336
testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.MULTI_MATCH_FUNCTION.capabilityName())
337337
);
338+
assumeFalse(
339+
"CSV tests cannot currently handle EXTRACT_SNIPPETS",
340+
testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.EXTRACT_SNIPPETS_FUNCTION.capabilityName())
341+
);
338342

339343
if (Build.current().isSnapshot()) {
340344
assertThat(

0 commit comments

Comments
 (0)