|
11 | 11 | import org.elasticsearch.action.support.WriteRequest;
|
12 | 12 | import org.elasticsearch.common.settings.Settings;
|
13 | 13 | import org.elasticsearch.compute.operator.DriverProfile;
|
14 |
| -import org.elasticsearch.test.junit.annotations.TestLogging; |
15 | 14 | import org.elasticsearch.xpack.esql.VerificationException;
|
16 | 15 | import org.elasticsearch.xpack.esql.parser.ParsingException;
|
17 | 16 | import org.junit.Before;
|
18 | 17 |
|
19 | 18 | import java.util.Arrays;
|
20 | 19 | import java.util.Iterator;
|
21 | 20 | import java.util.List;
|
| 21 | +import java.util.Map; |
22 | 22 | import java.util.Set;
|
23 | 23 | import java.util.function.Predicate;
|
24 | 24 | import java.util.stream.Collectors;
|
|
27 | 27 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
|
28 | 28 | import static org.hamcrest.Matchers.equalTo;
|
29 | 29 |
|
30 |
| -@TestLogging(value = "org.elasticsearch.xpack.esql:TRACE,org.elasticsearch.compute:TRACE", reason = "debug") |
| 30 | +// @TestLogging(value = "org.elasticsearch.xpack.esql:TRACE,org.elasticsearch.compute:TRACE", reason = "debug") |
31 | 31 | public class ForkIT extends AbstractEsqlIntegTestCase {
|
32 | 32 |
|
33 | 33 | @Before
|
@@ -800,6 +800,79 @@ public void testWithKeep() {
|
800 | 800 | }
|
801 | 801 | }
|
802 | 802 |
|
| 803 | + public void testWithUnsupportedFieldsWithSameBranches() { |
| 804 | + var query = """ |
| 805 | + FROM test-other |
| 806 | + | FORK |
| 807 | + ( WHERE id == "3") |
| 808 | + ( WHERE id == "2" ) |
| 809 | + | SORT _fork |
| 810 | + """; |
| 811 | + |
| 812 | + try (var resp = run(query)) { |
| 813 | + assertColumnNames(resp.columns(), List.of("content", "embedding", "id", "_fork")); |
| 814 | + assertColumnTypes(resp.columns(), List.of("keyword", "unsupported", "keyword", "keyword")); |
| 815 | + Iterable<Iterable<Object>> expectedValues = List.of( |
| 816 | + Arrays.stream(new Object[] { "This dog is really brown", null, "3", "fork1" }).toList(), |
| 817 | + Arrays.stream(new Object[] { "This is a brown dog", null, "2", "fork2" }).toList() |
| 818 | + ); |
| 819 | + assertValues(resp.values(), expectedValues); |
| 820 | + } |
| 821 | + } |
| 822 | + |
| 823 | + public void testWithUnsupportedFieldsWithDifferentBranches() { |
| 824 | + var query = """ |
| 825 | + FROM test-other |
| 826 | + | FORK |
| 827 | + ( STATS x = count(*)) |
| 828 | + ( WHERE id == "2" ) |
| 829 | + | SORT _fork |
| 830 | + """; |
| 831 | + |
| 832 | + try (var resp = run(query)) { |
| 833 | + assertColumnNames(resp.columns(), List.of("x", "_fork", "content", "embedding", "id")); |
| 834 | + assertColumnTypes(resp.columns(), List.of("long", "keyword", "keyword", "unsupported", "keyword")); |
| 835 | + Iterable<Iterable<Object>> expectedValues = List.of( |
| 836 | + Arrays.stream(new Object[] { 3L, "fork1", null, null, null }).toList(), |
| 837 | + Arrays.stream(new Object[] { null, "fork2", "This is a brown dog", null, "2" }).toList() |
| 838 | + ); |
| 839 | + assertValues(resp.values(), expectedValues); |
| 840 | + } |
| 841 | + } |
| 842 | + |
| 843 | + public void testWithUnsupportedFieldsAndConflicts() { |
| 844 | + var firstQuery = """ |
| 845 | + FROM test-other |
| 846 | + | FORK |
| 847 | + ( STATS embedding = count(*)) |
| 848 | + ( WHERE id == "2" ) |
| 849 | + | SORT _fork |
| 850 | + """; |
| 851 | + var e = expectThrows(VerificationException.class, () -> run(firstQuery)); |
| 852 | + assertTrue(e.getMessage().contains("Column [embedding] has conflicting data types")); |
| 853 | + |
| 854 | + var secondQuery = """ |
| 855 | + FROM test-other |
| 856 | + | FORK |
| 857 | + ( WHERE id == "2" ) |
| 858 | + ( STATS embedding = count(*)) |
| 859 | + | SORT _fork |
| 860 | + """; |
| 861 | + e = expectThrows(VerificationException.class, () -> run(secondQuery)); |
| 862 | + assertTrue(e.getMessage().contains("Column [embedding] has conflicting data types")); |
| 863 | + |
| 864 | + var thirdQuery = """ |
| 865 | + FROM test-other |
| 866 | + | FORK |
| 867 | + ( WHERE id == "2" ) |
| 868 | + ( WHERE id == "3" ) |
| 869 | + ( STATS embedding = count(*)) |
| 870 | + | SORT _fork |
| 871 | + """; |
| 872 | + e = expectThrows(VerificationException.class, () -> run(thirdQuery)); |
| 873 | + assertTrue(e.getMessage().contains("Column [embedding] has conflicting data types")); |
| 874 | + } |
| 875 | + |
803 | 876 | public void testWithEvalWithConflictingTypes() {
|
804 | 877 | var query = """
|
805 | 878 | FROM test
|
@@ -976,12 +1049,21 @@ private void createAndPopulateIndices() {
|
976 | 1049 |
|
977 | 1050 | createRequest = client.prepareCreate(otherTestIndex)
|
978 | 1051 | .setSettings(Settings.builder().put("index.number_of_shards", 1))
|
979 |
| - .setMapping("id", "type=keyword", "content", "type=keyword"); |
| 1052 | + .setMapping("id", "type=keyword", "content", "type=keyword", "embedding", "type=sparse_vector"); |
980 | 1053 | assertAcked(createRequest);
|
981 | 1054 | client().prepareBulk()
|
982 |
| - .add(new IndexRequest(otherTestIndex).id("1").source("id", "1", "content", "This is a brown fox")) |
983 |
| - .add(new IndexRequest(otherTestIndex).id("2").source("id", "2", "content", "This is a brown dog")) |
984 |
| - .add(new IndexRequest(otherTestIndex).id("3").source("id", "3", "content", "This dog is really brown")) |
| 1055 | + .add( |
| 1056 | + new IndexRequest(otherTestIndex).id("1") |
| 1057 | + .source("id", "1", "content", "This is a brown fox", "embedding", Map.of("abc", 1.0)) |
| 1058 | + ) |
| 1059 | + .add( |
| 1060 | + new IndexRequest(otherTestIndex).id("2") |
| 1061 | + .source("id", "2", "content", "This is a brown dog", "embedding", Map.of("def", 2.0)) |
| 1062 | + ) |
| 1063 | + .add( |
| 1064 | + new IndexRequest(otherTestIndex).id("3") |
| 1065 | + .source("id", "3", "content", "This dog is really brown", "embedding", Map.of("ghi", 1.0)) |
| 1066 | + ) |
985 | 1067 | .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
986 | 1068 | .get();
|
987 | 1069 | ensureYellow(indexName);
|
|
0 commit comments