From ba5b851230d47a0626201b2441400b147cfdf901 Mon Sep 17 00:00:00 2001 From: acarbonetto Date: Mon, 21 Aug 2023 18:12:07 -0700 Subject: [PATCH] Update to use OpenSearchDSL Signed-off-by: acarbonetto --- .../org/opensearch/sql/expression/DSL.java | 52 -- .../function/BuiltinFunctionRepository.java | 5 +- .../OpenSearchDataSourceMetadataStorage.java | 3 + .../opensearch/expression/OpenSearchDSL.java | 782 +----------------- .../request/OpenSearchRequestBuilderTest.java | 11 +- .../OpenSearchIndexScanOptimizationTest.java | 21 +- .../script/filter/FilterQueryBuilderTest.java | 121 +-- .../script/sort/SortQueryBuilderTest.java | 11 +- 8 files changed, 91 insertions(+), 915 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/DSL.java b/core/src/main/java/org/opensearch/sql/expression/DSL.java index 2ccc96b009..2131f7248e 100644 --- a/core/src/main/java/org/opensearch/sql/expression/DSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/DSL.java @@ -615,10 +615,6 @@ public static FunctionExpression xor(Expression... expressions) { return compile(FunctionProperties.None, BuiltinFunctionName.XOR, expressions); } - public static FunctionExpression nested(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.NESTED, expressions); - } - public static FunctionExpression not(Expression... expressions) { return compile(FunctionProperties.None, BuiltinFunctionName.NOT, expressions); } @@ -827,54 +823,6 @@ public static FunctionExpression typeof(Expression value) { return compile(FunctionProperties.None, BuiltinFunctionName.TYPEOF, value); } - public static FunctionExpression match(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.MATCH, args); - } - - public static FunctionExpression match_phrase(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.MATCH_PHRASE, args); - } - - public static FunctionExpression match_phrase_prefix(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.MATCH_PHRASE_PREFIX, args); - } - - public static FunctionExpression multi_match(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.MULTI_MATCH, args); - } - - public static FunctionExpression simple_query_string(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.SIMPLE_QUERY_STRING, args); - } - - public static FunctionExpression query(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.QUERY, args); - } - - public static FunctionExpression query_string(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.QUERY_STRING, args); - } - - public static FunctionExpression match_bool_prefix(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.MATCH_BOOL_PREFIX, args); - } - - public static FunctionExpression wildcard_query(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.WILDCARD_QUERY, args); - } - - public static FunctionExpression score(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.SCORE, args); - } - - public static FunctionExpression scorequery(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.SCOREQUERY, args); - } - - public static FunctionExpression score_query(Expression... args) { - return compile(FunctionProperties.None, BuiltinFunctionName.SCORE_QUERY, args); - } - public static FunctionExpression now(FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.NOW, args); } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java b/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java index b651dcb88e..6d65172734 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java @@ -91,8 +91,9 @@ public static synchronized BuiltinFunctionRepository getInstance(DataSourceServi for (DataSourceMetadata metadata : dataSourceService.getDataSourceMetadata(true)) { dataSourceService .getDataSource(metadata.getName()) - .getStorageEngine().getFunctions(). - forEach(repository::register); + .getStorageEngine() + .getFunctions() + .forEach(repository::register); } } instance.put(dataSourceServiceHash, repository); diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java index 73eb297fea..0ee5b82bca 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java @@ -80,6 +80,9 @@ public OpenSearchDataSourceMetadataStorage( @Override public List getDataSourceMetadata() { + if (this.clusterService.state() == null) { + return Collections.emptyList(); + } if (!this.clusterService.state().routingTable().hasIndex(DATASOURCE_INDEX_NAME)) { createDataSourcesIndex(); return Collections.emptyList(); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/expression/OpenSearchDSL.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/expression/OpenSearchDSL.java index cfa3cba9b8..a9da94ad03 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/expression/OpenSearchDSL.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/expression/OpenSearchDSL.java @@ -153,710 +153,10 @@ public static NamedArgumentExpression namedArgument(String name, String value) { return namedArgument(name, literal(value)); } - public static GrokExpression grok( - Expression sourceField, Expression pattern, Expression identifier) { - return new GrokExpression(sourceField, pattern, identifier); - } - - public static RegexExpression regex( - Expression sourceField, Expression pattern, Expression identifier) { - return new RegexExpression(sourceField, pattern, identifier); - } - - public static PatternsExpression patterns( - Expression sourceField, Expression pattern, Expression identifier) { - return new PatternsExpression(sourceField, pattern, identifier); - } - - public static SpanExpression span(Expression field, Expression value, String unit) { - return new SpanExpression(field, value, SpanUnit.of(unit)); - } - - public static FunctionExpression abs(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ABS, expressions); - } - - public static FunctionExpression add(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ADD, expressions); - } - - public static FunctionExpression addFunction(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ADDFUNCTION, expressions); - } - - public static FunctionExpression ceil(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.CEIL, expressions); - } - - public static FunctionExpression ceiling(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.CEILING, expressions); - } - - public static FunctionExpression conv(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.CONV, expressions); - } - - public static FunctionExpression crc32(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.CRC32, expressions); - } - - public static FunctionExpression divide(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DIVIDE, expressions); - } - - public static FunctionExpression divideFunction(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DIVIDEFUNCTION, expressions); - } - - public static FunctionExpression euler(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.E, expressions); - } - - public static FunctionExpression exp(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.EXP, expressions); - } - - public static FunctionExpression expm1(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.EXPM1, expressions); - } - - public static FunctionExpression floor(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.FLOOR, expressions); - } - - public static FunctionExpression ln(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LN, expressions); - } - - public static FunctionExpression log(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LOG, expressions); - } - - public static FunctionExpression log10(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LOG10, expressions); - } - - public static FunctionExpression log2(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LOG2, expressions); - } - - public static FunctionExpression mod(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MOD, expressions); - } - - public static FunctionExpression modulus(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MODULUS, expressions); - } - - public static FunctionExpression modulusFunction(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MODULUSFUNCTION, expressions); - } - - public static FunctionExpression multiply(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MULTIPLY, expressions); - } - - public static FunctionExpression multiplyFunction(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MULTIPLYFUNCTION, expressions); - } - - public static FunctionExpression pi(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.PI, expressions); - } - - public static FunctionExpression pow(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.POW, expressions); - } - - public static FunctionExpression power(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.POWER, expressions); - } - - public static FunctionExpression rand(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.RAND, expressions); - } - - public static FunctionExpression rint(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.RINT, expressions); - } - - public static FunctionExpression round(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ROUND, expressions); - } - - public static FunctionExpression sign(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SIGN, expressions); - } - - public static FunctionExpression signum(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SIGNUM, expressions); - } - - public static FunctionExpression sinh(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SINH, expressions); - } - - public static FunctionExpression sqrt(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SQRT, expressions); - } - - public static FunctionExpression cbrt(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.CBRT, expressions); - } - - public static FunctionExpression position(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.POSITION, expressions); - } - - public static FunctionExpression truncate(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.TRUNCATE, expressions); - } - - public static FunctionExpression acos(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ACOS, expressions); - } - - public static FunctionExpression asin(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ASIN, expressions); - } - - public static FunctionExpression atan(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ATAN, expressions); - } - - public static FunctionExpression atan2(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ATAN2, expressions); - } - - public static FunctionExpression cos(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.COS, expressions); - } - - public static FunctionExpression cosh(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.COSH, expressions); - } - - public static FunctionExpression cot(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.COT, expressions); - } - - public static FunctionExpression degrees(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DEGREES, expressions); - } - - public static FunctionExpression radians(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.RADIANS, expressions); - } - - public static FunctionExpression sin(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SIN, expressions); - } - - public static FunctionExpression subtract(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SUBTRACT, expressions); - } - - public static FunctionExpression subtractFunction(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SUBTRACTFUNCTION, expressions); - } - - public static FunctionExpression tan(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.TAN, expressions); - } - - public static FunctionExpression convert_tz(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.CONVERT_TZ, expressions); - } - - public static FunctionExpression date(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DATE, expressions); - } - - public static FunctionExpression datetime(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DATETIME, expressions); - } - - public static FunctionExpression date_add(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DATE_ADD, expressions); - } - - public static FunctionExpression day(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DAY, expressions); - } - - public static FunctionExpression dayname(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DAYNAME, expressions); - } - - public static FunctionExpression dayofmonth( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.DAYOFMONTH, expressions); - } - - public static FunctionExpression dayofweek( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.DAYOFWEEK, expressions); - } - - public static FunctionExpression dayofyear(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.DAYOFYEAR, expressions); - } - - public static FunctionExpression day_of_month( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.DAY_OF_MONTH, expressions); - } - - public static FunctionExpression day_of_year( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.DAY_OF_YEAR, expressions); - } - - public static FunctionExpression day_of_week( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.DAY_OF_WEEK, expressions); - } - - public static FunctionExpression extract( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.EXTRACT, expressions); - } - - public static FunctionExpression extract(Expression... expressions) { - return extract(FunctionProperties.None, expressions); - } - - public static FunctionExpression from_days(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.FROM_DAYS, expressions); - } - - public static FunctionExpression get_format(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.GET_FORMAT, expressions); - } - - public static FunctionExpression hour(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.HOUR, expressions); - } - - public static FunctionExpression hour_of_day(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.HOUR_OF_DAY, expressions); - } - - public static FunctionExpression last_day( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.LAST_DAY, expressions); - } - - public static FunctionExpression microsecond(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MICROSECOND, expressions); - } - - public static FunctionExpression minute(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MINUTE, expressions); - } - - public static FunctionExpression minute_of_day(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MINUTE_OF_DAY, expressions); - } - - public static FunctionExpression minute_of_hour(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MINUTE_OF_HOUR, expressions); - } - - public static FunctionExpression month(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MONTH, expressions); - } - - public static FunctionExpression month_of_year( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.MONTH_OF_YEAR, expressions); - } - - public static FunctionExpression monthname(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.MONTHNAME, expressions); - } - - public static FunctionExpression quarter(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.QUARTER, expressions); - } - - public static FunctionExpression second(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SECOND, expressions); - } - - public static FunctionExpression second_of_minute(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SECOND_OF_MINUTE, expressions); - } - - public static FunctionExpression time(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.TIME, expressions); - } - - public static FunctionExpression time_to_sec(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.TIME_TO_SEC, expressions); - } - - public static FunctionExpression timestamp(Expression... expressions) { - return timestamp(FunctionProperties.None, expressions); - } - - public static FunctionExpression timestamp( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.TIMESTAMP, expressions); - } - - public static FunctionExpression date_format( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.DATE_FORMAT, expressions); - } - - public static FunctionExpression to_days(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.TO_DAYS, expressions); - } - - public static FunctionExpression to_seconds( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.TO_SECONDS, expressions); - } - - public static FunctionExpression to_seconds(Expression... expressions) { - return to_seconds(FunctionProperties.None, expressions); - } - - public static FunctionExpression week( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.WEEK, expressions); - } - - public static FunctionExpression weekday( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.WEEKDAY, expressions); - } - - public static FunctionExpression weekofyear( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.WEEKOFYEAR, expressions); - } - - public static FunctionExpression week_of_year( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.WEEK_OF_YEAR, expressions); - } - - public static FunctionExpression year(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.YEAR, expressions); - } - - public static FunctionExpression yearweek( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.YEARWEEK, expressions); - } - - public static FunctionExpression str_to_date( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.STR_TO_DATE, expressions); - } - - public static FunctionExpression sec_to_time(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SEC_TO_TIME, expressions); - } - - public static FunctionExpression substr(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SUBSTR, expressions); - } - - public static FunctionExpression substring(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SUBSTR, expressions); - } - - public static FunctionExpression ltrim(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LTRIM, expressions); - } - - public static FunctionExpression rtrim(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.RTRIM, expressions); - } - - public static FunctionExpression trim(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.TRIM, expressions); - } - - public static FunctionExpression upper(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.UPPER, expressions); - } - - public static FunctionExpression lower(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LOWER, expressions); - } - - public static FunctionExpression regexp(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.REGEXP, expressions); - } - - public static FunctionExpression concat(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.CONCAT, expressions); - } - - public static FunctionExpression concat_ws(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.CONCAT_WS, expressions); - } - - public static FunctionExpression length(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LENGTH, expressions); - } - - public static FunctionExpression strcmp(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.STRCMP, expressions); - } - - public static FunctionExpression right(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.RIGHT, expressions); - } - - public static FunctionExpression left(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LEFT, expressions); - } - - public static FunctionExpression ascii(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ASCII, expressions); - } - - public static FunctionExpression locate(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LOCATE, expressions); - } - - public static FunctionExpression replace(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.REPLACE, expressions); - } - - public static FunctionExpression reverse(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.REVERSE, expressions); - } - - public static FunctionExpression and(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.AND, expressions); - } - - public static FunctionExpression or(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.OR, expressions); - } - - public static FunctionExpression xor(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.XOR, expressions); - } - public static FunctionExpression nested(Expression... expressions) { return compile(FunctionProperties.None, BuiltinFunctionName.NESTED, expressions); } - public static FunctionExpression not(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.NOT, expressions); - } - - public static FunctionExpression equal(FunctionProperties fp, Expression... expressions) { - return compile(fp, BuiltinFunctionName.EQUAL, expressions); - } - - public static FunctionExpression equal(Expression... expressions) { - return equal(FunctionProperties.None, expressions); - } - - public static FunctionExpression notequal(FunctionProperties fp, Expression... expressions) { - return compile(fp, BuiltinFunctionName.NOTEQUAL, expressions); - } - - public static FunctionExpression notequal(Expression... expressions) { - return notequal(FunctionProperties.None, expressions); - } - - public static FunctionExpression less(FunctionProperties fp, Expression... expressions) { - return compile(fp, BuiltinFunctionName.LESS, expressions); - } - - public static FunctionExpression less(Expression... expressions) { - return less(FunctionProperties.None, expressions); - } - - public static FunctionExpression lte(FunctionProperties fp, Expression... expressions) { - return compile(fp, BuiltinFunctionName.LTE, expressions); - } - - public static FunctionExpression lte(Expression... expressions) { - return lte(FunctionProperties.None, expressions); - } - - public static FunctionExpression greater(FunctionProperties fp, Expression... expressions) { - return compile(fp, BuiltinFunctionName.GREATER, expressions); - } - - public static FunctionExpression greater(Expression... expressions) { - return greater(FunctionProperties.None, expressions); - } - - public static FunctionExpression gte(FunctionProperties fp, Expression... expressions) { - return compile(fp, BuiltinFunctionName.GTE, expressions); - } - - public static FunctionExpression gte(Expression... expressions) { - return gte(FunctionProperties.None, expressions); - } - - public static FunctionExpression like(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.LIKE, expressions); - } - - public static FunctionExpression notLike(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.NOT_LIKE, expressions); - } - - public static Aggregator avg(Expression... expressions) { - return aggregate(BuiltinFunctionName.AVG, expressions); - } - - public static Aggregator sum(Expression... expressions) { - return aggregate(BuiltinFunctionName.SUM, expressions); - } - - public static Aggregator count(Expression... expressions) { - return aggregate(BuiltinFunctionName.COUNT, expressions); - } - - public static Aggregator distinctCount(Expression... expressions) { - return count(expressions).distinct(true); - } - - public static Aggregator varSamp(Expression... expressions) { - return aggregate(BuiltinFunctionName.VARSAMP, expressions); - } - - public static Aggregator varPop(Expression... expressions) { - return aggregate(BuiltinFunctionName.VARPOP, expressions); - } - - public static Aggregator stddevSamp(Expression... expressions) { - return aggregate(BuiltinFunctionName.STDDEV_SAMP, expressions); - } - - public static Aggregator stddevPop(Expression... expressions) { - return aggregate(BuiltinFunctionName.STDDEV_POP, expressions); - } - - public static Aggregator take(Expression... expressions) { - return aggregate(BuiltinFunctionName.TAKE, expressions); - } - - public static RankingWindowFunction rowNumber() { - return compile(FunctionProperties.None, BuiltinFunctionName.ROW_NUMBER); - } - - public static RankingWindowFunction rank() { - return compile(FunctionProperties.None, BuiltinFunctionName.RANK); - } - - public static RankingWindowFunction denseRank() { - return compile(FunctionProperties.None, BuiltinFunctionName.DENSE_RANK); - } - - public static Aggregator min(Expression... expressions) { - return aggregate(BuiltinFunctionName.MIN, expressions); - } - - public static Aggregator max(Expression... expressions) { - return aggregate(BuiltinFunctionName.MAX, expressions); - } - - private static Aggregator aggregate(BuiltinFunctionName functionName, Expression... expressions) { - return compile(FunctionProperties.None, functionName, expressions); - } - - public static FunctionExpression isnull(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.ISNULL, expressions); - } - - public static FunctionExpression is_null(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.IS_NULL, expressions); - } - - public static FunctionExpression isnotnull(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.IS_NOT_NULL, expressions); - } - - public static FunctionExpression ifnull(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.IFNULL, expressions); - } - - public static FunctionExpression nullif(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.NULLIF, expressions); - } - - public static FunctionExpression iffunction(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.IF, expressions); - } - - public static Expression cases(Expression defaultResult, WhenClause... whenClauses) { - return new CaseClause(Arrays.asList(whenClauses), defaultResult); - } - - public static WhenClause when(Expression condition, Expression result) { - return new WhenClause(condition, result); - } - - public static FunctionExpression interval(Expression value, Expression unit) { - return compile(FunctionProperties.None, BuiltinFunctionName.INTERVAL, value, unit); - } - - public static FunctionExpression castString(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_STRING, value); - } - - public static FunctionExpression castByte(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_BYTE, value); - } - - public static FunctionExpression castShort(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_SHORT, value); - } - - public static FunctionExpression castInt(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_INT, value); - } - - public static FunctionExpression castLong(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_LONG, value); - } - - public static FunctionExpression castFloat(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_FLOAT, value); - } - - public static FunctionExpression castDouble(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_DOUBLE, value); - } - - public static FunctionExpression castBoolean(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_BOOLEAN, value); - } - - public static FunctionExpression castDate(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_DATE, value); - } - - public static FunctionExpression castTime(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_TIME, value); - } - - public static FunctionExpression castTimestamp(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_TIMESTAMP, value); - } - - public static FunctionExpression castDatetime(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_DATETIME, value); - } - - public static FunctionExpression typeof(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.TYPEOF, value); - } - public static FunctionExpression match(Expression... args) { return compile(FunctionProperties.None, BuiltinFunctionName.MATCH, args); } @@ -905,85 +205,6 @@ public static FunctionExpression score_query(Expression... args) { return compile(FunctionProperties.None, BuiltinFunctionName.SCORE_QUERY, args); } - public static FunctionExpression now(FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.NOW, args); - } - - public static FunctionExpression current_timestamp( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.CURRENT_TIMESTAMP, args); - } - - public static FunctionExpression localtimestamp( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.LOCALTIMESTAMP, args); - } - - public static FunctionExpression localtime( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.LOCALTIME, args); - } - - public static FunctionExpression sysdate( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.SYSDATE, args); - } - - public static FunctionExpression curtime( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.CURTIME, args); - } - - public static FunctionExpression current_time( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.CURRENT_TIME, args); - } - - public static FunctionExpression curdate( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.CURDATE, args); - } - - public static FunctionExpression current_date( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.CURRENT_DATE, args); - } - - public static FunctionExpression time_format( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.TIME_FORMAT, expressions); - } - - public static FunctionExpression timestampadd(Expression... expressions) { - return timestampadd(FunctionProperties.None, expressions); - } - - public static FunctionExpression timestampadd( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.TIMESTAMPADD, expressions); - } - - public static FunctionExpression timestampdiff( - FunctionProperties functionProperties, Expression... expressions) { - return compile(functionProperties, BuiltinFunctionName.TIMESTAMPDIFF, expressions); - } - - public static FunctionExpression utc_date( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.UTC_DATE, args); - } - - public static FunctionExpression utc_time( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.UTC_TIME, args); - } - - public static FunctionExpression utc_timestamp( - FunctionProperties functionProperties, Expression... args) { - return compile(functionProperties, BuiltinFunctionName.UTC_TIMESTAMP, args); - } - - // Make this add OpenSearchStorageEngine @ExtendWith(MockitoExtension.class) protected static StorageEngine storageEngine() { @@ -1076,8 +297,7 @@ public void deleteDataSource(String dataSourceName) { @Override public Boolean dataSourceExists(String dataSourceName) { - return dataSourceName.equals(DEFAULT_DATASOURCE_NAME) - || dataSourceName.equals("prometheus"); + return dataSourceName.equals(DEFAULT_DATASOURCE_NAME); } } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java index 483ea1290e..b7d541007c 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java @@ -57,6 +57,7 @@ import org.opensearch.sql.expression.ReferenceExpression; import org.opensearch.sql.opensearch.data.type.OpenSearchDataType; import org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory; +import org.opensearch.sql.opensearch.expression.OpenSearchDSL; import org.opensearch.sql.opensearch.response.agg.CompositeAggregationParser; import org.opensearch.sql.opensearch.response.agg.OpenSearchAggregationResponseParser; import org.opensearch.sql.opensearch.response.agg.SingleValueParser; @@ -342,7 +343,7 @@ void test_push_down_nested() { List projectList = List.of( - new NamedExpression("message.info", DSL.nested(DSL.ref("message.info", STRING)), null) + new NamedExpression("message.info", OpenSearchDSL.nested(DSL.ref("message.info", STRING)), null) ); LogicalNested nested = new LogicalNested(null, args, projectList); @@ -375,8 +376,8 @@ void test_push_down_multiple_nested_with_same_path() { ); List projectList = List.of( - new NamedExpression("message.info", DSL.nested(DSL.ref("message.info", STRING)), null), - new NamedExpression("message.from", DSL.nested(DSL.ref("message.from", STRING)), null) + new NamedExpression("message.info", OpenSearchDSL.nested(DSL.ref("message.info", STRING)), null), + new NamedExpression("message.from", OpenSearchDSL.nested(DSL.ref("message.from", STRING)), null) ); LogicalNested nested = new LogicalNested(null, args, projectList); @@ -405,7 +406,7 @@ void test_push_down_nested_with_filter() { List projectList = List.of( - new NamedExpression("message.info", DSL.nested(DSL.ref("message.info", STRING)), null) + new NamedExpression("message.info", OpenSearchDSL.nested(DSL.ref("message.info", STRING)), null) ); LogicalNested nested = new LogicalNested(null, args, projectList); @@ -442,7 +443,7 @@ void testPushDownNestedWithNestedFilter() { List projectList = List.of( - new NamedExpression("message.info", DSL.nested(DSL.ref("message.info", STRING)), null) + new NamedExpression("message.info", OpenSearchDSL.nested(DSL.ref("message.info", STRING)), null) ); QueryBuilder innerFilterQuery = QueryBuilders.rangeQuery("myNum").gt(3); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java index ae1c93c635..26ba16c6f8 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java @@ -75,6 +75,7 @@ import org.opensearch.sql.expression.ReferenceExpression; import org.opensearch.sql.expression.function.OpenSearchFunction; import org.opensearch.sql.opensearch.data.type.OpenSearchDataType; +import org.opensearch.sql.opensearch.expression.OpenSearchDSL; import org.opensearch.sql.opensearch.request.OpenSearchRequestBuilder; import org.opensearch.sql.opensearch.response.agg.CompositeAggregationParser; import org.opensearch.sql.opensearch.response.agg.OpenSearchAggregationResponseParser; @@ -164,7 +165,7 @@ void test_filter_on_opensearchfunction_with_trackedscores_push_down() { ), DSL.named("i", DSL.ref("intV", INTEGER)) ); - FunctionExpression queryString = DSL.query_string( + FunctionExpression queryString = OpenSearchDSL.query_string( DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "intV", ExprValueUtils.floatValue(1.5F)))))), @@ -204,14 +205,14 @@ void test_filter_on_multiple_opensearchfunctions_with_trackedscores_push_down() ), DSL.named("i", DSL.ref("intV", INTEGER)) ); - FunctionExpression firstQueryString = DSL.query_string( + FunctionExpression firstQueryString = OpenSearchDSL.query_string( DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "intV", ExprValueUtils.floatValue(1.5F)))))), DSL.namedArgument("query", "QUERY"), DSL.namedArgument("boost", "12.5")); ((OpenSearchFunction) firstQueryString).setScoreTracked(false); - FunctionExpression secondQueryString = DSL.query_string( + FunctionExpression secondQueryString = OpenSearchDSL.query_string( DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "intV", ExprValueUtils.floatValue(1.5F)))))), @@ -243,7 +244,7 @@ void test_filter_on_opensearchfunction_without_trackedscores_push_down() { ), DSL.named("i", DSL.ref("intV", INTEGER)) ); - FunctionExpression queryString = DSL.query_string( + FunctionExpression queryString = OpenSearchDSL.query_string( DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "intV", ExprValueUtils.floatValue(1.5F)))))), @@ -413,7 +414,7 @@ void test_nested_push_down() { List projectList = List.of( - new NamedExpression("message.info", DSL.nested(DSL.ref("message.info", STRING)), null) + new NamedExpression("message.info", OpenSearchDSL.nested(DSL.ref("message.info", STRING)), null) ); LogicalNested nested = new LogicalNested(null, args, projectList); @@ -424,13 +425,13 @@ void test_nested_push_down() { indexScanBuilder( withNestedPushedDown(nested.getFields())), args, projectList), DSL.named("message.info", - DSL.nested(DSL.ref("message.info", STRING))) + OpenSearchDSL.nested(DSL.ref("message.info", STRING))) ), project( nested( relation("schema", table), args, projectList), DSL.named("message.info", - DSL.nested(DSL.ref("message.info", STRING))) + OpenSearchDSL.nested(DSL.ref("message.info", STRING))) ) ); } @@ -595,7 +596,7 @@ void test_nested_sort_filter_push_down() { DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ), Pair.of( - SortOption.DEFAULT_ASC, DSL.nested(DSL.ref("message.info", STRING)) + SortOption.DEFAULT_ASC, OpenSearchDSL.nested(DSL.ref("message.info", STRING)) ) ), DSL.named("intV", DSL.ref("intV", INTEGER)) @@ -611,14 +612,14 @@ void test_function_expression_sort_returns_optimized_logical_sort() { indexScanBuilder(), Pair.of( SortOption.DEFAULT_ASC, - DSL.match(DSL.namedArgument("field", literal("message"))) + OpenSearchDSL.match(DSL.namedArgument("field", literal("message"))) ) ), sort( relation("schema", table), Pair.of( SortOption.DEFAULT_ASC, - DSL.match(DSL.namedArgument("field", literal("message")) + OpenSearchDSL.match(DSL.namedArgument("field", literal("message")) ) ) ) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java index eb07076257..8ec125fbb6 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java @@ -56,6 +56,7 @@ import org.opensearch.sql.expression.ReferenceExpression; import org.opensearch.sql.opensearch.data.type.OpenSearchDataType; import org.opensearch.sql.opensearch.data.type.OpenSearchTextType; +import org.opensearch.sql.opensearch.expression.OpenSearchDSL; import org.opensearch.sql.opensearch.storage.serialization.ExpressionSerializer; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -320,7 +321,7 @@ void should_build_term_query_predicate_expression_with_nested_function() { + " }\n" + "}", buildQuery( - DSL.equal(DSL.nested( + DSL.equal(OpenSearchDSL.nested( DSL.ref("message.info", STRING), DSL.ref("message", STRING)), literal("string_value") @@ -352,7 +353,7 @@ void should_build_range_query_predicate_expression_with_nested_function() { + " }\n" + "}", buildQuery( - DSL.greater(DSL.nested( + DSL.greater(OpenSearchDSL.nested( DSL.ref("lottery.number.id", INTEGER)), literal(1234) ) ) @@ -365,7 +366,7 @@ void should_build_range_query_predicate_expression_with_nested_function() { void ensure_alternate_syntax_falls_back_to_legacy_engine() { assertThrows(SyntaxCheckException.class, () -> buildQuery( - DSL.nested( + OpenSearchDSL.nested( DSL.ref("message", STRING), DSL.equal(DSL.literal("message.info"), literal("a")) ) @@ -377,7 +378,7 @@ void ensure_alternate_syntax_falls_back_to_legacy_engine() { void nested_filter_wrong_right_side_type_in_predicate_throws_exception() { assertThrows(IllegalArgumentException.class, () -> buildQuery( - DSL.equal(DSL.nested( + DSL.equal(OpenSearchDSL.nested( DSL.ref("message.info", STRING), DSL.ref("message", STRING)), DSL.ref("string_value", STRING) @@ -390,7 +391,7 @@ void nested_filter_wrong_right_side_type_in_predicate_throws_exception() { void nested_filter_wrong_first_param_type_throws_exception() { assertThrows(IllegalArgumentException.class, () -> buildQuery( - DSL.equal(DSL.nested( + DSL.equal(OpenSearchDSL.nested( DSL.namedArgument("field", literal("message"))), literal("string_value") ) @@ -402,7 +403,7 @@ void nested_filter_wrong_first_param_type_throws_exception() { void nested_filter_wrong_second_param_type_throws_exception() { assertThrows(IllegalArgumentException.class, () -> buildQuery( - DSL.equal(DSL.nested( + DSL.equal(OpenSearchDSL.nested( DSL.ref("message.info", STRING), DSL.literal(2)), literal("string_value") @@ -415,7 +416,7 @@ void nested_filter_wrong_second_param_type_throws_exception() { void nested_filter_too_many_params_throws_exception() { assertThrows(IllegalArgumentException.class, () -> buildQuery( - DSL.equal(DSL.nested( + DSL.equal(OpenSearchDSL.nested( DSL.ref("message.info", STRING), DSL.ref("message", STRING), DSL.ref("message", STRING)), @@ -444,7 +445,7 @@ void should_build_match_query_with_default_parameters() { + " }\n" + "}", buildQuery( - DSL.match( + OpenSearchDSL.match( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query"))))); @@ -473,7 +474,7 @@ void should_build_match_query_with_custom_parameters() { + " }\n" + "}", buildQuery( - DSL.match( + OpenSearchDSL.match( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query")), @@ -493,7 +494,7 @@ void should_build_match_query_with_custom_parameters() { @Test void match_invalid_parameter() { - FunctionExpression expr = DSL.match( + FunctionExpression expr = OpenSearchDSL.match( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query")), @@ -504,7 +505,7 @@ void match_invalid_parameter() { @Test void match_disallow_duplicate_parameter() { - FunctionExpression expr = DSL.match( + FunctionExpression expr = OpenSearchDSL.match( DSL.namedArgument("field", literal("message")), DSL.namedArgument("query", literal("search query")), DSL.namedArgument("analyzer", literal("keyword")), @@ -515,7 +516,7 @@ void match_disallow_duplicate_parameter() { @Test void match_disallow_duplicate_query() { - FunctionExpression expr = DSL.match( + FunctionExpression expr = OpenSearchDSL.match( DSL.namedArgument("field", literal("message")), DSL.namedArgument("query", literal("search query")), DSL.namedArgument("analyzer", literal("keyword")), @@ -526,7 +527,7 @@ void match_disallow_duplicate_query() { @Test void match_disallow_duplicate_field() { - FunctionExpression expr = DSL.match( + FunctionExpression expr = OpenSearchDSL.match( DSL.namedArgument("field", literal("message")), DSL.namedArgument("query", literal("search query")), DSL.namedArgument("analyzer", literal("keyword")), @@ -537,7 +538,7 @@ void match_disallow_duplicate_field() { @Test void match_missing_field() { - FunctionExpression expr = DSL.match( + FunctionExpression expr = OpenSearchDSL.match( DSL.namedArgument("query", literal("search query")), DSL.namedArgument("analyzer", literal("keyword"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); @@ -546,7 +547,7 @@ void match_missing_field() { @Test void match_missing_query() { - FunctionExpression expr = DSL.match( + FunctionExpression expr = OpenSearchDSL.match( DSL.namedArgument("field", literal("field1")), DSL.namedArgument("analyzer", literal("keyword"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); @@ -567,7 +568,7 @@ void should_build_match_phrase_query_with_default_parameters() { + " }\n" + "}", buildQuery( - DSL.match_phrase( + OpenSearchDSL.match_phrase( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query"))))); @@ -592,7 +593,7 @@ void should_build_multi_match_query_with_default_parameters_single_field() { + " \"boost\" : 1.0,\n" + " }\n" + "}", - buildQuery(DSL.multi_match( + buildQuery(OpenSearchDSL.multi_match( DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F)))))), @@ -618,7 +619,7 @@ void should_build_multi_match_query_with_default_parameters_all_fields() { + " \"boost\" : 1.0,\n" + " }\n" + "}", - buildQuery(DSL.multi_match( + buildQuery(OpenSearchDSL.multi_match( DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "*", ExprValueUtils.floatValue(1.F)))))), @@ -642,7 +643,7 @@ void should_build_multi_match_query_with_default_parameters_no_fields() { + " \"boost\" : 1.0,\n" + " }\n" + "}", - buildQuery(DSL.multi_match( + buildQuery(OpenSearchDSL.multi_match( DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of())))), DSL.namedArgument("query", literal("search query"))))); @@ -667,7 +668,7 @@ void should_build_multi_match_query_with_default_parameters_multiple_fields() { + " \"boost\" : 1.0,\n" + " }\n" + "}"; - var actual = buildQuery(DSL.multi_match( + var actual = buildQuery(OpenSearchDSL.multi_match( DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), @@ -705,7 +706,7 @@ void should_build_multi_match_query_with_custom_parameters() { + " }\n" + "}"; var actual = buildQuery( - DSL.multi_match( + OpenSearchDSL.multi_match( DSL.namedArgument("fields", DSL.literal( ExprValueUtils.tupleValue(ImmutableMap.of("field1", 1.F, "field2", .3F)))), DSL.namedArgument("query", literal("search query")), @@ -734,7 +735,7 @@ void should_build_multi_match_query_with_custom_parameters() { @Test void multi_match_invalid_parameter() { - FunctionExpression expr = DSL.multi_match( + FunctionExpression expr = OpenSearchDSL.multi_match( DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), @@ -760,7 +761,7 @@ void should_build_match_phrase_query_with_custom_parameters() { + " }\n" + "}", buildQuery( - DSL.match_phrase( + OpenSearchDSL.match_phrase( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("boost", literal("1.2")), @@ -772,7 +773,7 @@ void should_build_match_phrase_query_with_custom_parameters() { @Test void wildcard_query_invalid_parameter() { - FunctionExpression expr = DSL.wildcard_query( + FunctionExpression expr = OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query*")), @@ -792,7 +793,7 @@ void wildcard_query_convert_sql_wildcard_to_lucene() { + " }\n" + " }\n" + "}", - buildQuery(DSL.wildcard_query( + buildQuery(OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query%"))))); @@ -805,7 +806,7 @@ void wildcard_query_convert_sql_wildcard_to_lucene() { + " }\n" + " }\n" + "}", - buildQuery(DSL.wildcard_query( + buildQuery(OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query_"))))); @@ -821,7 +822,7 @@ void wildcard_query_escape_wildcards_characters() { + " }\n" + " }\n" + "}", - buildQuery(DSL.wildcard_query( + buildQuery(OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query\\%"))))); @@ -834,7 +835,7 @@ void wildcard_query_escape_wildcards_characters() { + " }\n" + " }\n" + "}", - buildQuery(DSL.wildcard_query( + buildQuery(OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query\\_"))))); @@ -847,7 +848,7 @@ void wildcard_query_escape_wildcards_characters() { + " }\n" + " }\n" + "}", - buildQuery(DSL.wildcard_query( + buildQuery(OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query\\*"))))); @@ -860,7 +861,7 @@ void wildcard_query_escape_wildcards_characters() { + " }\n" + " }\n" + "}", - buildQuery(DSL.wildcard_query( + buildQuery(OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query\\?"))))); @@ -876,7 +877,7 @@ void should_build_wildcard_query_with_default_parameters() { + " }\n" + " }\n" + "}", - buildQuery(DSL.wildcard_query( + buildQuery(OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query*"))))); @@ -894,7 +895,7 @@ void should_build_wildcard_query_query_with_custom_parameters() { + " }\n" + " }\n" + "}", - buildQuery(DSL.wildcard_query( + buildQuery(OpenSearchDSL.wildcard_query( DSL.namedArgument("field", new ReferenceExpression("field", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query*")), @@ -905,7 +906,7 @@ void should_build_wildcard_query_query_with_custom_parameters() { @Test void query_invalid_parameter() { - FunctionExpression expr = DSL.query( + FunctionExpression expr = OpenSearchDSL.query( DSL.namedArgument("invalid_parameter", literal("invalid_value"))); assertThrows(SemanticCheckException.class, () -> buildQuery(expr), "Parameter invalid_parameter is invalid for query function."); @@ -913,7 +914,7 @@ void query_invalid_parameter() { @Test void query_invalid_fields_parameter_exception_message() { - FunctionExpression expr = DSL.query( + FunctionExpression expr = OpenSearchDSL.query( DSL.namedArgument("fields", literal("field1")), DSL.namedArgument("query", literal("search query"))); @@ -942,7 +943,7 @@ void should_build_query_query_with_default_parameters() { + " }\n" + "}"; - assertJsonEquals(expected, buildQuery(DSL.query( + assertJsonEquals(expected, buildQuery(OpenSearchDSL.query( DSL.namedArgument("query", literal("field1:query_value"))))); } @@ -972,7 +973,7 @@ void should_build_query_query_with_custom_parameters() { + " }\n" + "}"; var actual = buildQuery( - DSL.query( + OpenSearchDSL.query( DSL.namedArgument("query", literal("field1:query_value")), DSL.namedArgument("analyze_wildcard", literal("true")), DSL.namedArgument("analyzer", literal("keyword")), @@ -992,7 +993,7 @@ void should_build_query_query_with_custom_parameters() { @Test void query_string_invalid_parameter() { - FunctionExpression expr = DSL.query_string( + FunctionExpression expr = OpenSearchDSL.query_string( DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), @@ -1023,7 +1024,7 @@ void should_build_query_string_query_with_default_parameters_multiple_fields() { + " \"boost\" : 1.0\n" + " }\n" + "}"; - var actual = buildQuery(DSL.query_string( + var actual = buildQuery(OpenSearchDSL.query_string( DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), @@ -1063,7 +1064,7 @@ void should_build_query_string_query_with_custom_parameters() { + " }\n" + "}"; var actual = buildQuery( - DSL.query_string( + OpenSearchDSL.query_string( DSL.namedArgument("fields", DSL.literal( ExprValueUtils.tupleValue(ImmutableMap.of("field1", 1.F, "field2", .3F)))), DSL.namedArgument("query", literal("query_value")), @@ -1109,7 +1110,7 @@ void should_build_query_string_query_with_default_parameters_single_field() { + " \"boost\" : 1.0,\n" + " }\n" + "}", - buildQuery(DSL.query_string( + buildQuery(OpenSearchDSL.query_string( DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F)))))), @@ -1138,7 +1139,7 @@ void should_build_simple_query_string_query_with_default_parameters_single_field + " \"boost\" : 1.0\n" + " }\n" + "}", - buildQuery(DSL.simple_query_string( + buildQuery(OpenSearchDSL.simple_query_string( DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F)))))), @@ -1161,7 +1162,7 @@ void should_build_simple_query_string_query_with_default_parameters_multiple_fie + " \"boost\" : 1.0\n" + " }\n" + "}"; - var actual = buildQuery(DSL.simple_query_string( + var actual = buildQuery(OpenSearchDSL.simple_query_string( DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), @@ -1195,7 +1196,7 @@ void should_build_simple_query_string_query_with_custom_parameters() { + " }\n" + "}"; var actual = buildQuery( - DSL.simple_query_string( + OpenSearchDSL.simple_query_string( DSL.namedArgument("fields", DSL.literal( ExprValueUtils.tupleValue(ImmutableMap.of("field1", 1.F, "field2", .3F)))), DSL.namedArgument("query", literal("search query")), @@ -1220,7 +1221,7 @@ void should_build_simple_query_string_query_with_custom_parameters() { @Test void simple_query_string_invalid_parameter() { - FunctionExpression expr = DSL.simple_query_string( + FunctionExpression expr = OpenSearchDSL.simple_query_string( DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), @@ -1233,7 +1234,7 @@ void simple_query_string_invalid_parameter() { @Test void match_phrase_invalid_parameter() { - FunctionExpression expr = DSL.match_phrase( + FunctionExpression expr = OpenSearchDSL.match_phrase( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query")), @@ -1252,55 +1253,55 @@ void relevancy_func_invalid_arg_values() { "field2", ExprValueUtils.floatValue(.3F)))))); final var query = DSL.namedArgument("query", literal("search query")); - var slopTest = DSL.match_phrase(field, query, + var slopTest = OpenSearchDSL.match_phrase(field, query, DSL.namedArgument("slop", literal("1.5"))); var msg = assertThrows(RuntimeException.class, () -> buildQuery(slopTest)).getMessage(); assertEquals("Invalid slop value: '1.5'. Accepts only integer values.", msg); - var ztqTest = DSL.match_phrase(field, query, + var ztqTest = OpenSearchDSL.match_phrase(field, query, DSL.namedArgument("zero_terms_query", literal("meow"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(ztqTest)).getMessage(); assertEquals( "Invalid zero_terms_query value: 'meow'. Available values are: NONE, ALL, NULL.", msg); - var boostTest = DSL.match(field, query, + var boostTest = OpenSearchDSL.match(field, query, DSL.namedArgument("boost", literal("pewpew"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(boostTest)).getMessage(); assertEquals( "Invalid boost value: 'pewpew'. Accepts only floating point values greater than 0.", msg); - var boolTest = DSL.query_string(fields, query, + var boolTest = OpenSearchDSL.query_string(fields, query, DSL.namedArgument("escape", literal("42"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(boolTest)).getMessage(); assertEquals( "Invalid escape value: '42'. Accepts only boolean values: 'true' or 'false'.", msg); - var typeTest = DSL.multi_match(fields, query, + var typeTest = OpenSearchDSL.multi_match(fields, query, DSL.namedArgument("type", literal("42"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(typeTest)).getMessage(); assertTrue(msg.startsWith("Invalid type value: '42'. Available values are:")); - var operatorTest = DSL.simple_query_string(fields, query, + var operatorTest = OpenSearchDSL.simple_query_string(fields, query, DSL.namedArgument("default_operator", literal("42"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(operatorTest)).getMessage(); assertTrue(msg.startsWith("Invalid default_operator value: '42'. Available values are:")); - var flagsTest = DSL.simple_query_string(fields, query, + var flagsTest = OpenSearchDSL.simple_query_string(fields, query, DSL.namedArgument("flags", literal("42"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(flagsTest)).getMessage(); assertTrue(msg.startsWith("Invalid flags value: '42'. Available values are:")); - var fuzzinessTest = DSL.match_bool_prefix(field, query, + var fuzzinessTest = OpenSearchDSL.match_bool_prefix(field, query, DSL.namedArgument("fuzziness", literal("AUTO:"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(fuzzinessTest)).getMessage(); assertTrue(msg.startsWith("Invalid fuzziness value: 'AUTO:'. Available values are:")); - var rewriteTest = DSL.match_bool_prefix(field, query, + var rewriteTest = OpenSearchDSL.match_bool_prefix(field, query, DSL.namedArgument("fuzzy_rewrite", literal("42"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(rewriteTest)).getMessage(); assertTrue(msg.startsWith("Invalid fuzzy_rewrite value: '42'. Available values are:")); - var timezoneTest = DSL.query_string(fields, query, + var timezoneTest = OpenSearchDSL.query_string(fields, query, DSL.namedArgument("time_zone", literal("42"))); msg = assertThrows(RuntimeException.class, () -> buildQuery(timezoneTest)).getMessage(); assertTrue(msg.startsWith("Invalid time_zone value: '42'.")); @@ -1322,7 +1323,7 @@ void should_build_match_bool_prefix_query_with_default_parameters() { + " }\n" + "}", buildQuery( - DSL.match_bool_prefix( + OpenSearchDSL.match_bool_prefix( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query"))))); @@ -1330,7 +1331,7 @@ void should_build_match_bool_prefix_query_with_default_parameters() { @Test void multi_match_missing_fields_even_with_struct() { - FunctionExpression expr = DSL.multi_match( + FunctionExpression expr = OpenSearchDSL.multi_match( DSL.namedArgument("something-but-not-fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "pewpew", ExprValueUtils.integerValue(42)))))), @@ -1342,7 +1343,7 @@ void multi_match_missing_fields_even_with_struct() { @Test void multi_match_missing_query_even_with_struct() { - FunctionExpression expr = DSL.multi_match( + FunctionExpression expr = OpenSearchDSL.multi_match( DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), @@ -1367,7 +1368,7 @@ void should_build_match_phrase_prefix_query_with_default_parameters() { + " }\n" + "}", buildQuery( - DSL.match_phrase_prefix( + OpenSearchDSL.match_phrase_prefix( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query"))))); @@ -1389,7 +1390,7 @@ void should_build_match_phrase_prefix_query_with_non_default_parameters() { + " }\n" + "}", buildQuery( - DSL.match_phrase_prefix( + OpenSearchDSL.match_phrase_prefix( DSL.namedArgument("field", new ReferenceExpression("message", OpenSearchTextType.of())), DSL.namedArgument("query", literal("search query")), diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/sort/SortQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/sort/SortQueryBuilderTest.java index e84ed14e43..225f3e47d6 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/sort/SortQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/sort/SortQueryBuilderTest.java @@ -18,6 +18,7 @@ import org.opensearch.sql.data.model.ExprShortValue; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.LiteralExpression; +import org.opensearch.sql.opensearch.expression.OpenSearchDSL; class SortQueryBuilderTest { @@ -32,7 +33,7 @@ void build_sortbuilder_from_reference() { void build_sortbuilder_from_nested_function() { assertNotNull( sortQueryBuilder.build( - DSL.nested(DSL.ref("message.info", STRING)), + OpenSearchDSL.nested(DSL.ref("message.info", STRING)), Sort.SortOption.DEFAULT_ASC ) ); @@ -42,7 +43,7 @@ void build_sortbuilder_from_nested_function() { void build_sortbuilder_from_nested_function_with_path_param() { assertNotNull( sortQueryBuilder.build( - DSL.nested(DSL.ref("message.info", STRING), DSL.ref("message", STRING)), + OpenSearchDSL.nested(DSL.ref("message.info", STRING), DSL.ref("message", STRING)), Sort.SortOption.DEFAULT_ASC ) ); @@ -53,7 +54,7 @@ void nested_with_too_many_args_throws_exception() { assertThrows( IllegalArgumentException.class, () -> sortQueryBuilder.build( - DSL.nested( + OpenSearchDSL.nested( DSL.ref("message.info", STRING), DSL.ref("message", STRING), DSL.ref("message", STRING) @@ -68,7 +69,7 @@ void nested_with_too_few_args_throws_exception() { assertThrows( IllegalArgumentException.class, () -> sortQueryBuilder.build( - DSL.nested(), + OpenSearchDSL.nested(), Sort.SortOption.DEFAULT_ASC ) ); @@ -79,7 +80,7 @@ void nested_with_invalid_arg_type_throws_exception() { assertThrows( IllegalArgumentException.class, () -> sortQueryBuilder.build( - DSL.nested( + OpenSearchDSL.nested( DSL.literal(1) ), Sort.SortOption.DEFAULT_ASC