From dc48abef7125866880369997bd5d9d958568bc18 Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Wed, 23 Nov 2022 13:09:09 -0800 Subject: [PATCH 1/9] Added IT tests for text and keyword aggregations. Signed-off-by: MitchellGale-BitQuill --- .../sql/legacy/SQLIntegTestCase.java | 7 ++- .../org/opensearch/sql/legacy/TestUtils.java | 5 ++ .../opensearch/sql/legacy/TestsConstants.java | 1 + .../org/opensearch/sql/sql/TextTypeIT.java | 60 +++++++++++++++++++ .../text_keyword_index_mapping.json | 33 ++++++++++ .../test/resources/text_keyword_index.json | 16 +++++ 6 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java create mode 100644 integ-test/src/test/resources/indexDefinitions/text_keyword_index_mapping.json create mode 100644 integ-test/src/test/resources/text_keyword_index.json diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java index f03acbbbfd..9b1ee21c7d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java @@ -57,6 +57,7 @@ import static org.opensearch.sql.legacy.TestUtils.getPhraseIndexMapping; import static org.opensearch.sql.legacy.TestUtils.getResponseBody; import static org.opensearch.sql.legacy.TestUtils.getStringIndexMapping; +import static org.opensearch.sql.legacy.TestUtils.getDataTextKeywordIndexMapping; import static org.opensearch.sql.legacy.TestUtils.getWeblogsIndexMapping; import static org.opensearch.sql.legacy.TestUtils.isIndexExist; import static org.opensearch.sql.legacy.TestUtils.loadDataByRestClient; @@ -584,7 +585,11 @@ public enum Index { CALCS(TestsConstants.TEST_INDEX_CALCS, "calcs", getMappingFile("calcs_index_mappings.json"), - "src/test/resources/calcs.json"),; + "src/test/resources/calcs.json"), + TEXTKEYWORD(TestsConstants.TEST_INDEX_TEXTKEYWORD, + "textkeyword", + getMappingFile("text_keyword_index_mapping.json"), + "src/test/resources/text_keyword_index.json"); private final String name; private final String type; diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java b/integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java index 8f8ee4a70f..5ed447c4be 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java @@ -243,6 +243,11 @@ public static String getDataTypeNonnumericIndexMapping() { return getMappingFile(mappingFile); } + public static String getDataTextKeywordIndexMapping() { + String mappingFile = "text_keyword_index_mapping.json"; + return getMappingFile(mappingFile); + } + public static void loadBulk(Client client, String jsonPath, String defaultIndex) throws Exception { System.out.println(String.format("Loading file %s into opensearch cluster", jsonPath)); diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java b/integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java index a9f81c68fe..bfc6f5a681 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java @@ -53,6 +53,7 @@ public class TestsConstants { public final static String TEST_INDEX_BEER = TEST_INDEX + "_beer"; public final static String TEST_INDEX_NULL_MISSING = TEST_INDEX + "_null_missing"; public final static String TEST_INDEX_CALCS = TEST_INDEX + "_calcs"; + public final static String TEST_INDEX_TEXTKEYWORD = TEST_INDEX + "_textkeyword"; public final static String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; public final static String TS_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java new file mode 100644 index 0000000000..70e74ba96d --- /dev/null +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -0,0 +1,60 @@ + /* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.sql; + + import org.junit.Test; + import org.opensearch.sql.legacy.SQLIntegTestCase; + import java.io.IOException; + + + import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_TEXTKEYWORD; + import static org.opensearch.sql.util.MatcherUtils.schema; + import static org.opensearch.sql.util.MatcherUtils.verifySchema; + + public class TextTypeIT extends SQLIntegTestCase { + + + @Override + public void init() throws Exception { + super.init(); + loadIndex(Index.TEXTKEYWORD); + } + + @Test + public void textKeywordTest() throws IOException { + var result = executeJdbcRequest(String.format("select typeText from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeText", null, "text")); + } + + @Test + public void aggregateOnText() throws IOException { + var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY typeText", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("sum(int0)", null, "integer")); + } + + @Test + public void aggregateOnKeyword() throws IOException { + var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY typeKeyword", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("sum(int0)", null, "integer")); + } + + @Test + public void aggregateOnTextFieldData() throws IOException { + var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY typeTextFieldData", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("sum(int0)", null, "integer")); + } + + @Test + public void aggregateOnKeywordFieldData() throws IOException { + var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY typeKeywordFieldNoFieldData", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("sum(int0)", null, "integer")); + } + } diff --git a/integ-test/src/test/resources/indexDefinitions/text_keyword_index_mapping.json b/integ-test/src/test/resources/indexDefinitions/text_keyword_index_mapping.json new file mode 100644 index 0000000000..1f94ac7917 --- /dev/null +++ b/integ-test/src/test/resources/indexDefinitions/text_keyword_index_mapping.json @@ -0,0 +1,33 @@ +{ + "mappings" : { + "properties" : { + "typeKeyword" : { + "type" : "keyword" + }, + "typeText" : { + "type" : "text" + }, + "typeKeywordFieldNoFieldData" : { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } }, + "typeTextFieldData" : { + "type": "text", + "fielddata": true, + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "int0" : { + "type": "integer" + } + } + } +} diff --git a/integ-test/src/test/resources/text_keyword_index.json b/integ-test/src/test/resources/text_keyword_index.json new file mode 100644 index 0000000000..47b95d7566 --- /dev/null +++ b/integ-test/src/test/resources/text_keyword_index.json @@ -0,0 +1,16 @@ +{"index": {}} +{"typeKeyword": "key00", "typeText": "text00", "typeKeywordFieldData": "keyFD00", "typeTextFieldData": "textFD00", "int0": 0} +{"index": {}} +{"typeKeyword": "key01", "typeText": "text01", "typeKeywordFieldData": "keyFD01", "typeTextFieldData": "textFD01", "int0": 1} +{"index": {}} +{"typeKeyword": "key02", "typeText": "text02", "typeKeywordFieldData": "keyFD02", "typeTextFieldData": "textFD02", "int0": 2} +{"index": {}} +{"typeKeyword": "key03", "typeText": "text03", "typeKeywordFieldData": "keyFD03", "typeTextFieldData": "textFD03", "int0": 3} +{"index": {}} +{"typeKeyword": "key04", "typeText": "text04", "typeKeywordFieldData": "keyFD04", "typeTextFieldData": "textFD04", "int0": 4} +{"index": {}} +{"typeKeyword": "key05", "typeText": "text05", "typeKeywordFieldData": "keyFD05", "typeTextFieldData": "textFD05", "int0": 5} +{"index": {}} +{"typeKeyword": "key06", "typeText": "text06", "typeKeywordFieldData": "keyFD06", "typeTextFieldData": "textFD06", "int0": 6} +{"index": {}} +{"typeKeyword": "key07", "typeText": "text07", "typeKeywordFieldData": "keyFD07", "typeTextFieldData": "textFD07", "int0": 7} From 2a8fbacd599f31607935ba849ec4cf89527d9fb5 Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Wed, 23 Nov 2022 15:32:15 -0800 Subject: [PATCH 2/9] Added data for ignore_above and test with fielddata true but no field. Signed-off-by: MitchellGale-BitQuill --- .../org/opensearch/sql/sql/TextTypeIT.java | 7 +++++++ .../text_keyword_index_mapping.json | 8 ++++++-- .../src/test/resources/text_keyword_index.json | 18 +++++++++--------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java index 70e74ba96d..a6c2cb49dd 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -57,4 +57,11 @@ public void aggregateOnKeywordFieldData() throws IOException { verifySchema(result, schema("sum(int0)", null, "integer")); } + + @Test + public void aggregateOnTextAndFieldDataNoFields() throws IOException { + var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY textDataFieldNoFields", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("sum(int0)", null, "integer")); + } } diff --git a/integ-test/src/test/resources/indexDefinitions/text_keyword_index_mapping.json b/integ-test/src/test/resources/indexDefinitions/text_keyword_index_mapping.json index 1f94ac7917..1975a10bcc 100644 --- a/integ-test/src/test/resources/indexDefinitions/text_keyword_index_mapping.json +++ b/integ-test/src/test/resources/indexDefinitions/text_keyword_index_mapping.json @@ -12,7 +12,7 @@ "fields": { "keyword": { "type": "keyword", - "ignore_above": 256 + "ignore_above": 10 } } }, "typeTextFieldData" : { @@ -21,10 +21,14 @@ "fields": { "keyword": { "type": "keyword", - "ignore_above": 256 + "ignore_above": 10 } } }, + "textDataFieldNoFields" : { + "type": "text", + "fielddata": true + }, "int0" : { "type": "integer" } diff --git a/integ-test/src/test/resources/text_keyword_index.json b/integ-test/src/test/resources/text_keyword_index.json index 47b95d7566..06f2f766f3 100644 --- a/integ-test/src/test/resources/text_keyword_index.json +++ b/integ-test/src/test/resources/text_keyword_index.json @@ -1,16 +1,16 @@ {"index": {}} -{"typeKeyword": "key00", "typeText": "text00", "typeKeywordFieldData": "keyFD00", "typeTextFieldData": "textFD00", "int0": 0} +{"typeKeyword": "key00", "typeText": "text00", "typeKeywordFieldNoFieldData": "keyword00","typeTextFieldData": "keyFD00", "typeKeywordFieldData": "textFD00", "textDataFieldNoFields": "textFDNF00","int0": 0} {"index": {}} -{"typeKeyword": "key01", "typeText": "text01", "typeKeywordFieldData": "keyFD01", "typeTextFieldData": "textFD01", "int0": 1} +{"typeKeyword": "key01", "typeText": "text01", "typeKeywordFieldNoFieldData": "keyword01", "typeTextFieldData": "keyFD01", "typeTextFieldData": "textFD01OverTen", "textDataFieldNoFields": "textFDNF01", "int0": 1} +{"index": {},typeKeywordFieldData +{"typeKeyword": "key02", "typeText": "text02", "typeKeywordFieldNoFieldData": "keyword02", "typeTextFieldData": "keyFD02", "typeKeywordFieldData": "textFD02", "textDataFieldNoFields": "textFDNF02", "int0": 2} {"index": {}} -{"typeKeyword": "key02", "typeText": "text02", "typeKeywordFieldData": "keyFD02", "typeTextFieldData": "textFD02", "int0": 2} +{"typeKeyword": "key03", "typeText": "text03", "typeKeywordFieldNoFieldData": "keyword03", "typeTextFieldData": "keyFD03OverTen", "typeKeywordFieldData": "textFD03", "textDataFieldNoFields": "textFDNF03", "int0": 3} {"index": {}} -{"typeKeyword": "key03", "typeText": "text03", "typeKeywordFieldData": "keyFD03", "typeTextFieldData": "textFD03", "int0": 3} +{"typeKeyword": "key04", "typeText": "text04", "typeKeywordFieldNoFieldData": "keyword04", "typeTextFieldData": "keyFD04", "typeKeywordFieldData": "textFD04", "textDataFieldNoFields": "textFDNF04", "int0": 4} {"index": {}} -{"typeKeyword": "key04", "typeText": "text04", "typeKeywordFieldData": "keyFD04", "typeTextFieldData": "textFD04", "int0": 4} +{"typeKeyword": "key05", "typeText": "text05", "typeKeywordFieldNoFieldData": "keyword05", "typeTextFieldData": "keyFD05", "typeKeywordFieldData": "textFD0OverTen5", "textDataFieldNoFields": "textFDNF05", "int0": 5} {"index": {}} -{"typeKeyword": "key05", "typeText": "text05", "typeKeywordFieldData": "keyFD05", "typeTextFieldData": "textFD05", "int0": 5} +{"typeKeyword": "key06", "typeText": "text06", "typeKeywordFieldNoFieldData": "keyword06", "typeTextFieldData": "keyFD06OverTen", "typeKeywordFieldData": "textFD06", "textDataFieldNoFields": "textFDNF06", "int0": 6} {"index": {}} -{"typeKeyword": "key06", "typeText": "text06", "typeKeywordFieldData": "keyFD06", "typeTextFieldData": "textFD06", "int0": 6} -{"index": {}} -{"typeKeyword": "key07", "typeText": "text07", "typeKeywordFieldData": "keyFD07", "typeTextFieldData": "textFD07", "int0": 7} +{"typeKeyword": "key07", "typeText": "text07", "typeKeywordFieldNoFieldData": "keyword07", "typeTextFieldData": "keyFD07", "typeKeywordFieldData": "textFD07", "textDataFieldNoFields": "textFDNF07", "int0": 7} From 6be26aeb14ca89aab1eba57fe18e0822b066d455 Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Fri, 25 Nov 2022 13:06:11 -0800 Subject: [PATCH 3/9] Added test cases for wildcard, like substring, position, locate Signed-off-by: MitchellGale-BitQuill --- .../org/opensearch/sql/sql/TextTypeIT.java | 150 +++++++++++++++++- .../test/resources/text_keyword_index.json | 2 +- 2 files changed, 144 insertions(+), 8 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java index a6c2cb49dd..d3b47e703e 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -7,7 +7,6 @@ import org.junit.Test; import org.opensearch.sql.legacy.SQLIntegTestCase; - import java.io.IOException; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_TEXTKEYWORD; @@ -23,45 +22,182 @@ public void init() throws Exception { loadIndex(Index.TEXTKEYWORD); } + // Select + @Test - public void textKeywordTest() throws IOException { + public void textKeywordTest() { var result = executeJdbcRequest(String.format("select typeText from %s", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, schema("typeText", null, "text")); } @Test - public void aggregateOnText() throws IOException { + public void aggregateOnText() { var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY typeText", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, schema("sum(int0)", null, "integer")); } @Test - public void aggregateOnKeyword() throws IOException { + public void aggregateOnKeyword() { var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY typeKeyword", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, schema("sum(int0)", null, "integer")); } @Test - public void aggregateOnTextFieldData() throws IOException { + public void aggregateOnTextFieldData() { var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY typeTextFieldData", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, schema("sum(int0)", null, "integer")); } @Test - public void aggregateOnKeywordFieldData() throws IOException { + public void aggregateOnKeywordFieldData() { var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY typeKeywordFieldNoFieldData", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, schema("sum(int0)", null, "integer")); } @Test - public void aggregateOnTextAndFieldDataNoFields() throws IOException { + public void aggregateOnTextAndFieldDataNoFields() { var result = executeJdbcRequest(String.format("select sum(int0) from %s GROUP BY textDataFieldNoFields", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, schema("sum(int0)", null, "integer")); } + + // Where like + + @Test + public void whereLikeKeyword() { + executeJdbcRequest(String.format("select * from %s WHERE typeKeyword LIKE \\\"key*\\\"", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void whereLikeText() { + executeJdbcRequest(String.format("select * from %s WHERE typeText LIKE \\\"text*\\\"", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void whereLikeKeywordFieldNoFieldData() { + executeJdbcRequest(String.format("select * from %s WHERE typeKeywordFieldNoFieldData LIKE \\\"keyword*\\\"", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void whereLikeTextFieldData() { + executeJdbcRequest(String.format("select * from %s WHERE typeTextFieldData LIKE \\\"keyFD*\\\"", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void whereLiketextDataFieldNoFields() { + executeJdbcRequest(String.format("select * from %s WHERE textDataFieldNoFields LIKE \\\"textFDNF*\\\"", TEST_INDEX_TEXTKEYWORD)); + } + + // Wildcard + + @Test + public void whereWildcardKeyword() { + executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(typeKeyword, \\\"key*\\\")", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void whereWildcardText() { + executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(\\\"typeText\\\", \\\"text*\\\")", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void whereWildcardKeywordFieldNoFieldData() { + executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(\\\"typeKeywordFieldNoFieldData\\\", \\\"keyword*\\\")", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void whereWildcardTextFieldData() { + executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(\\\"typeTextFieldData\\\", \\\"keyFD*\\\")", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void whereWildcardtextDataFieldNoFields() { + executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(\\\"textDataFieldNoFields\\\", \\\"textFDNF*\\\")", TEST_INDEX_TEXTKEYWORD)); + } + + // Locate + + @Test + public void selectLocateKeyword() { + executeJdbcRequest(String.format("select typeKeyword LIKE \\\"key*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectLocateText() { + executeJdbcRequest(String.format("select typeText LIKE \\\"text*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectLocateTextKeywordFieldNoFieldData() { + executeJdbcRequest(String.format("select typeKeywordFieldNoFieldData LIKE \\\"keyword*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectLocateTypeTextFieldData() { + executeJdbcRequest(String.format("select typeTextFieldData LIKE \\\"keyFD*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectLocateTextDataFieldNoFields() { + executeJdbcRequest(String.format("select textDataFieldNoFields LIKE \\\"textFDNF*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + } + + // Position + + @Test + public void selectPositionKeyword() { + executeJdbcRequest(String.format("select POSITION(key IN typeKeyword) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectPositionText() { + executeJdbcRequest(String.format("select POSITION(text IN typeText) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectPositionTextKeywordFieldNoFieldData() { + executeJdbcRequest(String.format("select POSITION(keyword IN typeKeywordFieldNoFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectPositionTypeTextFieldData() { + executeJdbcRequest(String.format("select POSITION(keyFD IN typeTextFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectPositionTextDataFieldNoFields() { + executeJdbcRequest(String.format("select POSITION(textDataFieldNoFields) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + // Substring + + @Test + public void selectSubstringKeyword() { + executeJdbcRequest(String.format("select SUBSTRING(typeKeyword, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectSubstringText() { + executeJdbcRequest(String.format("select SUBSTRING(typeText, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectSubstringTextKeywordFieldNoFieldData() { + executeJdbcRequest(String.format("select SUBSTRING(typeKeywordFieldNoFieldData, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectSubstringTypeTextFieldData() { + executeJdbcRequest(String.format("select SUBSTRING(typeTextFieldData, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + } + + @Test + public void selectSubstringTextDataFieldNoFields() { + executeJdbcRequest(String.format("select SUBSTRING(textDataFieldNoFields, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + } } diff --git a/integ-test/src/test/resources/text_keyword_index.json b/integ-test/src/test/resources/text_keyword_index.json index 06f2f766f3..33e4e6702c 100644 --- a/integ-test/src/test/resources/text_keyword_index.json +++ b/integ-test/src/test/resources/text_keyword_index.json @@ -2,7 +2,7 @@ {"typeKeyword": "key00", "typeText": "text00", "typeKeywordFieldNoFieldData": "keyword00","typeTextFieldData": "keyFD00", "typeKeywordFieldData": "textFD00", "textDataFieldNoFields": "textFDNF00","int0": 0} {"index": {}} {"typeKeyword": "key01", "typeText": "text01", "typeKeywordFieldNoFieldData": "keyword01", "typeTextFieldData": "keyFD01", "typeTextFieldData": "textFD01OverTen", "textDataFieldNoFields": "textFDNF01", "int0": 1} -{"index": {},typeKeywordFieldData +{"index": {}} {"typeKeyword": "key02", "typeText": "text02", "typeKeywordFieldNoFieldData": "keyword02", "typeTextFieldData": "keyFD02", "typeKeywordFieldData": "textFD02", "textDataFieldNoFields": "textFDNF02", "int0": 2} {"index": {}} {"typeKeyword": "key03", "typeText": "text03", "typeKeywordFieldNoFieldData": "keyword03", "typeTextFieldData": "keyFD03OverTen", "typeKeywordFieldData": "textFD03", "textDataFieldNoFields": "textFDNF03", "int0": 3} From 925a5eeebc902fec3a1157c1085157c9dad8602b Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Fri, 25 Nov 2022 15:32:08 -0800 Subject: [PATCH 4/9] Fixed formatting issue in data Signed-off-by: MitchellGale-BitQuill --- .../java/org/opensearch/sql/sql/TextTypeIT.java | 4 ++-- .../src/test/resources/text_keyword_index.json | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java index d3b47e703e..fbab48bf25 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -26,9 +26,9 @@ public void init() throws Exception { @Test public void textKeywordTest() { - var result = executeJdbcRequest(String.format("select typeText from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeKeyword from %s", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, - schema("typeText", null, "text")); + schema("typeKeyword", null, "keyword")); } @Test diff --git a/integ-test/src/test/resources/text_keyword_index.json b/integ-test/src/test/resources/text_keyword_index.json index 33e4e6702c..d09dfd01e2 100644 --- a/integ-test/src/test/resources/text_keyword_index.json +++ b/integ-test/src/test/resources/text_keyword_index.json @@ -1,16 +1,16 @@ -{"index": {}} +{"index": {"_id":"1"}} {"typeKeyword": "key00", "typeText": "text00", "typeKeywordFieldNoFieldData": "keyword00","typeTextFieldData": "keyFD00", "typeKeywordFieldData": "textFD00", "textDataFieldNoFields": "textFDNF00","int0": 0} -{"index": {}} +{"index": {"_id":"2"}} {"typeKeyword": "key01", "typeText": "text01", "typeKeywordFieldNoFieldData": "keyword01", "typeTextFieldData": "keyFD01", "typeTextFieldData": "textFD01OverTen", "textDataFieldNoFields": "textFDNF01", "int0": 1} -{"index": {}} +{"index": {"_id":"3"}} {"typeKeyword": "key02", "typeText": "text02", "typeKeywordFieldNoFieldData": "keyword02", "typeTextFieldData": "keyFD02", "typeKeywordFieldData": "textFD02", "textDataFieldNoFields": "textFDNF02", "int0": 2} -{"index": {}} +{"index": {"_id":"4"}} {"typeKeyword": "key03", "typeText": "text03", "typeKeywordFieldNoFieldData": "keyword03", "typeTextFieldData": "keyFD03OverTen", "typeKeywordFieldData": "textFD03", "textDataFieldNoFields": "textFDNF03", "int0": 3} -{"index": {}} +{"index": {"_id":"5"}} {"typeKeyword": "key04", "typeText": "text04", "typeKeywordFieldNoFieldData": "keyword04", "typeTextFieldData": "keyFD04", "typeKeywordFieldData": "textFD04", "textDataFieldNoFields": "textFDNF04", "int0": 4} -{"index": {}} +{"index": {"_id":"6"}} {"typeKeyword": "key05", "typeText": "text05", "typeKeywordFieldNoFieldData": "keyword05", "typeTextFieldData": "keyFD05", "typeKeywordFieldData": "textFD0OverTen5", "textDataFieldNoFields": "textFDNF05", "int0": 5} -{"index": {}} +{"index": {"_id":"7"}} {"typeKeyword": "key06", "typeText": "text06", "typeKeywordFieldNoFieldData": "keyword06", "typeTextFieldData": "keyFD06OverTen", "typeKeywordFieldData": "textFD06", "textDataFieldNoFields": "textFDNF06", "int0": 6} -{"index": {}} +{"index": {"_id":"8"}} {"typeKeyword": "key07", "typeText": "text07", "typeKeywordFieldNoFieldData": "keyword07", "typeTextFieldData": "keyFD07", "typeKeywordFieldData": "textFD07", "textDataFieldNoFields": "textFDNF07", "int0": 7} From 56430399b72d0dcb0ec879734e4c5aa3e711a3da Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Fri, 25 Nov 2022 15:42:56 -0800 Subject: [PATCH 5/9] Fixed issue with selectPositionTextDataFieldNoFields Signed-off-by: MitchellGale-BitQuill --- integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java index fbab48bf25..c075f8591d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -171,7 +171,7 @@ public void selectPositionTypeTextFieldData() { @Test public void selectPositionTextDataFieldNoFields() { - executeJdbcRequest(String.format("select POSITION(textDataFieldNoFields) from %s", TEST_INDEX_TEXTKEYWORD)); + executeJdbcRequest(String.format("select POSITION(textFDNF IN textDataFieldNoFields) from %s", TEST_INDEX_TEXTKEYWORD)); } // Substring From 718210d7ee01d82da1d3b3d0f24c560c01f1ab74 Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Mon, 28 Nov 2022 13:56:30 -0800 Subject: [PATCH 6/9] Fixed issue with data duplication. Signed-off-by: MitchellGale-BitQuill --- .../src/test/java/org/opensearch/sql/sql/TextTypeIT.java | 4 ++-- integ-test/src/test/resources/text_keyword_index.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java index c075f8591d..ba3ab19fe8 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -156,7 +156,7 @@ public void selectPositionKeyword() { @Test public void selectPositionText() { - executeJdbcRequest(String.format("select POSITION(text IN typeText) from %s", TEST_INDEX_TEXTKEYWORD)); + executeJdbcRequest(String.format("select POSITION(\\\"text\\\" IN typeText) from %s", TEST_INDEX_TEXTKEYWORD)); } @Test @@ -166,7 +166,7 @@ public void selectPositionTextKeywordFieldNoFieldData() { @Test public void selectPositionTypeTextFieldData() { - executeJdbcRequest(String.format("select POSITION(keyFD IN typeTextFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + executeJdbcRequest(String.format("select POSITION(\\\"keyFD\\\" IN typeTextFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); } @Test diff --git a/integ-test/src/test/resources/text_keyword_index.json b/integ-test/src/test/resources/text_keyword_index.json index d09dfd01e2..b9cb83d438 100644 --- a/integ-test/src/test/resources/text_keyword_index.json +++ b/integ-test/src/test/resources/text_keyword_index.json @@ -1,7 +1,7 @@ {"index": {"_id":"1"}} {"typeKeyword": "key00", "typeText": "text00", "typeKeywordFieldNoFieldData": "keyword00","typeTextFieldData": "keyFD00", "typeKeywordFieldData": "textFD00", "textDataFieldNoFields": "textFDNF00","int0": 0} {"index": {"_id":"2"}} -{"typeKeyword": "key01", "typeText": "text01", "typeKeywordFieldNoFieldData": "keyword01", "typeTextFieldData": "keyFD01", "typeTextFieldData": "textFD01OverTen", "textDataFieldNoFields": "textFDNF01", "int0": 1} +{"typeKeyword": "key01", "typeText": "text01", "typeKeywordFieldNoFieldData": "keyword01", "typeTextFieldData": "keyFD01", "typeKeywordFieldData": "textFD01OverTen", "textDataFieldNoFields": "textFDNF01", "int0": 1} {"index": {"_id":"3"}} {"typeKeyword": "key02", "typeText": "text02", "typeKeywordFieldNoFieldData": "keyword02", "typeTextFieldData": "keyFD02", "typeKeywordFieldData": "textFD02", "textDataFieldNoFields": "textFDNF02", "int0": 2} {"index": {"_id":"4"}} From 924f592e8ec931c9b7eade9935ca0655aad0529c Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Wed, 30 Nov 2022 10:42:30 -0800 Subject: [PATCH 7/9] Fixed mapping Signed-off-by: MitchellGale-BitQuill --- .../org/opensearch/sql/sql/TextTypeIT.java | 127 ++++++++++++++---- .../calcs_index_mappings.json | 2 +- 2 files changed, 100 insertions(+), 29 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java index ba3ab19fe8..92da377334 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -8,6 +8,7 @@ import org.junit.Test; import org.opensearch.sql.legacy.SQLIntegTestCase; + import java.io.IOException; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_TEXTKEYWORD; import static org.opensearch.sql.util.MatcherUtils.schema; @@ -20,6 +21,8 @@ public class TextTypeIT extends SQLIntegTestCase { public void init() throws Exception { super.init(); loadIndex(Index.TEXTKEYWORD); + loadIndex(Index.CALCS); + } // Select @@ -70,134 +73,202 @@ public void aggregateOnTextAndFieldDataNoFields() { @Test public void whereLikeKeyword() { - executeJdbcRequest(String.format("select * from %s WHERE typeKeyword LIKE \\\"key*\\\"", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeKeyword from %s WHERE typeKeyword LIKE \\\"key*\\\"", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeKeyword", null, "keyword")); } @Test public void whereLikeText() { - executeJdbcRequest(String.format("select * from %s WHERE typeText LIKE \\\"text*\\\"", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeText from %s WHERE typeText LIKE \\\"text*\\\"", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeText", null, "text")); } @Test public void whereLikeKeywordFieldNoFieldData() { - executeJdbcRequest(String.format("select * from %s WHERE typeKeywordFieldNoFieldData LIKE \\\"keyword*\\\"", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeKeywordFieldNoFieldData from %s WHERE typeKeywordFieldNoFieldData LIKE \\\"keyword*\\\"", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeKeywordFieldNoFieldData", null, "text")); } @Test public void whereLikeTextFieldData() { - executeJdbcRequest(String.format("select * from %s WHERE typeTextFieldData LIKE \\\"keyFD*\\\"", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeTextFieldData from %s WHERE typeTextFieldData LIKE \\\"keyFD*\\\"", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeTextFieldData", null, "text")); } @Test public void whereLiketextDataFieldNoFields() { - executeJdbcRequest(String.format("select * from %s WHERE textDataFieldNoFields LIKE \\\"textFDNF*\\\"", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select textDataFieldNoFields from %s WHERE textDataFieldNoFields LIKE \\\"textFDNF*\\\"", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("textDataFieldNoFields", null, "text")); } // Wildcard @Test public void whereWildcardKeyword() { - executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(typeKeyword, \\\"key*\\\")", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeKeyword from %s WHERE wildcard_query(typeKeyword, \\\"key*\\\")", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeKeyword", null, "keyword")); } @Test public void whereWildcardText() { - executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(\\\"typeText\\\", \\\"text*\\\")", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeText from %s WHERE wildcard_query(\\\"typeText\\\", \\\"text*\\\")", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeText", null, "text")); } @Test public void whereWildcardKeywordFieldNoFieldData() { - executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(\\\"typeKeywordFieldNoFieldData\\\", \\\"keyword*\\\")", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeKeywordFieldNoFieldData from %s WHERE wildcard_query(\\\"typeKeywordFieldNoFieldData\\\", \\\"keyword*\\\")", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeKeywordFieldNoFieldData", null, "text")); } @Test public void whereWildcardTextFieldData() { - executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(\\\"typeTextFieldData\\\", \\\"keyFD*\\\")", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select typeTextFieldData from %s WHERE wildcard_query(\\\"typeTextFieldData\\\", \\\"keyFD*\\\")", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeTextFieldData", null, "text")); } @Test public void whereWildcardtextDataFieldNoFields() { - executeJdbcRequest(String.format("select * from %s WHERE wildcard_query(\\\"textDataFieldNoFields\\\", \\\"textFDNF*\\\")", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select textDataFieldNoFields from %s WHERE wildcard_query(\\\"textDataFieldNoFields\\\", \\\"textFDNF*\\\")", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("textDataFieldNoFields", null, "text")); } // Locate @Test public void selectLocateKeyword() { - executeJdbcRequest(String.format("select typeKeyword LIKE \\\"key*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select locate(\\\"key*\\\", typeKeyword) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("locate(\\\"key*\\\", typeKeyword)", null, "integer")); } @Test public void selectLocateText() { - executeJdbcRequest(String.format("select typeText LIKE \\\"text*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select locate(\\\"text*\\\", typeText) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("locate(\\\"text*\\\", typeText)", null, "integer")); } @Test public void selectLocateTextKeywordFieldNoFieldData() { - executeJdbcRequest(String.format("select typeKeywordFieldNoFieldData LIKE \\\"keyword*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select locate(\\\"keyword*\\\", typeKeywordFieldNoFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("locate(\\\"keyword*\\\", typeKeywordFieldNoFieldData)", null, "integer")); } @Test public void selectLocateTypeTextFieldData() { - executeJdbcRequest(String.format("select typeTextFieldData LIKE \\\"keyFD*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select locate(\\\"keyFD*\\\", typeTextFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("locate(\\\"keyFD*\\\", typeTextFieldData)", null, "integer")); } @Test public void selectLocateTextDataFieldNoFields() { - executeJdbcRequest(String.format("select textDataFieldNoFields LIKE \\\"textFDNF*\\\" from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select locate(\\\"textFDNF*\\\", textDataFieldNoFields) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("locate(\\\"textFDNF*\\\", textDataFieldNoFields)", null, "integer")); } // Position @Test public void selectPositionKeyword() { - executeJdbcRequest(String.format("select POSITION(key IN typeKeyword) from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select POSITION(\\\"key\\\" IN typeKeyword) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("LOCATE('key', typeKeyword)", null, "double")); } @Test - public void selectPositionText() { - executeJdbcRequest(String.format("select POSITION(\\\"text\\\" IN typeText) from %s", TEST_INDEX_TEXTKEYWORD)); + public void selectPositionText() throws IOException { + var result = executeQuery(String.format("select POSITION(\\\"text\\\" IN typeText) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("typeText", null, "double")); +// //assertFalse(result.has("error")); +// if(result.has("error")) { +// fail(result.optJSONObject("error").getString("reason") + "\n" + result.optJSONObject("error").getString("details")); +// } else { +// assert(true); +// } } @Test public void selectPositionTextKeywordFieldNoFieldData() { - executeJdbcRequest(String.format("select POSITION(keyword IN typeKeywordFieldNoFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select POSITION(\\\"keyword\\\" IN typeKeywordFieldNoFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("LOCATE('keyword', typeKeywordFieldNoFieldData)", null, "double")); } @Test - public void selectPositionTypeTextFieldData() { - executeJdbcRequest(String.format("select POSITION(\\\"keyFD\\\" IN typeTextFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + public void selectPositionTypeTextFieldData() throws IOException { + var result = executeQuery(String.format("select POSITION(\\\"keyFD\\\" IN typeTextFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("LOCATE('keyFD', typeTextFieldData)", null, "double")); } @Test public void selectPositionTextDataFieldNoFields() { - executeJdbcRequest(String.format("select POSITION(textFDNF IN textDataFieldNoFields) from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select POSITION(\\\"textFDNF\\\" IN textDataFieldNoFields) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("LOCATE('textFDNF', textDataFieldNoFields)", null, "double")); } // Substring @Test public void selectSubstringKeyword() { - executeJdbcRequest(String.format("select SUBSTRING(typeKeyword, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select SUBSTRING(typeKeyword, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("SUBSTRING(typeKeyword, 1, 1)", null, "keyword")); } @Test public void selectSubstringText() { - executeJdbcRequest(String.format("select SUBSTRING(typeText, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select SUBSTRING(typeText, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("SUBSTRING(typeText, 1, 1)", null, "keyword")); } @Test public void selectSubstringTextKeywordFieldNoFieldData() { - executeJdbcRequest(String.format("select SUBSTRING(typeKeywordFieldNoFieldData, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select SUBSTRING(typeKeywordFieldNoFieldData, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("SUBSTRING(typeKeywordFieldNoFieldData, 1, 1)", null, "keyword")); } @Test public void selectSubstringTypeTextFieldData() { - executeJdbcRequest(String.format("select SUBSTRING(typeTextFieldData, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + var result = executeJdbcRequest(String.format("select SUBSTRING(typeTextFieldData, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("SUBSTRING(typeTextFieldData, 1, 1)", null, "keyword")); } @Test public void selectSubstringTextDataFieldNoFields() { - executeJdbcRequest(String.format("select SUBSTRING(textDataFieldNoFields, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); - } + var result = executeJdbcRequest(String.format("select SUBSTRING(textDataFieldNoFields, 1, 1) from %s", TEST_INDEX_TEXTKEYWORD)); + verifySchema(result, + schema("SUBSTRING(textDataFieldNoFields, 1, 1)", null, "keyword")); + } + +// protected JSONObject executeQuery(String query) throws IOException { +// Request request = new Request("POST", QUERY_API_ENDPOINT); +// request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query)); +// +// RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder(); +// restOptionsBuilder.addHeader("Content-Type", "application/json"); +// request.setOptions(restOptionsBuilder); +// +// Response response = client().performRequest(request); +// return new JSONObject(getResponseBody(response)); +// } } diff --git a/integ-test/src/test/resources/indexDefinitions/calcs_index_mappings.json b/integ-test/src/test/resources/indexDefinitions/calcs_index_mappings.json index 08a88a9d32..84bad2a0a0 100644 --- a/integ-test/src/test/resources/indexDefinitions/calcs_index_mappings.json +++ b/integ-test/src/test/resources/indexDefinitions/calcs_index_mappings.json @@ -20,7 +20,7 @@ "type" : "double" }, "str0" : { - "type" : "keyword" + "type" : "integer" }, "str1" : { "type" : "keyword" From 3e4317d0b20d9be0ec175749ff0fdf8bf4eb9b50 Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Tue, 13 Dec 2022 11:53:23 -0800 Subject: [PATCH 8/9] Fixed quote issue. Signed-off-by: MitchellGale-BitQuill --- .../java/org/opensearch/sql/sql/TextTypeIT.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java index 92da377334..c96da3cdd1 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -149,35 +149,35 @@ public void whereWildcardtextDataFieldNoFields() { public void selectLocateKeyword() { var result = executeJdbcRequest(String.format("select locate(\\\"key*\\\", typeKeyword) from %s", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, - schema("locate(\\\"key*\\\", typeKeyword)", null, "integer")); + schema("locate(\"key*\", typeKeyword)", null, "integer")); } @Test public void selectLocateText() { var result = executeJdbcRequest(String.format("select locate(\\\"text*\\\", typeText) from %s", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, - schema("locate(\\\"text*\\\", typeText)", null, "integer")); + schema("locate(\"text*\", typeText)", null, "integer")); } @Test public void selectLocateTextKeywordFieldNoFieldData() { var result = executeJdbcRequest(String.format("select locate(\\\"keyword*\\\", typeKeywordFieldNoFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, - schema("locate(\\\"keyword*\\\", typeKeywordFieldNoFieldData)", null, "integer")); + schema("locate(\"keyword*\", typeKeywordFieldNoFieldData)", null, "integer")); } @Test public void selectLocateTypeTextFieldData() { var result = executeJdbcRequest(String.format("select locate(\\\"keyFD*\\\", typeTextFieldData) from %s", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, - schema("locate(\\\"keyFD*\\\", typeTextFieldData)", null, "integer")); + schema("locate(\"keyFD*\", typeTextFieldData)", null, "integer")); } @Test public void selectLocateTextDataFieldNoFields() { var result = executeJdbcRequest(String.format("select locate(\\\"textFDNF*\\\", textDataFieldNoFields) from %s", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, - schema("locate(\\\"textFDNF*\\\", textDataFieldNoFields)", null, "integer")); + schema("locate(\"textFDNF*\", textDataFieldNoFields)", null, "integer")); } // Position @@ -194,11 +194,7 @@ public void selectPositionText() throws IOException { var result = executeQuery(String.format("select POSITION(\\\"text\\\" IN typeText) from %s", TEST_INDEX_TEXTKEYWORD)); verifySchema(result, schema("typeText", null, "double")); -// //assertFalse(result.has("error")); -// if(result.has("error")) { -// fail(result.optJSONObject("error").getString("reason") + "\n" + result.optJSONObject("error").getString("details")); -// } else { -// assert(true); + // } } From 0222df6c46908d4373607d06de23d5748c8fb7bd Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Tue, 20 Dec 2022 14:43:44 -0800 Subject: [PATCH 9/9] Removed comment Signed-off-by: MitchellGale-BitQuill --- .../test/java/org/opensearch/sql/sql/TextTypeIT.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java index c96da3cdd1..881eb02420 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java @@ -255,16 +255,4 @@ public void selectSubstringTextDataFieldNoFields() { verifySchema(result, schema("SUBSTRING(textDataFieldNoFields, 1, 1)", null, "keyword")); } - -// protected JSONObject executeQuery(String query) throws IOException { -// Request request = new Request("POST", QUERY_API_ENDPOINT); -// request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query)); -// -// RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder(); -// restOptionsBuilder.addHeader("Content-Type", "application/json"); -// request.setOptions(restOptionsBuilder); -// -// Response response = client().performRequest(request); -// return new JSONObject(getResponseBody(response)); -// } }