-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Guian Gumpac <guiang@bitquilltech.com>
- Loading branch information
Guian Gumpac
authored
Dec 7, 2022
1 parent
64a3794
commit 2af7321
Showing
29 changed files
with
1,015 additions
and
38 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{"index":{"_id":"0"}} | ||
{"Body":"test wildcard"} | ||
{"index":{"_id":"1"}} | ||
{"Body":"test wildcard in the end of the text%"} | ||
{"index":{"_id":"2"}} | ||
{"Body":"%test wildcard in the beginning of the text"} | ||
{"index":{"_id":"3"}} | ||
{"Body":"test wildcard in % the middle of the text"} | ||
{"index":{"_id":"4"}} | ||
{"Body":"test wildcard %% beside each other"} | ||
{"index":{"_id":"5"}} | ||
{"Body":"test wildcard in the end of the text_"} | ||
{"index":{"_id":"6"}} | ||
{"Body":"_test wildcard in the beginning of the text"} | ||
{"index":{"_id":"7"}} | ||
{"Body":"test wildcard in _ the middle of the text"} | ||
{"index":{"_id":"8"}} | ||
{"Body":"test wildcard __ beside each other"} | ||
{"index":{"_id":"9"}} | ||
{"Body":"test backslash wildcard \\_"} | ||
{"index":{"_id":"10"}} | ||
{"Body":"tEsT wIlDcArD sensitive cases"} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"mappings" : { | ||
"properties" : { | ||
"Body" : { | ||
"type" : "keyword" | ||
} | ||
} | ||
} | ||
} |
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
88 changes: 88 additions & 0 deletions
88
integ-test/src/test/java/org/opensearch/sql/ppl/LikeQueryIT.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,88 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_WILDCARD; | ||
import static org.opensearch.sql.util.MatcherUtils.rows; | ||
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; | ||
|
||
import java.io.IOException; | ||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
|
||
public class LikeQueryIT extends PPLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.WILDCARD); | ||
} | ||
|
||
@Test | ||
public void test_like_with_percent() throws IOException { | ||
String query = "source=" + TEST_INDEX_WILDCARD + " | WHERE Like(KeywordBody, 'test wildcard%') | fields KeywordBody"; | ||
JSONObject result = executeQuery(query); | ||
verifyDataRows(result, | ||
rows("test wildcard"), | ||
rows("test wildcard in the end of the text%"), | ||
rows("test wildcard in % the middle of the text"), | ||
rows("test wildcard %% beside each other"), | ||
rows("test wildcard in the end of the text_"), | ||
rows("test wildcard in _ the middle of the text"), | ||
rows("test wildcard __ beside each other")); | ||
} | ||
|
||
@Test | ||
public void test_like_with_escaped_percent() throws IOException { | ||
String query = "source=" + TEST_INDEX_WILDCARD + " | WHERE Like(KeywordBody, '\\\\%test wildcard%') | fields KeywordBody"; | ||
JSONObject result = executeQuery(query); | ||
verifyDataRows(result, | ||
rows("%test wildcard in the beginning of the text")); | ||
} | ||
|
||
@Test | ||
public void test_like_in_where_with_escaped_underscore() throws IOException { | ||
String query = "source=" + TEST_INDEX_WILDCARD + " | WHERE Like(KeywordBody, '\\\\_test wildcard%') | fields KeywordBody"; | ||
JSONObject result = executeQuery(query); | ||
verifyDataRows(result, | ||
rows("_test wildcard in the beginning of the text")); | ||
} | ||
|
||
@Test | ||
public void test_like_on_text_field_with_one_word() throws IOException { | ||
String query = "source=" + TEST_INDEX_WILDCARD + " | WHERE Like(TextBody, 'test*') | fields TextBody"; | ||
JSONObject result = executeQuery(query); | ||
assertEquals(9, result.getInt("total")); | ||
} | ||
|
||
@Test | ||
public void test_like_on_text_keyword_field_with_one_word() throws IOException { | ||
String query = "source=" + TEST_INDEX_WILDCARD + " | WHERE Like(TextKeywordBody, 'test*') | fields TextKeywordBody"; | ||
JSONObject result = executeQuery(query); | ||
assertEquals(8, result.getInt("total")); | ||
} | ||
|
||
@Test | ||
public void test_like_on_text_keyword_field_with_greater_than_one_word() throws IOException { | ||
String query = "source=" + TEST_INDEX_WILDCARD + " | WHERE Like(TextKeywordBody, 'test wild*') | fields TextKeywordBody"; | ||
JSONObject result = executeQuery(query); | ||
assertEquals(7, result.getInt("total")); | ||
} | ||
|
||
@Test | ||
public void test_like_on_text_field_with_greater_than_one_word() throws IOException { | ||
String query = "source=" + TEST_INDEX_WILDCARD + " | WHERE Like(TextBody, 'test wild*') | fields TextBody"; | ||
JSONObject result = executeQuery(query); | ||
assertEquals(0, result.getInt("total")); | ||
} | ||
|
||
@Test | ||
public void test_convert_field_text_to_keyword() throws IOException { | ||
String query = "source=" + TEST_INDEX_WILDCARD + " | WHERE Like(TextKeywordBody, '*') | fields TextKeywordBody"; | ||
String result = explainQueryToString(query); | ||
assertTrue(result.contains("TextKeywordBody.keyword")); | ||
} | ||
} |
Oops, something went wrong.