forked from opensearch-project/sql
-
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.
Merge remote-tracking branch 'upstream/main' into dev-datetime-now
Signed-off-by: Yury Fridlyand <[email protected]>
- Loading branch information
Showing
30 changed files
with
731 additions
and
7,691 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
Binary file not shown.
Binary file not shown.
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
Binary file not shown.
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
48 changes: 48 additions & 0 deletions
48
core/src/test/java/org/opensearch/sql/common/utils/StringUtilsTest.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,48 @@ | ||
package org.opensearch.sql.common.utils; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opensearch.sql.common.utils.StringUtils.unquoteText; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class StringUtilsTest { | ||
@Test | ||
void unquoteTest() { | ||
assertEquals("test", unquoteText("test")); | ||
assertEquals("test", unquoteText("'test'")); | ||
assertEquals("test", unquoteText("`test`")); | ||
|
||
assertEquals("test'", unquoteText("'test'''")); | ||
assertEquals("test\"", unquoteText("\"test\"\"\"")); | ||
|
||
assertEquals("te``st", unquoteText("'te``st'")); | ||
assertEquals("te``st", unquoteText("\"te``st\"")); | ||
assertEquals("te``st", unquoteText("`te``st`")); | ||
|
||
assertEquals("te'st", unquoteText("'te''st'")); | ||
assertEquals("te''st", unquoteText("\"te''st\"")); | ||
assertEquals("te''st", unquoteText("`te''st`")); | ||
|
||
assertEquals("te\"\"st", unquoteText("'te\"\"st'")); | ||
assertEquals("te\"st", unquoteText("\"te\"\"st\"")); | ||
assertEquals("te\"\"st", unquoteText("`te\"\"st`")); | ||
|
||
assertEquals("''", unquoteText("''''''")); | ||
assertEquals("\"\"", unquoteText("\"\"\"\"\"\"")); | ||
assertEquals("````", unquoteText("``````")); | ||
|
||
assertEquals("test'", unquoteText("'test''")); | ||
|
||
assertEquals("", unquoteText("")); | ||
assertEquals("'", unquoteText("'")); | ||
assertEquals("`", unquoteText("`")); | ||
assertEquals("\"", unquoteText("\"")); | ||
|
||
assertEquals("hello'", unquoteText("'hello''")); | ||
assertEquals("don't", unquoteText("'don't'")); | ||
assertEquals("hello`", unquoteText("`hello``")); | ||
assertEquals("don\"t", unquoteText("\"don\"t\"")); | ||
|
||
} | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
integ-test/src/test/java/org/opensearch/sql/ppl/MatchIT.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,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; | ||
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.jupiter.api.Test; | ||
|
||
public class MatchIT extends PPLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.BANK); | ||
} | ||
|
||
@Test | ||
public void test_match_function() throws IOException { | ||
JSONObject result = | ||
executeQuery( | ||
String.format( | ||
"source=%s | where match(firstname, 'Hattie') | fields firstname", | ||
TEST_INDEX_BANK)); | ||
verifyDataRows(result, rows("Hattie")); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
integ-test/src/test/java/org/opensearch/sql/ppl/MatchPhraseIT.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,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_PHRASE; | ||
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.Ignore; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class MatchPhraseIT extends PPLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.PHRASE); | ||
} | ||
|
||
@Test | ||
public void test_match_phrase_function() throws IOException { | ||
JSONObject result = | ||
executeQuery( | ||
String.format( | ||
"source=%s | where match_phrase(phrase, 'quick fox') | fields phrase", TEST_INDEX_PHRASE)); | ||
verifyDataRows(result, rows("quick fox"), rows("quick fox here")); | ||
} | ||
|
||
@Test | ||
@Ignore("Not supported actually in PPL") | ||
public void test_matchphrase_legacy_function() throws IOException { | ||
JSONObject result = | ||
executeQuery( | ||
String.format( | ||
"source=%s | where matchphrase(phrase, 'quick fox') | fields phrase", TEST_INDEX_PHRASE)); | ||
verifyDataRows(result, rows("quick fox"), rows("quick fox here")); | ||
} | ||
|
||
@Test | ||
public void test_match_phrase_with_slop() throws IOException { | ||
JSONObject result = | ||
executeQuery( | ||
String.format( | ||
"source=%s | where match_phrase(phrase, 'brown fox', slop = 2) | fields phrase", TEST_INDEX_PHRASE)); | ||
verifyDataRows(result, rows("brown fox"), rows("fox brown")); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
integ-test/src/test/java/org/opensearch/sql/ppl/MultiMatchIT.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,58 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BEER; | ||
|
||
import java.io.IOException; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
|
||
public class MultiMatchIT extends PPLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.BEER); | ||
} | ||
|
||
@Test | ||
public void test_multi_match() throws IOException { | ||
String query = "SOURCE=" + TEST_INDEX_BEER | ||
+ " | WHERE multi_match([\\\"Tags\\\" ^ 1.5, Title, `Body` 4.2], 'taste') | fields Id"; | ||
var result = executeQuery(query); | ||
assertEquals(16, result.getInt("total")); | ||
} | ||
|
||
@Test | ||
public void test_multi_match_all_params() throws IOException { | ||
String query = "SOURCE=" + TEST_INDEX_BEER | ||
+ " | WHERE multi_match(['Body', Tags], 'taste beer', operator='and', analyzer=english," | ||
+ "auto_generate_synonyms_phrase_query=true, boost = 0.77, cutoff_frequency=0.33," | ||
+ "fuzziness = 'AUTO:1,5', fuzzy_transpositions = false, lenient = true, max_expansions = 25," | ||
+ "minimum_should_match = '2<-25% 9<-3', prefix_length = 7, tie_breaker = 0.3," | ||
+ "type = most_fields, slop = 2, zero_terms_query = 'ALL') | fields Id"; | ||
var result = executeQuery(query); | ||
assertEquals(10, result.getInt("total")); | ||
} | ||
|
||
@Test | ||
public void test_wildcard_multi_match() throws IOException { | ||
String query1 = "SOURCE=" + TEST_INDEX_BEER | ||
+ " | WHERE multi_match(['Tags'], 'taste') | fields Id"; | ||
var result1 = executeQuery(query1); | ||
String query2 = "SOURCE=" + TEST_INDEX_BEER | ||
+ " | WHERE multi_match(['T*'], 'taste') | fields Id"; | ||
var result2 = executeQuery(query2); | ||
assertNotEquals(result2.getInt("total"), result1.getInt("total")); | ||
|
||
String query3 = "source=" + TEST_INDEX_BEER | ||
+ " | where simple_query_string(['*Date'], '2014-01-22')"; | ||
JSONObject result3 = executeQuery(query3); | ||
assertEquals(10, result3.getInt("total")); | ||
} | ||
} |
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
Oops, something went wrong.