diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQuery.java index 36ebb92253..26ef56e576 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQuery.java @@ -215,10 +215,7 @@ private ExprValue cast(FunctionExpression castFunction, ReferenceExpression ref) .put( BuiltinFunctionName.CAST_TO_IP.getName(), (expr, ref) -> { - ExprValue value = expr.valueOf(); - return value.type().equals(ExprCoreType.IP) - ? value - : new ExprIpValue(value.stringValue()); + return new ExprIpValue(expr.valueOf().stringValue()); }) .put( BuiltinFunctionName.CAST_TO_DATE.getName(), diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/RangeQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/RangeQueryTest.java index 2f5482171d..55272d4cd7 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/RangeQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/RangeQueryTest.java @@ -85,8 +85,8 @@ void test_date_has_format() { } @Test - void test_non_date_field_type() { - String dateString = "2021-11-08"; + void test_string_field_type() { + String dateString = "STRING"; OpenSearchDateType dateType = OpenSearchDateType.of(STRING); ExprValue literal = ExprValueUtils.stringValue(dateString); assertNotNull(new RangeQuery(Comparison.LT).doBuild("string_value", dateType, literal));