forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05fc57a
commit a3e4852
Showing
9 changed files
with
219 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
x-pack/plugin/esql/qa/testFixtures/src/main/resources/qstr-function.csv-spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
############################################### | ||
# Tests for QSTR function | ||
# | ||
|
||
qstrWithField | ||
required_capability: qstr_function | ||
// tag::qstr-with-field[] | ||
from books | where qstr("author: Faulkner") | keep book_no, author | sort book_no | LIMIT 5; | ||
// end::qstr-with-field[] | ||
|
||
book_no:keyword | author:text | ||
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott] | ||
2713 | William Faulkner | ||
2847 | Colleen Faulkner | ||
2883 | William Faulkner | ||
3293 | Danny Faulkner | ||
; |
121 changes: 121 additions & 0 deletions
121
...c/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/QueryStringFunctionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.plugin; | ||
|
||
import org.elasticsearch.Build; | ||
import org.elasticsearch.action.index.IndexRequest; | ||
import org.elasticsearch.action.support.WriteRequest; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase; | ||
import org.elasticsearch.xpack.esql.action.ColumnInfoImpl; | ||
import org.elasticsearch.xpack.esql.action.EsqlCapabilities; | ||
import org.elasticsearch.xpack.esql.action.EsqlQueryRequest; | ||
import org.elasticsearch.xpack.esql.action.EsqlQueryResponse; | ||
import org.elasticsearch.xpack.esql.core.type.DataType; | ||
import org.junit.Before; | ||
|
||
import java.util.List; | ||
|
||
import static org.elasticsearch.test.ListMatcher.matchesList; | ||
import static org.elasticsearch.test.MapMatcher.assertMap; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class QueryStringFunctionIT extends AbstractEsqlIntegTestCase { | ||
|
||
@Before | ||
public void setupIndex() { | ||
createAndPopulateIndex(); | ||
} | ||
|
||
@Override | ||
protected EsqlQueryResponse run(EsqlQueryRequest request) { | ||
assumeTrue("qstr function available in snapshot builds only", EsqlCapabilities.Cap.QSTR_FUNCTION.isEnabled()); | ||
return super.run(request); | ||
} | ||
|
||
public void testSimpleQueryString() { | ||
var query = """ | ||
FROM test | ||
| WHERE qstr("content: dog") | ||
| KEEP id | ||
| SORT id | ||
"""; | ||
|
||
try (var resp = run(query)) { | ||
assertThat(resp.columns().stream().map(ColumnInfoImpl::name).toList(), equalTo(List.of("id"))); | ||
assertThat(resp.columns().stream().map(ColumnInfoImpl::type).map(DataType::toString).toList(), equalTo(List.of("INTEGER"))); | ||
// values | ||
List<List<Object>> values = getValuesList(resp); | ||
assertMap(values, matchesList().item(List.of(1)).item(List.of(3)).item(List.of(4)).item(List.of(5))); | ||
} | ||
} | ||
|
||
public void testMultiFieldQueryString() { | ||
var query = """ | ||
FROM test | ||
| WHERE qstr("dog OR canine") | ||
"""; | ||
|
||
try (var resp = run(query)) { | ||
assertThat(resp.columns().stream().map(ColumnInfoImpl::name).toList(), equalTo(List.of("id"))); | ||
assertThat(resp.columns().stream().map(ColumnInfoImpl::type).map(DataType::toString).toList(), equalTo(List.of("INTEGER"))); | ||
// values | ||
List<List<Object>> values = getValuesList(resp); | ||
assertThat(values.size(), equalTo(5)); | ||
} | ||
} | ||
|
||
private void createAndPopulateIndex() { | ||
var indexName = "test"; | ||
var client = client().admin().indices(); | ||
var CreateRequest = client.prepareCreate(indexName) | ||
.setSettings(Settings.builder().put("index.number_of_shards", 1)) | ||
.setMapping("id", "type=integer", "content", "type=text"); | ||
assertAcked(CreateRequest); | ||
client().prepareBulk() | ||
.add( | ||
new IndexRequest(indexName).id("1") | ||
.source("id", 1, "content", "The quick brown animal swiftly jumps over a lazy dog", "title", "A Swift Fox's Journey") | ||
) | ||
.add( | ||
new IndexRequest(indexName).id("2") | ||
.source("id", 2, "content", "A speedy brown fox hops effortlessly over a sluggish canine", "title", "The Fox's Leap") | ||
) | ||
.add( | ||
new IndexRequest(indexName).id("3") | ||
.source("id", 4, "content", "Quick and nimble, the fox vaults over the lazy dog", "title", "Brown Fox in Action") | ||
) | ||
.add( | ||
new IndexRequest(indexName).id("4") | ||
.source( | ||
"id", | ||
5, | ||
"content", | ||
"A fox that is quick and brown jumps over a dog that is quite lazy", | ||
"title", | ||
"Speedy Animals" | ||
) | ||
) | ||
.add( | ||
new IndexRequest(indexName).id("5") | ||
.source( | ||
"id", | ||
6, | ||
"content", | ||
"With agility, a quick brown fox bounds over a slow-moving dog", | ||
"title", | ||
"Foxes and Canines" | ||
) | ||
) | ||
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) | ||
.get(); | ||
ensureYellow(indexName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters