Skip to content

Commit

Permalink
Remove TextKeywordValue.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
  • Loading branch information
Yury-Fridlyand committed Jan 11, 2023
1 parent 735e9f7 commit 46f20ee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected OpenSearchDataType() {

@Override
public String typeName() {
if (type == null) {
if (exprCoreType != ExprCoreType.UNKNOWN || type == null) {
return exprCoreType.typeName();
}
return type.toString().toLowerCase();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,49 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.config.ExpressionConfig;
import org.opensearch.sql.opensearch.data.value.OpenSearchExprBinaryValue;
import org.opensearch.sql.opensearch.data.value.OpenSearchExprGeoPointValue;
import org.opensearch.sql.opensearch.data.value.OpenSearchExprIpValue;
import org.opensearch.sql.opensearch.data.value.OpenSearchExprTextKeywordValue;
import org.opensearch.sql.opensearch.data.value.OpenSearchExprTextValue;

public class OpenSearchDataTypeRecognitionTest {

private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository());

@ParameterizedTest
@ParameterizedTest(name = "{2}")
@MethodSource("types")
public void typeof(String expected, ExprValue value) {
public void typeof(String expected, ExprValue value, String testName) {
assertEquals(expected, typeofGetValue(value));
}

private static Stream<Arguments> types() {
// TODO: ARRAY and new types
return Stream.of(
Arguments.of("text", new OpenSearchExprTextValue("A")),
Arguments.of("binary", new OpenSearchExprBinaryValue("A")),
Arguments.of("ip", new OpenSearchExprIpValue("A")),
Arguments.of("text", new OpenSearchExprTextKeywordValue("A")),
Arguments.of("geo_point", new OpenSearchExprGeoPointValue(0d, 0d))
Arguments.of("text", new OpenSearchExprTextValue("A"), "text without fields"),
Arguments.of("binary", new OpenSearchExprBinaryValue("A"), "binary"),
Arguments.of("ip", new OpenSearchExprIpValue("A"), "ip"),
Arguments.of("text", new TestTextWithFieldValue("Hello World"), "text with fields"),
Arguments.of("geo_point", new OpenSearchExprGeoPointValue(0d, 0d), "geo point")
);
}

private String typeofGetValue(ExprValue input) {
return dsl.typeof(DSL.literal(input)).valueOf().stringValue();
}

static class TestTextWithFieldValue extends OpenSearchExprTextValue {
public TestTextWithFieldValue(String value) {
super(value);
}

@Override
public ExprType type() {
var type = OpenSearchDataType.of(OpenSearchDataType.Type.Text);
type.getFields().put("words", OpenSearchDataType.of(OpenSearchDataType.Type.Keyword));
return type;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public void constructText() {
assertEquals(new OpenSearchExprTextValue("text"),
constructFromObject("textV", "text"));

assertEquals(new OpenSearchExprTextKeywordValue("text"),
assertEquals(new OpenSearchExprTextValue("text"),
tupleValue("{\"textKeywordV\":\"text\"}").get("textKeywordV"));
assertEquals(new OpenSearchExprTextKeywordValue("text"),
assertEquals(new OpenSearchExprTextValue("text"),
constructFromObject("textKeywordV", "text"));
}

Expand Down

0 comments on commit 46f20ee

Please sign in to comment.