Skip to content

Commit

Permalink
Fixed mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellGale committed Nov 30, 2022
1 parent 412ba1d commit 005c48e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 29 deletions.
127 changes: 99 additions & 28 deletions integ-test/src/test/java/org/opensearch/sql/sql/TextTypeIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,8 @@ public class TextTypeIT extends SQLIntegTestCase {
public void init() throws Exception {
super.init();
loadIndex(Index.TEXTKEYWORD);
loadIndex(Index.CALCS);

}

// Select
Expand Down Expand Up @@ -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));
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"type" : "double"
},
"str0" : {
"type" : "keyword"
"type" : "integer"
},
"str1" : {
"type" : "keyword"
Expand Down

0 comments on commit 005c48e

Please sign in to comment.