|
4 | 4 | import org.junit.Test;
|
5 | 5 | import org.nlpcn.es4sql.exception.SqlParseException;
|
6 | 6 | import org.nlpcn.es4sql.query.SqlElasticRequestBuilder;
|
7 |
| - |
8 |
| - |
9 | 7 | import java.io.File;
|
10 | 8 | import java.io.IOException;
|
11 | 9 | import java.lang.reflect.InvocationTargetException;
|
12 | 10 | import java.nio.charset.StandardCharsets;
|
13 | 11 | import java.sql.SQLFeatureNotSupportedException;
|
14 | 12 |
|
15 | 13 | import static org.hamcrest.MatcherAssert.assertThat;
|
16 |
| -import static org.nlpcn.es4sql.TestsConstants.TEST_INDEX; |
17 | 14 | import static org.hamcrest.Matchers.*;
|
| 15 | +import static org.nlpcn.es4sql.TestsConstants.*; |
18 | 16 |
|
19 | 17 | public class ExplainTest {
|
20 | 18 |
|
21 | 19 | @Test
|
22 | 20 | public void searchSanity() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
|
23 | 21 | String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/search_explain.json"), StandardCharsets.UTF_8).replaceAll("\r","");
|
24 |
| - String result = explain(String.format("SELECT * FROM %s WHERE firstname LIKE 'A%%' AND age > 20 GROUP BY gender order by _score", TEST_INDEX)); |
| 22 | + String result = explain(String.format("SELECT * FROM %s WHERE firstname LIKE 'A%%' AND age > 20 GROUP BY gender order by _score", TEST_INDEX_ACCOUNT)); |
25 | 23 |
|
26 | 24 | assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
|
27 | 25 | }
|
28 | 26 |
|
29 | 27 | @Test
|
30 | 28 | public void aggregationQuery() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
|
31 | 29 | String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/aggregation_query_explain.json"), StandardCharsets.UTF_8).replaceAll("\r","");
|
32 |
| - String result = explain(String.format("SELECT a, CASE WHEN gender='0' then 'aaa' else 'bbb'end a2345,count(c) FROM %s GROUP BY terms('field'='a'),a2345", TEST_INDEX)); |
| 30 | + String result = explain(String.format("SELECT a, CASE WHEN gender='0' then 'aaa' else 'bbb'end a2345,count(c) FROM %s GROUP BY terms('field'='a'),a2345", TEST_INDEX_ACCOUNT)); |
33 | 31 |
|
34 | 32 | assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
|
35 | 33 | }
|
36 | 34 |
|
37 | 35 | @Test
|
38 | 36 | public void explainScriptValue() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
|
39 | 37 | String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/script_value.json"), StandardCharsets.UTF_8).replaceAll("\r","");
|
40 |
| - String result = explain(String.format("SELECT case when gender is null then 'aaa' else gender end test , cust_code FROM %s", TEST_INDEX)); |
| 38 | + String result = explain(String.format("SELECT case when gender is null then 'aaa' else gender end test , cust_code FROM %s", TEST_INDEX_ACCOUNT)); |
41 | 39 |
|
42 | 40 | assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
|
43 | 41 | }
|
44 | 42 |
|
45 | 43 | @Test
|
46 | 44 | public void betweenScriptValue() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
|
47 | 45 | String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/between_query.json"), StandardCharsets.UTF_8).replaceAll("\r","");
|
48 |
| - String result = explain(String.format("SELECT case when value between 100 and 200 then 'aaa' else value end test , cust_code FROM %s", TEST_INDEX)); |
| 46 | + String result = explain(String.format("SELECT case when value between 100 and 200 then 'aaa' else value end test , cust_code FROM %s", TEST_INDEX_ACCOUNT)); |
49 | 47 |
|
50 | 48 | assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
|
51 | 49 | }
|
52 | 50 |
|
53 | 51 | @Test
|
54 | 52 | public void searchSanityFilter() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
|
55 | 53 | String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/search_explain_filter.json"), StandardCharsets.UTF_8).replaceAll("\r","");
|
56 |
| - String result = explain(String.format("SELECT * FROM %s WHERE firstname LIKE 'A%%' AND age > 20 GROUP BY gender", TEST_INDEX)); |
| 54 | + String result = explain(String.format("SELECT * FROM %s WHERE firstname LIKE 'A%%' AND age > 20 GROUP BY gender", TEST_INDEX_ACCOUNT)); |
57 | 55 |
|
58 | 56 | assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
|
59 | 57 | }
|
60 | 58 |
|
61 | 59 | @Test
|
62 | 60 | public void deleteSanity() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
|
63 | 61 | String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/delete_explain.json"), StandardCharsets.UTF_8).replaceAll("\r","");;
|
64 |
| - String result = explain(String.format("DELETE FROM %s WHERE firstname LIKE 'A%%' AND age > 20", TEST_INDEX)); |
| 62 | + String result = explain(String.format("DELETE FROM %s WHERE firstname LIKE 'A%%' AND age > 20", TEST_INDEX_ACCOUNT)); |
65 | 63 |
|
66 | 64 | assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
|
67 | 65 | }
|
68 | 66 |
|
69 | 67 | @Test
|
70 | 68 | public void spatialFilterExplainTest() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
|
71 | 69 | String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/search_spatial_explain.json"), StandardCharsets.UTF_8).replaceAll("\r","");;
|
72 |
| - String result = explain(String.format("SELECT * FROM %s WHERE GEO_INTERSECTS(place,'POLYGON ((102 2, 103 2, 103 3, 102 3, 102 2))')", TEST_INDEX)); |
| 70 | + String result = explain(String.format("SELECT * FROM %s WHERE GEO_INTERSECTS(place,'POLYGON ((102 2, 103 2, 103 3, 102 3, 102 2))')", TEST_INDEX_LOCATION)); |
73 | 71 | assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
|
74 | 72 | }
|
75 | 73 |
|
|
0 commit comments