Skip to content

Commit a584ca9

Browse files
committed
add type wildcard test
1 parent 88bf672 commit a584ca9

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/test/java/org/nlpcn/es4sql/MainTestSuite.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ public static void setUp() throws Exception {
5050
deleteQuery(TEST_INDEX);
5151
loadBulk("src/test/resources/accounts.json");
5252
loadBulk("src/test/resources/phrases.json");
53+
loadBulk("src/test/resources/phrases_2.json");
5354
loadBulk("src/test/resources/online.json");
5455

56+
5557
searchDao = new SearchDao(client);
5658
System.out.println("Finished the setup process...");
5759
}

src/test/java/org/nlpcn/es4sql/QueryTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public void multipleFromTest() throws IOException, SqlParseException, SQLFeature
3535
Assert.assertEquals(1004, response.getTotalHits());
3636
}
3737

38+
@Test
39+
public void typeWithWildcardTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException{
40+
SearchHits response = query(String.format("SELECT * FROM %s/phrase* LIMIT 1000", TEST_INDEX));
41+
Assert.assertEquals(8, response.getTotalHits());
42+
}
43+
3844

3945
@Test
4046
public void selectSpecificFields() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
@@ -67,7 +73,7 @@ public void selectAliases() throws IOException, SqlParseException, SQLFeatureNot
6773

6874
@Test
6975
public void equallityTest() throws SqlParseException, SQLFeatureNotSupportedException {
70-
SearchHits response = query(String.format("select * from %s where city = 'Nogal' LIMIT 1000", TEST_INDEX));
76+
SearchHits response = query(String.format("select * from %s/phrase where city = 'Nogal' LIMIT 1000", TEST_INDEX));
7177
SearchHit[] hits = response.getHits();
7278

7379
// assert the results is correct according to accounts.json data.
@@ -80,7 +86,7 @@ public void equallityTest() throws SqlParseException, SQLFeatureNotSupportedExce
8086
// in some cases, depends on the analasis, we might want choose better behavior for equallity.
8187
@Test
8288
public void equallityTest_phrase() throws SqlParseException, SQLFeatureNotSupportedException {
83-
SearchHits response = query(String.format("SELECT * FROM %s WHERE phrase = 'quick fox here' LIMIT 1000", TEST_INDEX));
89+
SearchHits response = query(String.format("SELECT * FROM %s/phrase WHERE phrase = 'quick fox here' LIMIT 1000", TEST_INDEX));
8490
SearchHit[] hits = response.getHits();
8591

8692
// assert the results is correct according to accounts.json data.
@@ -228,7 +234,7 @@ public void notBetweenTest() throws IOException, SqlParseException, SQLFeatureNo
228234

229235
@Test
230236
public void inTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException{
231-
SearchHits response = query(String.format("SELECT age FROM %s WHERE age IN (20, 22) LIMIT 1000", TEST_INDEX));
237+
SearchHits response = query(String.format("SELECT age FROM %s/phrase WHERE age IN (20, 22) LIMIT 1000", TEST_INDEX));
232238
SearchHit[] hits = response.getHits();
233239
for(SearchHit hit : hits) {
234240
int age = (int) hit.getSource().get("age");
@@ -239,7 +245,7 @@ public void inTest() throws IOException, SqlParseException, SQLFeatureNotSupport
239245

240246
@Test
241247
public void inTestWithStrings() throws IOException, SqlParseException, SQLFeatureNotSupportedException{
242-
SearchHits response = query(String.format("SELECT phrase FROM %s WHERE phrase IN ('quick fox here', 'fox brown') LIMIT 1000", TEST_INDEX));
248+
SearchHits response = query(String.format("SELECT phrase FROM %s/phrase WHERE phrase IN ('quick fox here', 'fox brown') LIMIT 1000", TEST_INDEX));
243249
SearchHit[] hits = response.getHits();
244250
Assert.assertEquals(2, response.getTotalHits());
245251
for(SearchHit hit : hits) {

src/test/resources/phrases_2.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{"index":{"_type": "phrase_2"}}
2+
{"phrase": "quick fox"}
3+
{"index":{"_type": "phrase_2"}}
4+
{"phrase": "quick fox here", "insert_time":"2014-08-19T07:09:13.434Z" }
5+
{"index":{"_type": "phrase_2"}}
6+
{"phrase": "brown fox"}
7+
{"index":{"_type": "phrase_2"}}
8+
{"phrase": "fox brown", "insert_time":"2014-08-19T07:09:13.434Z"}

0 commit comments

Comments
 (0)