diff --git a/build.gradle b/build.gradle index bbfc122005..a9a171da01 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ buildscript { buildVersionQualifier = System.getProperty("build.version_qualifier", "") version_tokens = opensearch_version.tokenize('-') opensearch_build = version_tokens[0] + '.0' + prometheus_binary_version = "2.37.2" if (buildVersionQualifier) { opensearch_build += "-${buildVersionQualifier}" } @@ -21,6 +22,32 @@ buildscript { // 2.0.0-rc1-SNAPSHOT -> 2.0.0.0-rc1-SNAPSHOT (opensearch_build) opensearch_build += "-SNAPSHOT" } + getArchType = { + if (System.getProperty("os.arch").startsWith("x") || System.getProperty("os.arch").startsWith("amd")) { + return "amd64" + } + else { + return "arm64" + } + } + getOSFamilyType = { + def os = org.gradle.internal.os.OperatingSystem.current(); + if (os.isMacOsX()) { + return "darwin" + } + else if(os.isLinux()){ + return "linux" + } + else if(os.isWindows()) { + return "windows" + } + else { + return os.getFamilyName().toString() + } + } + getPrometheusBinaryLocation = { -> + return "https://github.com/prometheus/prometheus/releases/download/v${prometheus_binary_version}/prometheus-${prometheus_binary_version}."+ getOSFamilyType() + "-" + getArchType() + ".tar.gz" + } } repositories { diff --git a/core/build.gradle b/core/build.gradle index 45169f4ead..fe7126fed5 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -68,7 +68,7 @@ jacocoTestReport { afterEvaluate { classDirectories.setFrom(files(classDirectories.files.collect { fileTree(dir: it, - exclude: ['**/ast/**', '**/catalog/model/**']) + exclude: ['**/ast/**', '**/datasource/model/**']) })) } } @@ -80,7 +80,7 @@ jacocoTestCoverageVerification { excludes = [ 'org.opensearch.sql.utils.MLCommonsConstants', 'org.opensearch.sql.utils.Constants', - 'org.opensearch.sql.catalog.model.*' + 'org.opensearch.sql.datasource.model.*' ] limit { counter = 'LINE' diff --git a/core/src/main/java/org/opensearch/sql/CatalogSchemaName.java b/core/src/main/java/org/opensearch/sql/DataSourceSchemaName.java similarity index 77% rename from core/src/main/java/org/opensearch/sql/CatalogSchemaName.java rename to core/src/main/java/org/opensearch/sql/DataSourceSchemaName.java index 8dde03ca3d..47988097c3 100644 --- a/core/src/main/java/org/opensearch/sql/CatalogSchemaName.java +++ b/core/src/main/java/org/opensearch/sql/DataSourceSchemaName.java @@ -12,9 +12,9 @@ @Getter @RequiredArgsConstructor -public class CatalogSchemaName { +public class DataSourceSchemaName { - private final String catalogName; + private final String dataSourceName; private final String schemaName; diff --git a/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java b/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java index 7d0a452e1b..d463ed424d 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java @@ -11,19 +11,11 @@ import static org.opensearch.sql.ast.tree.Sort.SortOrder.ASC; import static org.opensearch.sql.ast.tree.Sort.SortOrder.DESC; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; -import static org.opensearch.sql.utils.MLCommonsConstants.ACTION; -import static org.opensearch.sql.utils.MLCommonsConstants.MODELID; -import static org.opensearch.sql.utils.MLCommonsConstants.PREDICT; import static org.opensearch.sql.utils.MLCommonsConstants.RCF_ANOMALOUS; import static org.opensearch.sql.utils.MLCommonsConstants.RCF_ANOMALY_GRADE; import static org.opensearch.sql.utils.MLCommonsConstants.RCF_SCORE; -import static org.opensearch.sql.utils.MLCommonsConstants.RCF_TIMESTAMP; -import static org.opensearch.sql.utils.MLCommonsConstants.STATUS; -import static org.opensearch.sql.utils.MLCommonsConstants.TASKID; import static org.opensearch.sql.utils.MLCommonsConstants.TIME_FIELD; -import static org.opensearch.sql.utils.MLCommonsConstants.TRAIN; -import static org.opensearch.sql.utils.MLCommonsConstants.TRAINANDPREDICT; -import static org.opensearch.sql.utils.SystemIndexUtils.CATALOGS_TABLE_NAME; +import static org.opensearch.sql.utils.SystemIndexUtils.DATASOURCES_TABLE_NAME; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; @@ -37,7 +29,7 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.analysis.symbol.Namespace; import org.opensearch.sql.analysis.symbol.Symbol; import org.opensearch.sql.ast.AbstractNodeVisitor; @@ -69,10 +61,10 @@ import org.opensearch.sql.ast.tree.TableFunction; import org.opensearch.sql.ast.tree.UnresolvedPlan; import org.opensearch.sql.ast.tree.Values; -import org.opensearch.sql.catalog.CatalogService; -import org.opensearch.sql.catalog.model.Catalog; import org.opensearch.sql.data.model.ExprMissingValue; import org.opensearch.sql.data.type.ExprCoreType; +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.model.DataSource; import org.opensearch.sql.exception.SemanticCheckException; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; @@ -101,7 +93,7 @@ import org.opensearch.sql.planner.logical.LogicalRename; import org.opensearch.sql.planner.logical.LogicalSort; import org.opensearch.sql.planner.logical.LogicalValues; -import org.opensearch.sql.planner.physical.catalog.CatalogTable; +import org.opensearch.sql.planner.physical.datasource.DataSourceTable; import org.opensearch.sql.storage.Table; import org.opensearch.sql.utils.ParseUtils; @@ -117,7 +109,7 @@ public class Analyzer extends AbstractNodeVisitor private final NamedExpressionAnalyzer namedExpressionAnalyzer; - private final CatalogService catalogService; + private final DataSourceService dataSourceService; private final BuiltinFunctionRepository repository; @@ -126,10 +118,10 @@ public class Analyzer extends AbstractNodeVisitor */ public Analyzer( ExpressionAnalyzer expressionAnalyzer, - CatalogService catalogService, + DataSourceService dataSourceService, BuiltinFunctionRepository repository) { this.expressionAnalyzer = expressionAnalyzer; - this.catalogService = catalogService; + this.dataSourceService = dataSourceService; this.selectExpressionAnalyzer = new SelectExpressionAnalyzer(expressionAnalyzer); this.namedExpressionAnalyzer = new NamedExpressionAnalyzer(expressionAnalyzer); this.repository = repository; @@ -142,25 +134,27 @@ public LogicalPlan analyze(UnresolvedPlan unresolved, AnalysisContext context) { @Override public LogicalPlan visitRelation(Relation node, AnalysisContext context) { QualifiedName qualifiedName = node.getTableQualifiedName(); - Set allowedCatalogNames = catalogService.getCatalogs() + Set allowedDataSourceNames = dataSourceService.getDataSources() .stream() - .map(Catalog::getName) + .map(DataSource::getName) .collect(Collectors.toSet()); - CatalogSchemaIdentifierNameResolver catalogSchemaIdentifierNameResolver - = new CatalogSchemaIdentifierNameResolver(qualifiedName.getParts(), allowedCatalogNames); - String tableName = catalogSchemaIdentifierNameResolver.getIdentifierName(); + DataSourceSchemaIdentifierNameResolver dataSourceSchemaIdentifierNameResolver + = new DataSourceSchemaIdentifierNameResolver(qualifiedName.getParts(), + allowedDataSourceNames); + String tableName = dataSourceSchemaIdentifierNameResolver.getIdentifierName(); context.push(); TypeEnvironment curEnv = context.peek(); Table table; - if (CATALOGS_TABLE_NAME.equals(tableName)) { - table = new CatalogTable(catalogService); + if (DATASOURCES_TABLE_NAME.equals(tableName)) { + table = new DataSourceTable(dataSourceService); } else { - table = catalogService - .getCatalog(catalogSchemaIdentifierNameResolver.getCatalogName()) + table = dataSourceService + .getDataSource(dataSourceSchemaIdentifierNameResolver.getDataSourceName()) .getStorageEngine() - .getTable(new CatalogSchemaName(catalogSchemaIdentifierNameResolver.getCatalogName(), - catalogSchemaIdentifierNameResolver.getSchemaName()), - catalogSchemaIdentifierNameResolver.getIdentifierName()); + .getTable(new DataSourceSchemaName( + dataSourceSchemaIdentifierNameResolver.getDataSourceName(), + dataSourceSchemaIdentifierNameResolver.getSchemaName()), + dataSourceSchemaIdentifierNameResolver.getIdentifierName()); } table.getFieldTypes().forEach((k, v) -> curEnv.define(new Symbol(Namespace.FIELD_NAME, k), v)); @@ -188,28 +182,29 @@ public LogicalPlan visitRelationSubquery(RelationSubquery node, AnalysisContext @Override public LogicalPlan visitTableFunction(TableFunction node, AnalysisContext context) { QualifiedName qualifiedName = node.getFunctionName(); - Set allowedCatalogNames = catalogService.getCatalogs() + Set allowedDataSourceNames = dataSourceService.getDataSources() .stream() - .map(Catalog::getName) + .map(DataSource::getName) .collect(Collectors.toSet()); - CatalogSchemaIdentifierNameResolver catalogSchemaIdentifierNameResolver - = new CatalogSchemaIdentifierNameResolver(qualifiedName.getParts(), allowedCatalogNames); + DataSourceSchemaIdentifierNameResolver dataSourceSchemaIdentifierNameResolver + = new DataSourceSchemaIdentifierNameResolver(qualifiedName.getParts(), + allowedDataSourceNames); FunctionName functionName - = FunctionName.of(catalogSchemaIdentifierNameResolver.getIdentifierName()); + = FunctionName.of(dataSourceSchemaIdentifierNameResolver.getIdentifierName()); List arguments = node.getArguments().stream() .map(unresolvedExpression -> this.expressionAnalyzer.analyze(unresolvedExpression, context)) .collect(Collectors.toList()); TableFunctionImplementation tableFunctionImplementation = (TableFunctionImplementation) repository.compile( - catalogSchemaIdentifierNameResolver.getCatalogName(), functionName, arguments); + dataSourceSchemaIdentifierNameResolver.getDataSourceName(), functionName, arguments); context.push(); TypeEnvironment curEnv = context.peek(); Table table = tableFunctionImplementation.applyArguments(); table.getFieldTypes().forEach((k, v) -> curEnv.define(new Symbol(Namespace.FIELD_NAME, k), v)); curEnv.define(new Symbol(Namespace.INDEX_NAME, - catalogSchemaIdentifierNameResolver.getIdentifierName()), STRUCT); - return new LogicalRelation(catalogSchemaIdentifierNameResolver.getIdentifierName(), + dataSourceSchemaIdentifierNameResolver.getIdentifierName()), STRUCT); + return new LogicalRelation(dataSourceSchemaIdentifierNameResolver.getIdentifierName(), tableFunctionImplementation.applyArguments()); } diff --git a/core/src/main/java/org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver.java b/core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java similarity index 56% rename from core/src/main/java/org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver.java rename to core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java index 7e0d2af028..f3552b029b 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver.java +++ b/core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java @@ -10,29 +10,31 @@ import java.util.List; import java.util.Set; -public class CatalogSchemaIdentifierNameResolver { +public class DataSourceSchemaIdentifierNameResolver { - public static final String DEFAULT_CATALOG_NAME = "@opensearch"; + public static final String DEFAULT_DATASOURCE_NAME = "@opensearch"; public static final String DEFAULT_SCHEMA_NAME = "default"; public static final String INFORMATION_SCHEMA_NAME = "information_schema"; - private String catalogName = DEFAULT_CATALOG_NAME; + private String dataSourceName = DEFAULT_DATASOURCE_NAME; private String schemaName = DEFAULT_SCHEMA_NAME; private String identifierName; private static final String DOT = "."; /** - * Data model for capturing catalog, schema and identifier from + * Data model for capturing dataSourceName, schema and identifier from * fully qualifiedName. In the current state, it is used to capture - * CatalogSchemaTable name and CatalogSchemaFunction in case of table + * DataSourceSchemaTable name and DataSourceSchemaFunction in case of table * functions. * * @param parts parts of qualifiedName. - * @param allowedCatalogs allowedCatalogs. + * @param allowedDataSources allowedDataSources. */ - public CatalogSchemaIdentifierNameResolver(List parts, Set allowedCatalogs) { - List remainingParts = captureSchemaName(captureCatalogName(parts, allowedCatalogs)); + public DataSourceSchemaIdentifierNameResolver(List parts, + Set allowedDataSources) { + List remainingParts + = captureSchemaName(captureDataSourceName(parts, allowedDataSources)); identifierName = String.join(DOT, remainingParts); } @@ -40,8 +42,8 @@ public String getIdentifierName() { return identifierName; } - public String getCatalogName() { - return catalogName; + public String getDataSourceName() { + return dataSourceName; } public String getSchemaName() { @@ -49,12 +51,12 @@ public String getSchemaName() { } - // Capture catalog name and return remaining parts(schema name and table name) + // Capture datasource name and return remaining parts(schema name and table name) // from the fully qualified name. - private List captureCatalogName(List parts, Set allowedCatalogs) { - if (parts.size() > 1 && allowedCatalogs.contains(parts.get(0)) - || DEFAULT_CATALOG_NAME.equals(parts.get(0))) { - catalogName = parts.get(0); + private List captureDataSourceName(List parts, Set allowedDataSources) { + if (parts.size() > 1 && allowedDataSources.contains(parts.get(0)) + || DEFAULT_DATASOURCE_NAME.equals(parts.get(0))) { + dataSourceName = parts.get(0); return parts.subList(1, parts.size()); } else { return parts; diff --git a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java index 9885302a69..a3ba9b1b6b 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java @@ -22,7 +22,6 @@ import org.opensearch.sql.ast.expression.AggregateFunction; import org.opensearch.sql.ast.expression.AllFields; import org.opensearch.sql.ast.expression.And; -import org.opensearch.sql.ast.expression.Argument; import org.opensearch.sql.ast.expression.Case; import org.opensearch.sql.ast.expression.Cast; import org.opensearch.sql.ast.expression.Compare; @@ -74,7 +73,6 @@ public class ExpressionAnalyzer extends AbstractNodeVisitor { @Getter private final BuiltinFunctionRepository repository; - private final DSL dsl; @Override public Expression visitCast(Cast node, AnalysisContext context) { @@ -86,7 +84,6 @@ public Expression visitCast(Cast node, AnalysisContext context) { public ExpressionAnalyzer( BuiltinFunctionRepository repository) { this.repository = repository; - this.dsl = new DSL(repository); } public Expression analyze(UnresolvedExpression unresolved, AnalysisContext context) { @@ -103,7 +100,7 @@ public Expression visitEqualTo(EqualTo node, AnalysisContext context) { Expression left = node.getLeft().accept(this, context); Expression right = node.getRight().accept(this, context); - return dsl.equal(left, right); + return DSL.equal(left, right); } @Override @@ -116,7 +113,7 @@ public Expression visitLiteral(Literal node, AnalysisContext context) { public Expression visitInterval(Interval node, AnalysisContext context) { Expression value = node.getValue().accept(this, context); Expression unit = DSL.literal(node.getUnit().name()); - return dsl.interval(value, unit); + return DSL.interval(value, unit); } @Override @@ -124,7 +121,7 @@ public Expression visitAnd(And node, AnalysisContext context) { Expression left = node.getLeft().accept(this, context); Expression right = node.getRight().accept(this, context); - return dsl.and(left, right); + return DSL.and(left, right); } @Override @@ -132,7 +129,7 @@ public Expression visitOr(Or node, AnalysisContext context) { Expression left = node.getLeft().accept(this, context); Expression right = node.getRight().accept(this, context); - return dsl.or(left, right); + return DSL.or(left, right); } @Override @@ -140,12 +137,12 @@ public Expression visitXor(Xor node, AnalysisContext context) { Expression left = node.getLeft().accept(this, context); Expression right = node.getRight().accept(this, context); - return dsl.xor(left, right); + return DSL.xor(left, right); } @Override public Expression visitNot(Not node, AnalysisContext context) { - return dsl.not(node.getExpression().accept(this, context)); + return DSL.not(node.getExpression().accept(this, context)); } @Override @@ -226,7 +223,7 @@ private Expression visitIn( if (valueList.size() == 1) { return visitCompare(new Compare("=", field, valueList.get(0)), context); } else if (valueList.size() > 1) { - return dsl.or( + return DSL.or( visitCompare(new Compare("=", field, valueList.get(0)), context), visitIn(field, valueList.subList(1, valueList.size()), context)); } else { diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java b/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java index ef24597b90..8c3868329f 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java @@ -73,7 +73,7 @@ public String getAlias() { /** * Get Qualified name preservs parts of the user given identifiers. - * This can later be utilized to determine Catalog,Schema and Table Name during + * This can later be utilized to determine DataSource,Schema and Table Name during * Analyzer stage. So Passing QualifiedName directly to Analyzer Stage. * * @return TableQualifiedName. diff --git a/core/src/main/java/org/opensearch/sql/catalog/CatalogService.java b/core/src/main/java/org/opensearch/sql/catalog/CatalogService.java deleted file mode 100644 index 4c40920c7b..0000000000 --- a/core/src/main/java/org/opensearch/sql/catalog/CatalogService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.catalog; - -import java.util.Set; -import org.opensearch.sql.catalog.model.Catalog; -import org.opensearch.sql.storage.StorageEngine; - -/** - * Catalog Service manages catalogs. - */ -public interface CatalogService { - - /** - * Returns all catalog objects. - * - * @return Catalog Catalogs. - */ - Set getCatalogs(); - - /** - * Returns Catalog with corresponding to the catalog name. - * - * @param catalogName Name of the catalog. - * @return Catalog catalog. - */ - Catalog getCatalog(String catalogName); - - /** - * Default opensearch engine is not defined in catalog.json. - * So the registration of default catalog happens separately. - * - * @param storageEngine StorageEngine. - */ - void registerDefaultOpenSearchCatalog(StorageEngine storageEngine); - -} diff --git a/core/src/main/java/org/opensearch/sql/catalog/model/CatalogMetadata.java b/core/src/main/java/org/opensearch/sql/catalog/model/CatalogMetadata.java deleted file mode 100644 index a859090a5d..0000000000 --- a/core/src/main/java/org/opensearch/sql/catalog/model/CatalogMetadata.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.catalog.model; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; -import lombok.Getter; -import lombok.Setter; - -@JsonIgnoreProperties(ignoreUnknown = true) -@Getter -@Setter -public class CatalogMetadata { - - @JsonProperty(required = true) - private String name; - - @JsonProperty(required = true) - @JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) - private ConnectorType connector; - - @JsonProperty(required = true) - private Map properties; - -} diff --git a/core/src/main/java/org/opensearch/sql/catalog/model/ConnectorType.java b/core/src/main/java/org/opensearch/sql/catalog/model/ConnectorType.java deleted file mode 100644 index b84c68adbf..0000000000 --- a/core/src/main/java/org/opensearch/sql/catalog/model/ConnectorType.java +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.catalog.model; - -public enum ConnectorType { - PROMETHEUS,OPENSEARCH -} diff --git a/core/src/main/java/org/opensearch/sql/datasource/DataSourceService.java b/core/src/main/java/org/opensearch/sql/datasource/DataSourceService.java new file mode 100644 index 0000000000..37e6f8e085 --- /dev/null +++ b/core/src/main/java/org/opensearch/sql/datasource/DataSourceService.java @@ -0,0 +1,43 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.datasource; + +import java.util.Set; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; + +/** + * DataSource Service manage {@link DataSource}. + */ +public interface DataSourceService { + + /** + * Returns all DataSource objects. + * + * @return set of {@link DataSource}. + */ + Set getDataSources(); + + /** + * Returns {@link DataSource} with corresponding to the DataSource name. + * + * @param dataSourceName Name of the {@link DataSource}. + * @return {@link DataSource}. + */ + DataSource getDataSource(String dataSourceName); + + /** + * Register {@link DataSource} defined by {@link DataSourceMetadata}. + * + * @param metadatas list of {@link DataSourceMetadata}. + */ + void addDataSource(DataSourceMetadata... metadatas); + + /** + * remove all the registered {@link DataSource}. + */ + void clear(); +} diff --git a/core/src/main/java/org/opensearch/sql/datasource/DataSourceServiceImpl.java b/core/src/main/java/org/opensearch/sql/datasource/DataSourceServiceImpl.java new file mode 100644 index 0000000000..274024e548 --- /dev/null +++ b/core/src/main/java/org/opensearch/sql/datasource/DataSourceServiceImpl.java @@ -0,0 +1,99 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.datasource; + +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +import org.opensearch.sql.common.utils.StringUtils; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.storage.DataSourceFactory; + +/** + * Default implementation of {@link DataSourceService}. It is per-jvm single instance. + * + *

{@link DataSourceService} is constructed by the list of {@link DataSourceFactory} at service + * bootstrap time. The set of {@link DataSourceFactory} is immutable. Client could add {@link + * DataSource} defined by {@link DataSourceMetadata} at any time. {@link DataSourceService} use + * {@link DataSourceFactory} to create {@link DataSource}. + */ +public class DataSourceServiceImpl implements DataSourceService { + + private static String DATASOURCE_NAME_REGEX = "[@*A-Za-z]+?[*a-zA-Z_\\-0-9]*"; + + private final ConcurrentHashMap dataSourceMap; + + private final Map dataSourceFactoryMap; + + /** + * Construct from the set of {@link DataSourceFactory} at bootstrap time. + */ + public DataSourceServiceImpl(Set dataSourceFactories) { + dataSourceFactoryMap = + dataSourceFactories.stream() + .collect(Collectors.toMap(DataSourceFactory::getDataSourceType, f -> f)); + dataSourceMap = new ConcurrentHashMap<>(); + } + + @Override + public Set getDataSources() { + return Set.copyOf(dataSourceMap.values()); + } + + @Override + public DataSource getDataSource(String dataSourceName) { + if (!dataSourceMap.containsKey(dataSourceName)) { + throw new IllegalArgumentException( + String.format("DataSource with name %s doesn't exist.", dataSourceName)); + } + return dataSourceMap.get(dataSourceName); + } + + @Override + public void addDataSource(DataSourceMetadata... metadatas) { + for (DataSourceMetadata metadata : metadatas) { + validateDataSourceMetaData(metadata); + dataSourceMap.put( + metadata.getName(), + dataSourceFactoryMap.get(metadata.getConnector()).createDataSource(metadata)); + } + } + + @Override + public void clear() { + dataSourceMap.clear(); + } + + /** + * This can be moved to a different validator class when we introduce more connectors. + * + * @param metadata {@link DataSourceMetadata}. + */ + private void validateDataSourceMetaData(DataSourceMetadata metadata) { + Preconditions.checkArgument( + !Strings.isNullOrEmpty(metadata.getName()), + "Missing Name Field from a DataSource. Name is a required parameter."); + Preconditions.checkArgument( + !dataSourceMap.containsKey(metadata.getName()), + StringUtils.format( + "Datasource name should be unique, Duplicate datasource found %s.", + metadata.getName())); + Preconditions.checkArgument( + metadata.getName().matches(DATASOURCE_NAME_REGEX), + StringUtils.format( + "DataSource Name: %s contains illegal characters. Allowed characters: a-zA-Z0-9_-*@.", + metadata.getName())); + Preconditions.checkArgument( + !Objects.isNull(metadata.getProperties()), + "Missing properties field in catalog configuration. Properties are required parameters."); + } +} diff --git a/core/src/main/java/org/opensearch/sql/catalog/model/Catalog.java b/core/src/main/java/org/opensearch/sql/datasource/model/DataSource.java similarity index 66% rename from core/src/main/java/org/opensearch/sql/catalog/model/Catalog.java rename to core/src/main/java/org/opensearch/sql/datasource/model/DataSource.java index 5b7eaca523..5deb460961 100644 --- a/core/src/main/java/org/opensearch/sql/catalog/model/Catalog.java +++ b/core/src/main/java/org/opensearch/sql/datasource/model/DataSource.java @@ -5,21 +5,24 @@ * */ -package org.opensearch.sql.catalog.model; +package org.opensearch.sql.datasource.model; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.opensearch.sql.storage.StorageEngine; +/** + * Each user configured datasource mapping to one instance of DataSource per JVM. + */ @Getter @RequiredArgsConstructor @EqualsAndHashCode -public class Catalog { +public class DataSource { private final String name; - private final ConnectorType connectorType; + private final DataSourceType connectorType; @EqualsAndHashCode.Exclude private final StorageEngine storageEngine; diff --git a/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java b/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java new file mode 100644 index 0000000000..f97d272bb9 --- /dev/null +++ b/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java @@ -0,0 +1,48 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.datasource.model; + + +import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import org.opensearch.sql.datasource.DataSourceService; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +@Setter +@EqualsAndHashCode +public class DataSourceMetadata { + + @JsonProperty(required = true) + private String name; + + @JsonProperty(required = true) + @JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) + private DataSourceType connector; + + @JsonProperty(required = true) + private Map properties; + + /** + * Default OpenSearch {@link DataSourceMetadata}. Which is used to register default OpenSearch + * {@link DataSource} to {@link DataSourceService}. + */ + public static DataSourceMetadata defaultOpenSearchDataSourceMetadata() { + DataSourceMetadata dataSourceMetadata = new DataSourceMetadata(); + dataSourceMetadata.setName(DEFAULT_DATASOURCE_NAME); + dataSourceMetadata.setConnector(DataSourceType.OPENSEARCH); + dataSourceMetadata.setProperties(ImmutableMap.of()); + return dataSourceMetadata; + } +} diff --git a/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceType.java b/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceType.java new file mode 100644 index 0000000000..1895b431c7 --- /dev/null +++ b/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceType.java @@ -0,0 +1,12 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.datasource.model; + +public enum DataSourceType { + PROMETHEUS, + OPENSEARCH, + FILESYSTEM +} diff --git a/core/src/main/java/org/opensearch/sql/catalog/model/auth/AuthenticationType.java b/core/src/main/java/org/opensearch/sql/datasource/model/auth/AuthenticationType.java similarity index 89% rename from core/src/main/java/org/opensearch/sql/catalog/model/auth/AuthenticationType.java rename to core/src/main/java/org/opensearch/sql/datasource/model/auth/AuthenticationType.java index 1157d8e497..9cf3e01509 100644 --- a/core/src/main/java/org/opensearch/sql/catalog/model/auth/AuthenticationType.java +++ b/core/src/main/java/org/opensearch/sql/datasource/model/auth/AuthenticationType.java @@ -5,12 +5,11 @@ * */ -package org.opensearch.sql.catalog.model.auth; +package org.opensearch.sql.datasource.model.auth; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; public enum AuthenticationType { 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 e7c94bea7c..4ba4f4fe45 100644 --- a/core/src/main/java/org/opensearch/sql/expression/DSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/DSL.java @@ -7,21 +7,18 @@ package org.opensearch.sql.expression; import java.util.Arrays; -import java.util.Collections; -import lombok.RequiredArgsConstructor; import org.opensearch.sql.ast.expression.SpanUnit; import org.opensearch.sql.data.model.ExprShortValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.model.ExprValueUtils; -import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.aggregation.Aggregator; import org.opensearch.sql.expression.aggregation.NamedAggregator; import org.opensearch.sql.expression.conditional.cases.CaseClause; import org.opensearch.sql.expression.conditional.cases.WhenClause; -import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.BuiltinFunctionName; import org.opensearch.sql.expression.function.BuiltinFunctionRepository; +import org.opensearch.sql.expression.function.FunctionImplementation; import org.opensearch.sql.expression.parse.GrokExpression; import org.opensearch.sql.expression.parse.ParseExpression; import org.opensearch.sql.expression.parse.PatternsExpression; @@ -29,9 +26,10 @@ import org.opensearch.sql.expression.span.SpanExpression; import org.opensearch.sql.expression.window.ranking.RankingWindowFunction; -@RequiredArgsConstructor public class DSL { - private final BuiltinFunctionRepository repository; + + private DSL() { + } public static LiteralExpression literal(Byte value) { return new LiteralExpression(ExprValueUtils.byteValue(value)); @@ -124,7 +122,7 @@ public static NamedArgumentExpression namedArgument(String argName, Expression v return new NamedArgumentExpression(argName, value); } - public NamedArgumentExpression namedArgument(String name, String value) { + public static NamedArgumentExpression namedArgument(String name, String value) { return namedArgument(name, literal(value)); } @@ -147,465 +145,456 @@ public static SpanExpression span(Expression field, Expression value, String uni return new SpanExpression(field, value, SpanUnit.of(unit)); } - public FunctionExpression abs(Expression... expressions) { - return function(BuiltinFunctionName.ABS, expressions); + public static FunctionExpression abs(Expression... expressions) { + return compile(BuiltinFunctionName.ABS, expressions); } - public FunctionExpression ceil(Expression... expressions) { - return function(BuiltinFunctionName.CEIL, expressions); + public static FunctionExpression ceil(Expression... expressions) { + return compile(BuiltinFunctionName.CEIL, expressions); } - public FunctionExpression ceiling(Expression... expressions) { - return function(BuiltinFunctionName.CEILING, expressions); + public static FunctionExpression ceiling(Expression... expressions) { + return compile(BuiltinFunctionName.CEILING, expressions); } - public FunctionExpression conv(Expression... expressions) { - return function(BuiltinFunctionName.CONV, expressions); + public static FunctionExpression conv(Expression... expressions) { + return compile(BuiltinFunctionName.CONV, expressions); } - public FunctionExpression crc32(Expression... expressions) { - return function(BuiltinFunctionName.CRC32, expressions); + public static FunctionExpression crc32(Expression... expressions) { + return compile(BuiltinFunctionName.CRC32, expressions); } - public FunctionExpression euler(Expression... expressions) { - return function(BuiltinFunctionName.E, expressions); + public static FunctionExpression euler(Expression... expressions) { + return compile(BuiltinFunctionName.E, expressions); } - public FunctionExpression exp(Expression... expressions) { - return function(BuiltinFunctionName.EXP, expressions); + public static FunctionExpression exp(Expression... expressions) { + return compile(BuiltinFunctionName.EXP, expressions); } - public FunctionExpression floor(Expression... expressions) { - return function(BuiltinFunctionName.FLOOR, expressions); + public static FunctionExpression floor(Expression... expressions) { + return compile(BuiltinFunctionName.FLOOR, expressions); } - public FunctionExpression ln(Expression... expressions) { - return function(BuiltinFunctionName.LN, expressions); + public static FunctionExpression ln(Expression... expressions) { + return compile(BuiltinFunctionName.LN, expressions); } - public FunctionExpression log(Expression... expressions) { - return function(BuiltinFunctionName.LOG, expressions); + public static FunctionExpression log(Expression... expressions) { + return compile(BuiltinFunctionName.LOG, expressions); } - public FunctionExpression log10(Expression... expressions) { - return function(BuiltinFunctionName.LOG10, expressions); + public static FunctionExpression log10(Expression... expressions) { + return compile(BuiltinFunctionName.LOG10, expressions); } - public FunctionExpression log2(Expression... expressions) { - return function(BuiltinFunctionName.LOG2, expressions); + public static FunctionExpression log2(Expression... expressions) { + return compile(BuiltinFunctionName.LOG2, expressions); } - public FunctionExpression mod(Expression... expressions) { - return function(BuiltinFunctionName.MOD, expressions); + public static FunctionExpression mod(Expression... expressions) { + return compile(BuiltinFunctionName.MOD, expressions); } - public FunctionExpression pi(Expression... expressions) { - return function(BuiltinFunctionName.PI, expressions); + public static FunctionExpression pi(Expression... expressions) { + return compile(BuiltinFunctionName.PI, expressions); } - public FunctionExpression pow(Expression... expressions) { - return function(BuiltinFunctionName.POW, expressions); + public static FunctionExpression pow(Expression... expressions) { + return compile(BuiltinFunctionName.POW, expressions); } - public FunctionExpression power(Expression... expressions) { - return function(BuiltinFunctionName.POWER, expressions); + public static FunctionExpression power(Expression... expressions) { + return compile(BuiltinFunctionName.POWER, expressions); } - public FunctionExpression rand(Expression... expressions) { - return function(BuiltinFunctionName.RAND, expressions); + public static FunctionExpression rand(Expression... expressions) { + return compile(BuiltinFunctionName.RAND, expressions); } - public FunctionExpression round(Expression... expressions) { - return function(BuiltinFunctionName.ROUND, expressions); + public static FunctionExpression round(Expression... expressions) { + return compile(BuiltinFunctionName.ROUND, expressions); } - public FunctionExpression sign(Expression... expressions) { - return function(BuiltinFunctionName.SIGN, expressions); + public static FunctionExpression sign(Expression... expressions) { + return compile(BuiltinFunctionName.SIGN, expressions); } - public FunctionExpression sqrt(Expression... expressions) { - return function(BuiltinFunctionName.SQRT, expressions); + public static FunctionExpression sqrt(Expression... expressions) { + return compile(BuiltinFunctionName.SQRT, expressions); } - public FunctionExpression truncate(Expression... expressions) { - return function(BuiltinFunctionName.TRUNCATE, expressions); + public static FunctionExpression truncate(Expression... expressions) { + return compile(BuiltinFunctionName.TRUNCATE, expressions); } - public FunctionExpression acos(Expression... expressions) { - return function(BuiltinFunctionName.ACOS, expressions); + public static FunctionExpression acos(Expression... expressions) { + return compile(BuiltinFunctionName.ACOS, expressions); } - public FunctionExpression asin(Expression... expressions) { - return function(BuiltinFunctionName.ASIN, expressions); + public static FunctionExpression asin(Expression... expressions) { + return compile(BuiltinFunctionName.ASIN, expressions); } - public FunctionExpression atan(Expression... expressions) { - return function(BuiltinFunctionName.ATAN, expressions); + public static FunctionExpression atan(Expression... expressions) { + return compile(BuiltinFunctionName.ATAN, expressions); } - public FunctionExpression atan2(Expression... expressions) { - return function(BuiltinFunctionName.ATAN2, expressions); + public static FunctionExpression atan2(Expression... expressions) { + return compile(BuiltinFunctionName.ATAN2, expressions); } - public FunctionExpression cos(Expression... expressions) { - return function(BuiltinFunctionName.COS, expressions); + public static FunctionExpression cos(Expression... expressions) { + return compile(BuiltinFunctionName.COS, expressions); } - public FunctionExpression cot(Expression... expressions) { - return function(BuiltinFunctionName.COT, expressions); + public static FunctionExpression cot(Expression... expressions) { + return compile(BuiltinFunctionName.COT, expressions); } - public FunctionExpression degrees(Expression... expressions) { - return function(BuiltinFunctionName.DEGREES, expressions); + public static FunctionExpression degrees(Expression... expressions) { + return compile(BuiltinFunctionName.DEGREES, expressions); } - public FunctionExpression radians(Expression... expressions) { - return function(BuiltinFunctionName.RADIANS, expressions); + public static FunctionExpression radians(Expression... expressions) { + return compile(BuiltinFunctionName.RADIANS, expressions); } - public FunctionExpression sin(Expression... expressions) { - return function(BuiltinFunctionName.SIN, expressions); + public static FunctionExpression sin(Expression... expressions) { + return compile(BuiltinFunctionName.SIN, expressions); } - public FunctionExpression tan(Expression... expressions) { - return function(BuiltinFunctionName.TAN, expressions); + public static FunctionExpression tan(Expression... expressions) { + return compile(BuiltinFunctionName.TAN, expressions); } - public FunctionExpression add(Expression... expressions) { - return function(BuiltinFunctionName.ADD, expressions); + public static FunctionExpression add(Expression... expressions) { + return compile(BuiltinFunctionName.ADD, expressions); } - public FunctionExpression subtract(Expression... expressions) { - return function(BuiltinFunctionName.SUBTRACT, expressions); + public static FunctionExpression subtract(Expression... expressions) { + return compile(BuiltinFunctionName.SUBTRACT, expressions); } - public FunctionExpression multiply(Expression... expressions) { - return function(BuiltinFunctionName.MULTIPLY, expressions); + public static FunctionExpression multiply(Expression... expressions) { + return compile(BuiltinFunctionName.MULTIPLY, expressions); } - public FunctionExpression adddate(Expression... expressions) { - return function(BuiltinFunctionName.ADDDATE, expressions); + public static FunctionExpression adddate(Expression... expressions) { + return compile(BuiltinFunctionName.ADDDATE, expressions); } - public FunctionExpression convert_tz(Expression... expressions) { - return function(BuiltinFunctionName.CONVERT_TZ, expressions); + public static FunctionExpression convert_tz(Expression... expressions) { + return compile(BuiltinFunctionName.CONVERT_TZ, expressions); } - public FunctionExpression date(Expression... expressions) { - return function(BuiltinFunctionName.DATE, expressions); + public static FunctionExpression date(Expression... expressions) { + return compile(BuiltinFunctionName.DATE, expressions); } - public FunctionExpression datetime(Expression... expressions) { - return function(BuiltinFunctionName.DATETIME, expressions); + public static FunctionExpression datetime(Expression... expressions) { + return compile(BuiltinFunctionName.DATETIME, expressions); } - public FunctionExpression date_add(Expression... expressions) { - return function(BuiltinFunctionName.DATE_ADD, expressions); + public static FunctionExpression date_add(Expression... expressions) { + return compile(BuiltinFunctionName.DATE_ADD, expressions); } - public FunctionExpression date_sub(Expression... expressions) { - return function(BuiltinFunctionName.DATE_SUB, expressions); + public static FunctionExpression date_sub(Expression... expressions) { + return compile(BuiltinFunctionName.DATE_SUB, expressions); } - public FunctionExpression day(Expression... expressions) { - return function(BuiltinFunctionName.DAY, expressions); + public static FunctionExpression day(Expression... expressions) { + return compile(BuiltinFunctionName.DAY, expressions); } - public FunctionExpression dayname(Expression... expressions) { - return function(BuiltinFunctionName.DAYNAME, expressions); + public static FunctionExpression dayname(Expression... expressions) { + return compile(BuiltinFunctionName.DAYNAME, expressions); } - public FunctionExpression dayofmonth(Expression... expressions) { - return function(BuiltinFunctionName.DAYOFMONTH, expressions); + public static FunctionExpression dayofmonth(Expression... expressions) { + return compile(BuiltinFunctionName.DAYOFMONTH, expressions); } - public FunctionExpression dayofweek(Expression... expressions) { - return function(BuiltinFunctionName.DAYOFWEEK, expressions); + public static FunctionExpression dayofweek(Expression... expressions) { + return compile(BuiltinFunctionName.DAYOFWEEK, expressions); } - public FunctionExpression dayofyear(Expression... expressions) { - return function(BuiltinFunctionName.DAYOFYEAR, expressions); + public static FunctionExpression dayofyear(Expression... expressions) { + return compile(BuiltinFunctionName.DAYOFYEAR, expressions); } - public FunctionExpression from_days(Expression... expressions) { - return function(BuiltinFunctionName.FROM_DAYS, expressions); + public static FunctionExpression from_days(Expression... expressions) { + return compile(BuiltinFunctionName.FROM_DAYS, expressions); } - public FunctionExpression hour(Expression... expressions) { - return function(BuiltinFunctionName.HOUR, expressions); + public static FunctionExpression hour(Expression... expressions) { + return compile(BuiltinFunctionName.HOUR, expressions); } - public FunctionExpression microsecond(Expression... expressions) { - return function(BuiltinFunctionName.MICROSECOND, expressions); + public static FunctionExpression microsecond(Expression... expressions) { + return compile(BuiltinFunctionName.MICROSECOND, expressions); } - public FunctionExpression minute(Expression... expressions) { - return function(BuiltinFunctionName.MINUTE, expressions); + public static FunctionExpression minute(Expression... expressions) { + return compile(BuiltinFunctionName.MINUTE, expressions); } - public FunctionExpression month(Expression... expressions) { - return function(BuiltinFunctionName.MONTH, expressions); + public static FunctionExpression month(Expression... expressions) { + return compile(BuiltinFunctionName.MONTH, expressions); } - public FunctionExpression monthname(Expression... expressions) { - return function(BuiltinFunctionName.MONTHNAME, expressions); + public static FunctionExpression monthname(Expression... expressions) { + return compile(BuiltinFunctionName.MONTHNAME, expressions); } - public FunctionExpression quarter(Expression... expressions) { - return function(BuiltinFunctionName.QUARTER, expressions); + public static FunctionExpression quarter(Expression... expressions) { + return compile(BuiltinFunctionName.QUARTER, expressions); } - public FunctionExpression second(Expression... expressions) { - return function(BuiltinFunctionName.SECOND, expressions); + public static FunctionExpression second(Expression... expressions) { + return compile(BuiltinFunctionName.SECOND, expressions); } - public FunctionExpression subdate(Expression... expressions) { - return function(BuiltinFunctionName.SUBDATE, expressions); + public static FunctionExpression subdate(Expression... expressions) { + return compile(BuiltinFunctionName.SUBDATE, expressions); } - public FunctionExpression time(Expression... expressions) { - return function(BuiltinFunctionName.TIME, expressions); + public static FunctionExpression time(Expression... expressions) { + return compile(BuiltinFunctionName.TIME, expressions); } - public FunctionExpression time_to_sec(Expression... expressions) { - return function(BuiltinFunctionName.TIME_TO_SEC, expressions); + public static FunctionExpression time_to_sec(Expression... expressions) { + return compile(BuiltinFunctionName.TIME_TO_SEC, expressions); } - public FunctionExpression timestamp(Expression... expressions) { - return function(BuiltinFunctionName.TIMESTAMP, expressions); + public static FunctionExpression timestamp(Expression... expressions) { + return compile(BuiltinFunctionName.TIMESTAMP, expressions); } - public FunctionExpression date_format(Expression... expressions) { - return function(BuiltinFunctionName.DATE_FORMAT, expressions); + public static FunctionExpression date_format(Expression... expressions) { + return compile(BuiltinFunctionName.DATE_FORMAT, expressions); } - public FunctionExpression to_days(Expression... expressions) { - return function(BuiltinFunctionName.TO_DAYS, expressions); + public static FunctionExpression to_days(Expression... expressions) { + return compile(BuiltinFunctionName.TO_DAYS, expressions); } - public FunctionExpression week(Expression... expressions) { - return function(BuiltinFunctionName.WEEK, expressions); + public static FunctionExpression week(Expression... expressions) { + return compile(BuiltinFunctionName.WEEK, expressions); } - public FunctionExpression year(Expression... expressions) { - return function(BuiltinFunctionName.YEAR, expressions); + public static FunctionExpression year(Expression... expressions) { + return compile(BuiltinFunctionName.YEAR, expressions); } - public FunctionExpression divide(Expression... expressions) { - return function(BuiltinFunctionName.DIVIDE, expressions); + public static FunctionExpression divide(Expression... expressions) { + return compile(BuiltinFunctionName.DIVIDE, expressions); } - public FunctionExpression module(Expression... expressions) { - return function(BuiltinFunctionName.MODULES, expressions); + public static FunctionExpression module(Expression... expressions) { + return compile(BuiltinFunctionName.MODULES, expressions); } - public FunctionExpression substr(Expression... expressions) { - return function(BuiltinFunctionName.SUBSTR, expressions); + public static FunctionExpression substr(Expression... expressions) { + return compile(BuiltinFunctionName.SUBSTR, expressions); } - public FunctionExpression substring(Expression... expressions) { - return function(BuiltinFunctionName.SUBSTR, expressions); + public static FunctionExpression substring(Expression... expressions) { + return compile(BuiltinFunctionName.SUBSTR, expressions); } - public FunctionExpression ltrim(Expression... expressions) { - return function(BuiltinFunctionName.LTRIM, expressions); + public static FunctionExpression ltrim(Expression... expressions) { + return compile(BuiltinFunctionName.LTRIM, expressions); } - public FunctionExpression rtrim(Expression... expressions) { - return function(BuiltinFunctionName.RTRIM, expressions); + public static FunctionExpression rtrim(Expression... expressions) { + return compile(BuiltinFunctionName.RTRIM, expressions); } - public FunctionExpression trim(Expression... expressions) { - return function(BuiltinFunctionName.TRIM, expressions); + public static FunctionExpression trim(Expression... expressions) { + return compile(BuiltinFunctionName.TRIM, expressions); } - public FunctionExpression upper(Expression... expressions) { - return function(BuiltinFunctionName.UPPER, expressions); + public static FunctionExpression upper(Expression... expressions) { + return compile(BuiltinFunctionName.UPPER, expressions); } - public FunctionExpression lower(Expression... expressions) { - return function(BuiltinFunctionName.LOWER, expressions); + public static FunctionExpression lower(Expression... expressions) { + return compile(BuiltinFunctionName.LOWER, expressions); } - public FunctionExpression regexp(Expression... expressions) { - return function(BuiltinFunctionName.REGEXP, expressions); + public static FunctionExpression regexp(Expression... expressions) { + return compile(BuiltinFunctionName.REGEXP, expressions); } - public FunctionExpression concat(Expression... expressions) { - return function(BuiltinFunctionName.CONCAT, expressions); + public static FunctionExpression concat(Expression... expressions) { + return compile(BuiltinFunctionName.CONCAT, expressions); } - public FunctionExpression concat_ws(Expression... expressions) { - return function(BuiltinFunctionName.CONCAT_WS, expressions); + public static FunctionExpression concat_ws(Expression... expressions) { + return compile(BuiltinFunctionName.CONCAT_WS, expressions); } - public FunctionExpression length(Expression... expressions) { - return function(BuiltinFunctionName.LENGTH, expressions); + public static FunctionExpression length(Expression... expressions) { + return compile(BuiltinFunctionName.LENGTH, expressions); } - public FunctionExpression strcmp(Expression... expressions) { - return function(BuiltinFunctionName.STRCMP, expressions); + public static FunctionExpression strcmp(Expression... expressions) { + return compile(BuiltinFunctionName.STRCMP, expressions); } - public FunctionExpression right(Expression... expressions) { - return function(BuiltinFunctionName.RIGHT, expressions); + public static FunctionExpression right(Expression... expressions) { + return compile(BuiltinFunctionName.RIGHT, expressions); } - public FunctionExpression left(Expression... expressions) { - return function(BuiltinFunctionName.LEFT, expressions); + public static FunctionExpression left(Expression... expressions) { + return compile(BuiltinFunctionName.LEFT, expressions); } - public FunctionExpression ascii(Expression... expressions) { - return function(BuiltinFunctionName.ASCII, expressions); + public static FunctionExpression ascii(Expression... expressions) { + return compile(BuiltinFunctionName.ASCII, expressions); } - public FunctionExpression locate(Expression... expressions) { - return function(BuiltinFunctionName.LOCATE, expressions); + public static FunctionExpression locate(Expression... expressions) { + return compile(BuiltinFunctionName.LOCATE, expressions); } - public FunctionExpression replace(Expression... expressions) { - return function(BuiltinFunctionName.REPLACE, expressions); + public static FunctionExpression replace(Expression... expressions) { + return compile(BuiltinFunctionName.REPLACE, expressions); } - public FunctionExpression and(Expression... expressions) { - return function(BuiltinFunctionName.AND, expressions); + public static FunctionExpression and(Expression... expressions) { + return compile(BuiltinFunctionName.AND, expressions); } - public FunctionExpression or(Expression... expressions) { - return function(BuiltinFunctionName.OR, expressions); + public static FunctionExpression or(Expression... expressions) { + return compile(BuiltinFunctionName.OR, expressions); } - public FunctionExpression xor(Expression... expressions) { - return function(BuiltinFunctionName.XOR, expressions); + public static FunctionExpression xor(Expression... expressions) { + return compile(BuiltinFunctionName.XOR, expressions); } - public FunctionExpression not(Expression... expressions) { - return function(BuiltinFunctionName.NOT, expressions); + public static FunctionExpression not(Expression... expressions) { + return compile(BuiltinFunctionName.NOT, expressions); } - public FunctionExpression equal(Expression... expressions) { - return function(BuiltinFunctionName.EQUAL, expressions); + public static FunctionExpression equal(Expression... expressions) { + return compile(BuiltinFunctionName.EQUAL, expressions); } - public FunctionExpression notequal(Expression... expressions) { - return function(BuiltinFunctionName.NOTEQUAL, expressions); + public static FunctionExpression notequal(Expression... expressions) { + return compile(BuiltinFunctionName.NOTEQUAL, expressions); } - public FunctionExpression less(Expression... expressions) { - return function(BuiltinFunctionName.LESS, expressions); + public static FunctionExpression less(Expression... expressions) { + return compile(BuiltinFunctionName.LESS, expressions); } - public FunctionExpression lte(Expression... expressions) { - return function(BuiltinFunctionName.LTE, expressions); + public static FunctionExpression lte(Expression... expressions) { + return compile(BuiltinFunctionName.LTE, expressions); } - public FunctionExpression greater(Expression... expressions) { - return function(BuiltinFunctionName.GREATER, expressions); + public static FunctionExpression greater(Expression... expressions) { + return compile(BuiltinFunctionName.GREATER, expressions); } - public FunctionExpression gte(Expression... expressions) { - return function(BuiltinFunctionName.GTE, expressions); + public static FunctionExpression gte(Expression... expressions) { + return compile(BuiltinFunctionName.GTE, expressions); } - public FunctionExpression like(Expression... expressions) { - return function(BuiltinFunctionName.LIKE, expressions); + public static FunctionExpression like(Expression... expressions) { + return compile(BuiltinFunctionName.LIKE, expressions); } - public FunctionExpression notLike(Expression... expressions) { - return function(BuiltinFunctionName.NOT_LIKE, expressions); + public static FunctionExpression notLike(Expression... expressions) { + return compile(BuiltinFunctionName.NOT_LIKE, expressions); } - public Aggregator avg(Expression... expressions) { + public static Aggregator avg(Expression... expressions) { return aggregate(BuiltinFunctionName.AVG, expressions); } - public Aggregator sum(Expression... expressions) { + public static Aggregator sum(Expression... expressions) { return aggregate(BuiltinFunctionName.SUM, expressions); } - public Aggregator count(Expression... expressions) { + public static Aggregator count(Expression... expressions) { return aggregate(BuiltinFunctionName.COUNT, expressions); } - public Aggregator distinctCount(Expression... expressions) { + public static Aggregator distinctCount(Expression... expressions) { return count(expressions).distinct(true); } - public Aggregator varSamp(Expression... expressions) { + public static Aggregator varSamp(Expression... expressions) { return aggregate(BuiltinFunctionName.VARSAMP, expressions); } - public Aggregator varPop(Expression... expressions) { + public static Aggregator varPop(Expression... expressions) { return aggregate(BuiltinFunctionName.VARPOP, expressions); } - public Aggregator stddevSamp(Expression... expressions) { + public static Aggregator stddevSamp(Expression... expressions) { return aggregate(BuiltinFunctionName.STDDEV_SAMP, expressions); } - public Aggregator stddevPop(Expression... expressions) { + public static Aggregator stddevPop(Expression... expressions) { return aggregate(BuiltinFunctionName.STDDEV_POP, expressions); } - public Aggregator take(Expression... expressions) { + public static Aggregator take(Expression... expressions) { return aggregate(BuiltinFunctionName.TAKE, expressions); } - public RankingWindowFunction rowNumber() { - return (RankingWindowFunction) repository.compile( - BuiltinFunctionName.ROW_NUMBER.getName(), Collections.emptyList()); + public static RankingWindowFunction rowNumber() { + return compile(BuiltinFunctionName.ROW_NUMBER); } - public RankingWindowFunction rank() { - return (RankingWindowFunction) repository.compile( - BuiltinFunctionName.RANK.getName(), Collections.emptyList()); + public static RankingWindowFunction rank() { + return compile(BuiltinFunctionName.RANK); } - public RankingWindowFunction denseRank() { - return (RankingWindowFunction) repository.compile( - BuiltinFunctionName.DENSE_RANK.getName(), Collections.emptyList()); + public static RankingWindowFunction denseRank() { + return compile(BuiltinFunctionName.DENSE_RANK); } - public Aggregator min(Expression... expressions) { + public static Aggregator min(Expression... expressions) { return aggregate(BuiltinFunctionName.MIN, expressions); } - public Aggregator max(Expression... expressions) { + public static Aggregator max(Expression... expressions) { return aggregate(BuiltinFunctionName.MAX, expressions); } - private FunctionExpression function(BuiltinFunctionName functionName, Expression... expressions) { - return (FunctionExpression) repository.compile( - functionName.getName(), Arrays.asList(expressions)); - } - - private Aggregator aggregate(BuiltinFunctionName functionName, Expression... expressions) { - return (Aggregator) repository.compile( - functionName.getName(), Arrays.asList(expressions)); + private static Aggregator aggregate(BuiltinFunctionName functionName, Expression... expressions) { + return compile(functionName, expressions); } - public FunctionExpression isnull(Expression... expressions) { - return function(BuiltinFunctionName.ISNULL, expressions); + public static FunctionExpression isnull(Expression... expressions) { + return compile(BuiltinFunctionName.ISNULL, expressions); } - public FunctionExpression is_null(Expression... expressions) { - return function(BuiltinFunctionName.IS_NULL, expressions); + public static FunctionExpression is_null(Expression... expressions) { + return compile(BuiltinFunctionName.IS_NULL, expressions); } - public FunctionExpression isnotnull(Expression... expressions) { - return function(BuiltinFunctionName.IS_NOT_NULL, expressions); + public static FunctionExpression isnotnull(Expression... expressions) { + return compile(BuiltinFunctionName.IS_NOT_NULL, expressions); } - public FunctionExpression ifnull(Expression... expressions) { - return function(BuiltinFunctionName.IFNULL, expressions); + public static FunctionExpression ifnull(Expression... expressions) { + return compile(BuiltinFunctionName.IFNULL, expressions); } - public FunctionExpression nullif(Expression... expressions) { - return function(BuiltinFunctionName.NULLIF, expressions); + public static FunctionExpression nullif(Expression... expressions) { + return compile(BuiltinFunctionName.NULLIF, expressions); } - public FunctionExpression iffunction(Expression... expressions) { - return function(BuiltinFunctionName.IF, expressions); + public static FunctionExpression iffunction(Expression... expressions) { + return compile(BuiltinFunctionName.IF, expressions); } public static Expression cases(Expression defaultResult, @@ -617,145 +606,133 @@ public static WhenClause when(Expression condition, Expression result) { return new WhenClause(condition, result); } - public FunctionExpression interval(Expression value, Expression unit) { - return (FunctionExpression) repository.compile( - BuiltinFunctionName.INTERVAL.getName(), Arrays.asList(value, unit)); + public static FunctionExpression interval(Expression value, Expression unit) { + return compile(BuiltinFunctionName.INTERVAL, value, unit); } - public FunctionExpression castString(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_STRING.getName(), Arrays.asList(value)); + public static FunctionExpression castString(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_STRING, value); } - public FunctionExpression castByte(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_BYTE.getName(), Arrays.asList(value)); + public static FunctionExpression castByte(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_BYTE, value); } - public FunctionExpression castShort(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_SHORT.getName(), Arrays.asList(value)); + public static FunctionExpression castShort(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_SHORT, value); } - public FunctionExpression castInt(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_INT.getName(), Arrays.asList(value)); + public static FunctionExpression castInt(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_INT, value); } - public FunctionExpression castLong(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_LONG.getName(), Arrays.asList(value)); + public static FunctionExpression castLong(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_LONG, value); } - public FunctionExpression castFloat(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_FLOAT.getName(), Arrays.asList(value)); + public static FunctionExpression castFloat(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_FLOAT, value); } - public FunctionExpression castDouble(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_DOUBLE.getName(), Arrays.asList(value)); + public static FunctionExpression castDouble(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_DOUBLE, value); } - public FunctionExpression castBoolean(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_BOOLEAN.getName(), Arrays.asList(value)); + public static FunctionExpression castBoolean(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_BOOLEAN, value); } - public FunctionExpression castDate(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_DATE.getName(), Arrays.asList(value)); + public static FunctionExpression castDate(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_DATE, value); } - public FunctionExpression castTime(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_TIME.getName(), Arrays.asList(value)); + public static FunctionExpression castTime(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_TIME, value); } - public FunctionExpression castTimestamp(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_TIMESTAMP.getName(), Arrays.asList(value)); + public static FunctionExpression castTimestamp(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_TIMESTAMP, value); } - public FunctionExpression castDatetime(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.CAST_TO_DATETIME.getName(), Arrays.asList(value)); + public static FunctionExpression castDatetime(Expression value) { + return compile(BuiltinFunctionName.CAST_TO_DATETIME, value); } - public FunctionExpression typeof(Expression value) { - return (FunctionExpression) repository - .compile(BuiltinFunctionName.TYPEOF.getName(), Arrays.asList(value)); + public static FunctionExpression typeof(Expression value) { + return compile(BuiltinFunctionName.TYPEOF, value); } - public FunctionExpression match(Expression... args) { + public static FunctionExpression match(Expression... args) { return compile(BuiltinFunctionName.MATCH, args); } - public FunctionExpression match_phrase(Expression... args) { + public static FunctionExpression match_phrase(Expression... args) { return compile(BuiltinFunctionName.MATCH_PHRASE, args); } - public FunctionExpression match_phrase_prefix(Expression... args) { + public static FunctionExpression match_phrase_prefix(Expression... args) { return compile(BuiltinFunctionName.MATCH_PHRASE_PREFIX, args); } - public FunctionExpression multi_match(Expression... args) { + public static FunctionExpression multi_match(Expression... args) { return compile(BuiltinFunctionName.MULTI_MATCH, args); } - public FunctionExpression simple_query_string(Expression... args) { + public static FunctionExpression simple_query_string(Expression... args) { return compile(BuiltinFunctionName.SIMPLE_QUERY_STRING, args); } - public FunctionExpression query(Expression... args) { + public static FunctionExpression query(Expression... args) { return compile(BuiltinFunctionName.QUERY, args); } - public FunctionExpression query_string(Expression... args) { + public static FunctionExpression query_string(Expression... args) { return compile(BuiltinFunctionName.QUERY_STRING, args); } - public FunctionExpression match_bool_prefix(Expression... args) { + public static FunctionExpression match_bool_prefix(Expression... args) { return compile(BuiltinFunctionName.MATCH_BOOL_PREFIX, args); } - public FunctionExpression now(Expression... args) { + public static FunctionExpression now(Expression... args) { return compile(BuiltinFunctionName.NOW, args); } - public FunctionExpression current_timestamp(Expression... args) { + public static FunctionExpression current_timestamp(Expression... args) { return compile(BuiltinFunctionName.CURRENT_TIMESTAMP, args); } - public FunctionExpression localtimestamp(Expression... args) { + public static FunctionExpression localtimestamp(Expression... args) { return compile(BuiltinFunctionName.LOCALTIMESTAMP, args); } - public FunctionExpression localtime(Expression... args) { + public static FunctionExpression localtime(Expression... args) { return compile(BuiltinFunctionName.LOCALTIME, args); } - public FunctionExpression sysdate(Expression... args) { + public static FunctionExpression sysdate(Expression... args) { return compile(BuiltinFunctionName.SYSDATE, args); } - public FunctionExpression curtime(Expression... args) { + public static FunctionExpression curtime(Expression... args) { return compile(BuiltinFunctionName.CURTIME, args); } - public FunctionExpression current_time(Expression... args) { + public static FunctionExpression current_time(Expression... args) { return compile(BuiltinFunctionName.CURRENT_TIME, args); } - public FunctionExpression curdate(Expression... args) { + public static FunctionExpression curdate(Expression... args) { return compile(BuiltinFunctionName.CURDATE, args); } - public FunctionExpression current_date(Expression... args) { + public static FunctionExpression current_date(Expression... args) { return compile(BuiltinFunctionName.CURRENT_DATE, args); } - private FunctionExpression compile(BuiltinFunctionName bfn, Expression... args) { - return (FunctionExpression) repository.compile(bfn.getName(), Arrays.asList(args.clone())); + @SuppressWarnings("unchecked") + private static + T compile(BuiltinFunctionName bfn, Expression... args) { + return (T) BuiltinFunctionRepository.getInstance().compile(bfn.getName(), Arrays.asList(args)); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/config/ExpressionConfig.java b/core/src/main/java/org/opensearch/sql/expression/config/ExpressionConfig.java deleted file mode 100644 index 9335512b11..0000000000 --- a/core/src/main/java/org/opensearch/sql/expression/config/ExpressionConfig.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - - -package org.opensearch.sql.expression.config; - -import java.util.HashMap; -import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.aggregation.AggregatorFunction; -import org.opensearch.sql.expression.datetime.DateTimeFunction; -import org.opensearch.sql.expression.datetime.IntervalClause; -import org.opensearch.sql.expression.function.BuiltinFunctionRepository; -import org.opensearch.sql.expression.function.OpenSearchFunctions; -import org.opensearch.sql.expression.operator.arthmetic.ArithmeticFunction; -import org.opensearch.sql.expression.operator.arthmetic.MathematicalFunction; -import org.opensearch.sql.expression.operator.convert.TypeCastOperator; -import org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperator; -import org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperator; -import org.opensearch.sql.expression.system.SystemFunctions; -import org.opensearch.sql.expression.text.TextFunction; -import org.opensearch.sql.expression.window.WindowFunctions; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Scope; - -/** - * Expression Config for Spring IoC. - */ -@Configuration -public class ExpressionConfig { - /** - * BuiltinFunctionRepository constructor. - */ - @Bean - @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public BuiltinFunctionRepository functionRepository() { - BuiltinFunctionRepository builtinFunctionRepository = - new BuiltinFunctionRepository(new HashMap<>()); - ArithmeticFunction.register(builtinFunctionRepository); - BinaryPredicateOperator.register(builtinFunctionRepository); - MathematicalFunction.register(builtinFunctionRepository); - UnaryPredicateOperator.register(builtinFunctionRepository); - AggregatorFunction.register(builtinFunctionRepository); - DateTimeFunction.register(builtinFunctionRepository); - IntervalClause.register(builtinFunctionRepository); - WindowFunctions.register(builtinFunctionRepository); - TextFunction.register(builtinFunctionRepository); - TypeCastOperator.register(builtinFunctionRepository); - SystemFunctions.register(builtinFunctionRepository); - OpenSearchFunctions.register(builtinFunctionRepository); - return builtinFunctionRepository; - } - - @Bean - @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public DSL dsl(BuiltinFunctionRepository repository) { - return new DSL(repository); - } -} 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 33f652d534..22c588e679 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 @@ -8,40 +8,83 @@ import static org.opensearch.sql.ast.expression.Cast.getCastFunctionName; import static org.opensearch.sql.ast.expression.Cast.isCastFunction; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.TreeSet; import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; import org.opensearch.sql.common.utils.StringUtils; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.exception.ExpressionEvaluationException; import org.opensearch.sql.expression.Expression; +import org.opensearch.sql.expression.aggregation.AggregatorFunction; +import org.opensearch.sql.expression.datetime.DateTimeFunction; +import org.opensearch.sql.expression.datetime.IntervalClause; +import org.opensearch.sql.expression.operator.arthmetic.ArithmeticFunction; +import org.opensearch.sql.expression.operator.arthmetic.MathematicalFunction; +import org.opensearch.sql.expression.operator.convert.TypeCastOperator; +import org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperator; +import org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperator; +import org.opensearch.sql.expression.system.SystemFunctions; +import org.opensearch.sql.expression.text.TextFunction; +import org.opensearch.sql.expression.window.WindowFunctions; /** * Builtin Function Repository. - * Repository registers catalog specific functions under catalog specific namespace and - * universal functions under default namespace. Catalog Specific Namespace carries their own - * namespace. + * Repository registers datasource specific functions under datasource namespace and + * universal functions under default namespace. * */ -@RequiredArgsConstructor public class BuiltinFunctionRepository { public static final String DEFAULT_NAMESPACE = "default"; private final Map> namespaceFunctionResolverMap; + /** The singleton instance. */ + private static BuiltinFunctionRepository instance; + + /** + * Construct a function repository with the given function registered. This is only used in test. + * + * @param namespaceFunctionResolverMap function supported + */ + @VisibleForTesting + BuiltinFunctionRepository( + Map> namespaceFunctionResolverMap) { + this.namespaceFunctionResolverMap = namespaceFunctionResolverMap; + } + + /** + * Get singleton instance of the function repository. Initialize it with all built-in functions + * for the first time in synchronized way. + * + * @return singleton instance + */ + public static synchronized BuiltinFunctionRepository getInstance() { + if (instance == null) { + instance = new BuiltinFunctionRepository(new HashMap<>()); + + // Register all built-in functions + ArithmeticFunction.register(instance); + BinaryPredicateOperator.register(instance); + MathematicalFunction.register(instance); + UnaryPredicateOperator.register(instance); + AggregatorFunction.register(instance); + DateTimeFunction.register(instance); + IntervalClause.register(instance); + WindowFunctions.register(instance); + TextFunction.register(instance); + TypeCastOperator.register(instance); + SystemFunctions.register(instance); + OpenSearchFunctions.register(instance); + } + return instance; + } /** * Register {@link DefaultFunctionResolver} to the Builtin Function Repository diff --git a/core/src/main/java/org/opensearch/sql/planner/optimizer/LogicalPlanOptimizer.java b/core/src/main/java/org/opensearch/sql/planner/optimizer/LogicalPlanOptimizer.java index 058cf8b9f5..0e547df68d 100644 --- a/core/src/main/java/org/opensearch/sql/planner/optimizer/LogicalPlanOptimizer.java +++ b/core/src/main/java/org/opensearch/sql/planner/optimizer/LogicalPlanOptimizer.java @@ -12,7 +12,6 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.opensearch.sql.expression.DSL; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.optimizer.rule.MergeFilterAndFilter; import org.opensearch.sql.planner.optimizer.rule.PushFilterUnderSort; @@ -38,9 +37,9 @@ public LogicalPlanOptimizer(List> rules) { /** * Create {@link LogicalPlanOptimizer} with pre-defined rules. */ - public static LogicalPlanOptimizer create(DSL dsl) { + public static LogicalPlanOptimizer create() { return new LogicalPlanOptimizer(Arrays.asList( - new MergeFilterAndFilter(dsl), + new MergeFilterAndFilter(), new PushFilterUnderSort())); } diff --git a/core/src/main/java/org/opensearch/sql/planner/optimizer/rule/MergeFilterAndFilter.java b/core/src/main/java/org/opensearch/sql/planner/optimizer/rule/MergeFilterAndFilter.java index 21e93fcb67..57763728d5 100644 --- a/core/src/main/java/org/opensearch/sql/planner/optimizer/rule/MergeFilterAndFilter.java +++ b/core/src/main/java/org/opensearch/sql/planner/optimizer/rule/MergeFilterAndFilter.java @@ -26,8 +26,6 @@ public class MergeFilterAndFilter implements Rule { private final Capture capture; - private final DSL dsl; - @Accessors(fluent = true) @Getter private final Pattern pattern; @@ -35,8 +33,7 @@ public class MergeFilterAndFilter implements Rule { /** * Constructor of MergeFilterAndFilter. */ - public MergeFilterAndFilter(DSL dsl) { - this.dsl = dsl; + public MergeFilterAndFilter() { this.capture = Capture.newCapture(); this.pattern = typeOf(LogicalFilter.class) .with(source().matching(typeOf(LogicalFilter.class).capturedAs(capture))); @@ -48,7 +45,7 @@ public LogicalPlan apply(LogicalFilter filter, LogicalFilter childFilter = captures.get(capture); return new LogicalFilter( childFilter.getChild().get(0), - dsl.and(filter.getCondition(), childFilter.getCondition()) + DSL.and(filter.getCondition(), childFilter.getCondition()) ); } } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTable.java b/core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTable.java similarity index 60% rename from core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTable.java rename to core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTable.java index 4e6a87e21b..105ad5ed32 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTable.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTable.java @@ -5,14 +5,14 @@ * */ -package org.opensearch.sql.planner.physical.catalog; +package org.opensearch.sql.planner.physical.datasource; import com.google.common.annotations.VisibleForTesting; import java.util.Map; import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; -import org.opensearch.sql.catalog.CatalogService; import org.opensearch.sql.data.type.ExprType; +import org.opensearch.sql.datasource.DataSourceService; import org.opensearch.sql.planner.DefaultImplementor; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.logical.LogicalRelation; @@ -22,36 +22,36 @@ /** * Table implementation to handle show datasources command. - * Since catalog information is not tied to any storage engine, this info - * is handled via Catalog Table. + * Since datasource information is not tied to any storage engine, this info + * is handled via DataSource Table. * */ @RequiredArgsConstructor @EqualsAndHashCode -public class CatalogTable implements Table { +public class DataSourceTable implements Table { - private final CatalogService catalogService; + private final DataSourceService dataSourceService; @Override public Map getFieldTypes() { - return CatalogTableSchema.CATALOG_TABLE_SCHEMA.getMapping(); + return DataSourceTableSchema.DATASOURCE_TABLE_SCHEMA.getMapping(); } @Override public PhysicalPlan implement(LogicalPlan plan) { - return plan.accept(new CatalogTableDefaultImplementor(catalogService), null); + return plan.accept(new DataSourceTableDefaultImplementor(dataSourceService), null); } @VisibleForTesting @RequiredArgsConstructor - public static class CatalogTableDefaultImplementor + public static class DataSourceTableDefaultImplementor extends DefaultImplementor { - private final CatalogService catalogService; + private final DataSourceService dataSourceService; @Override public PhysicalPlan visitRelation(LogicalRelation node, Object context) { - return new CatalogTableScan(catalogService); + return new DataSourceTableScan(dataSourceService); } } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTableScan.java b/core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableScan.java similarity index 54% rename from core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTableScan.java rename to core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableScan.java index efc59c97ec..14cd09e162 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTableScan.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableScan.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.planner.physical.catalog; +package org.opensearch.sql.planner.physical.datasource; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; @@ -14,45 +14,47 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Set; -import org.opensearch.sql.catalog.CatalogService; -import org.opensearch.sql.catalog.model.Catalog; import org.opensearch.sql.data.model.ExprTupleValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.model.ExprValueUtils; +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.model.DataSource; import org.opensearch.sql.storage.TableScanOperator; /** - * This class handles table scan of catalog table. - * Right now these are derived from catalogService thorough static fields. + * This class handles table scan of data source table. + * Right now these are derived from dataSourceService thorough static fields. * In future this might scan data from underlying datastore if we start - * persisting catalog info somewhere. + * persisting datasource info somewhere. * */ -public class CatalogTableScan extends TableScanOperator { +public class DataSourceTableScan extends TableScanOperator { - private final CatalogService catalogService; + private final DataSourceService dataSourceService; private Iterator iterator; - public CatalogTableScan(CatalogService catalogService) { - this.catalogService = catalogService; + public DataSourceTableScan(DataSourceService dataSourceService) { + this.dataSourceService = dataSourceService; this.iterator = Collections.emptyIterator(); } @Override public String explain() { - return "GetCatalogRequestRequest{}"; + return "GetDataSourcesInfoRequest{}"; } @Override public void open() { List exprValues = new ArrayList<>(); - Set catalogs = catalogService.getCatalogs(); - for (Catalog catalog : catalogs) { + Set dataSources = dataSourceService.getDataSources(); + for (DataSource dataSource : dataSources) { exprValues.add( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( - "DATASOURCE_NAME", ExprValueUtils.stringValue(catalog.getName()), - "CONNECTOR_TYPE", ExprValueUtils.stringValue(catalog.getConnectorType().name()))))); + "DATASOURCE_NAME", + ExprValueUtils.stringValue(dataSource.getName()), + "CONNECTOR_TYPE", + ExprValueUtils.stringValue(dataSource.getConnectorType().name()))))); } iterator = exprValues.iterator(); } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTableSchema.java b/core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableSchema.java similarity index 72% rename from core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTableSchema.java rename to core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableSchema.java index b360eb87db..dd959d9b56 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTableSchema.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableSchema.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.sql.planner.physical.catalog; +package org.opensearch.sql.planner.physical.datasource; import static org.opensearch.sql.data.type.ExprCoreType.STRING; @@ -14,13 +14,13 @@ import org.opensearch.sql.data.type.ExprType; /** - * Definition of the system table schema. + * Definition of the data source table schema. */ @Getter @RequiredArgsConstructor -public enum CatalogTableSchema { +public enum DataSourceTableSchema { - CATALOG_TABLE_SCHEMA(new LinkedHashMap<>() { + DATASOURCE_TABLE_SCHEMA(new LinkedHashMap<>() { { put("DATASOURCE_NAME", STRING); put("CONNECTOR_TYPE", STRING); diff --git a/core/src/main/java/org/opensearch/sql/storage/DataSourceFactory.java b/core/src/main/java/org/opensearch/sql/storage/DataSourceFactory.java new file mode 100644 index 0000000000..20d263e601 --- /dev/null +++ b/core/src/main/java/org/opensearch/sql/storage/DataSourceFactory.java @@ -0,0 +1,31 @@ +/* + * + * * Copyright OpenSearch Contributors + * * SPDX-License-Identifier: Apache-2.0 + * + */ + +package org.opensearch.sql.storage; + +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; + +/** + * {@link DataSourceFactory} is used to create {@link DataSource} from {@link DataSourceMetadata}. + * Each data source define {@link DataSourceFactory} and register to {@link DataSourceService}. + * {@link DataSourceFactory} is one instance per JVM . Each {@link DataSourceType} mapping to one + * {@link DataSourceFactory}. + */ +public interface DataSourceFactory { + /** + * Get {@link DataSourceType}. + */ + DataSourceType getDataSourceType(); + + /** + * Create {@link DataSource}. + */ + DataSource createDataSource(DataSourceMetadata metadata); +} diff --git a/core/src/main/java/org/opensearch/sql/storage/StorageEngine.java b/core/src/main/java/org/opensearch/sql/storage/StorageEngine.java index 609949578c..246a50ea09 100644 --- a/core/src/main/java/org/opensearch/sql/storage/StorageEngine.java +++ b/core/src/main/java/org/opensearch/sql/storage/StorageEngine.java @@ -8,7 +8,7 @@ import java.util.Collection; import java.util.Collections; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.expression.function.FunctionResolver; /** @@ -19,12 +19,12 @@ public interface StorageEngine { /** * Get {@link Table} from storage engine. */ - Table getTable(CatalogSchemaName catalogSchemaName, String tableName); + Table getTable(DataSourceSchemaName dataSourceSchemaName, String tableName); /** - * Get list of catalog related functions. + * Get list of datasource related functions. * - * @return FunctionResolvers of catalog functions. + * @return FunctionResolvers of datasource functions. */ default Collection getFunctions() { return Collections.emptyList(); diff --git a/core/src/main/java/org/opensearch/sql/storage/StorageEngineFactory.java b/core/src/main/java/org/opensearch/sql/storage/StorageEngineFactory.java deleted file mode 100644 index 4cc27f6fa0..0000000000 --- a/core/src/main/java/org/opensearch/sql/storage/StorageEngineFactory.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * - * * Copyright OpenSearch Contributors - * * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.opensearch.sql.storage; - -import java.util.Map; -import org.opensearch.sql.catalog.model.ConnectorType; - -public interface StorageEngineFactory { - - ConnectorType getConnectorType(); - - StorageEngine getStorageEngine(String catalogName, Map requiredConfig); - -} diff --git a/core/src/main/java/org/opensearch/sql/utils/SystemIndexUtils.java b/core/src/main/java/org/opensearch/sql/utils/SystemIndexUtils.java index 9ba3a67847..5325ea371a 100644 --- a/core/src/main/java/org/opensearch/sql/utils/SystemIndexUtils.java +++ b/core/src/main/java/org/opensearch/sql/utils/SystemIndexUtils.java @@ -38,7 +38,7 @@ public class SystemIndexUtils { */ public static final String TABLE_INFO = "ALL." + SYS_META_SUFFIX; - public static final String CATALOGS_TABLE_NAME = ".CATALOGS"; + public static final String DATASOURCES_TABLE_NAME = ".DATASOURCES"; public static Boolean isSystemIndex(String indexName) { diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java index 97c560d505..044949ea35 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -10,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opensearch.sql.analysis.CatalogSchemaIdentifierNameResolver.DEFAULT_CATALOG_NAME; +import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; import static org.opensearch.sql.ast.dsl.AstDSL.aggregate; import static org.opensearch.sql.ast.dsl.AstDSL.alias; import static org.opensearch.sql.ast.dsl.AstDSL.argument; @@ -52,6 +52,7 @@ import static org.opensearch.sql.utils.MLCommonsConstants.STATUS; import static org.opensearch.sql.utils.MLCommonsConstants.TASKID; import static org.opensearch.sql.utils.MLCommonsConstants.TRAIN; +import static org.opensearch.sql.utils.SystemIndexUtils.DATASOURCES_TABLE_NAME; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -80,7 +81,6 @@ import org.opensearch.sql.exception.SemanticCheckException; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.HighlightExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.window.WindowDefinition; import org.opensearch.sql.planner.logical.LogicalAD; import org.opensearch.sql.planner.logical.LogicalMLCommons; @@ -88,7 +88,7 @@ import org.opensearch.sql.planner.logical.LogicalPlanDSL; import org.opensearch.sql.planner.logical.LogicalProject; import org.opensearch.sql.planner.logical.LogicalRelation; -import org.opensearch.sql.planner.physical.catalog.CatalogTable; +import org.opensearch.sql.planner.physical.datasource.DataSourceTable; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -96,7 +96,7 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTest.class}) +@ContextConfiguration(classes = {AnalyzerTest.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) class AnalyzerTest extends AnalyzerTestBase { @@ -105,7 +105,7 @@ public void filter_relation() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("schema", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation("schema"), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); @@ -116,65 +116,65 @@ public void filter_relation_with_alias() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("schema", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation("schema", "alias"), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); } @Test - public void filter_relation_with_catalog() { + public void filter_relation_with_datasource() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("http_total_requests", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation(AstDSL.qualifiedName("prometheus", "http_total_requests")), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); } @Test - public void filter_relation_with_escaped_catalog() { + public void filter_relation_with_escaped_datasource() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("prometheus.http_total_requests", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation(AstDSL.qualifiedName("prometheus.http_total_requests")), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); } @Test - public void filter_relation_with_information_schema_and_prom_catalog() { + public void filter_relation_with_information_schema_and_prom_datasource() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("tables", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation(AstDSL.qualifiedName("prometheus", "information_schema", "tables")), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); } @Test - public void filter_relation_with_default_schema_and_prom_catalog() { + public void filter_relation_with_default_schema_and_prom_datasource() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("tables", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation(AstDSL.qualifiedName("prometheus", "default", "tables")), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); } @Test - public void filter_relation_with_information_schema_and_os_catalog() { + public void filter_relation_with_information_schema_and_os_datasource() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("tables", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation( - AstDSL.qualifiedName(DEFAULT_CATALOG_NAME, "information_schema", "tables")), + AstDSL.qualifiedName(DEFAULT_DATASOURCE_NAME, "information_schema", "tables")), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); } @@ -183,29 +183,29 @@ public void filter_relation_with_information_schema() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("tables.test", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation(AstDSL.qualifiedName("information_schema", "tables", "test")), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); } @Test - public void filter_relation_with_non_existing_catalog() { + public void filter_relation_with_non_existing_datasource() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("test.http_total_requests", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation(AstDSL.qualifiedName("test", "http_total_requests")), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); } @Test - public void filter_relation_with_non_existing_catalog_with_three_parts() { + public void filter_relation_with_non_existing_datasource_with_three_parts() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("test.nonexisting_schema.http_total_requests", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation(AstDSL.qualifiedName("test", "nonexisting_schema", "http_total_requests")), @@ -217,7 +217,7 @@ public void filter_relation_with_multiple_tables() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("test.1,test.2", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), AstDSL.filter( AstDSL.relation(Arrays.asList("test.1", "test.2")), AstDSL.equalTo(AstDSL.field("integer_value"), AstDSL.intLiteral(1)))); @@ -236,7 +236,7 @@ public void analyze_filter_relation() { assertAnalyzeEqual( LogicalPlanDSL.filter( LogicalPlanDSL.relation("schema", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))), filter(relation("schema"), compare("=", field("integer_value"), intLiteral(1)))); } @@ -247,10 +247,10 @@ public void analyze_filter_aggregation_relation() { LogicalPlanDSL.aggregation( LogicalPlanDSL.relation("schema", table), ImmutableList.of( - DSL.named("AVG(integer_value)", dsl.avg(DSL.ref("integer_value", INTEGER))), - DSL.named("MIN(integer_value)", dsl.min(DSL.ref("integer_value", INTEGER)))), + DSL.named("AVG(integer_value)", DSL.avg(DSL.ref("integer_value", INTEGER))), + DSL.named("MIN(integer_value)", DSL.min(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("string_value", DSL.ref("string_value", STRING)))), - dsl.greater(// Expect to be replaced with reference by expression optimizer + DSL.greater(// Expect to be replaced with reference by expression optimizer DSL.ref("MIN(integer_value)", INTEGER), DSL.literal(integerValue(10)))), AstDSL.filter( AstDSL.agg( @@ -282,7 +282,7 @@ public void stats_source() { LogicalPlanDSL.aggregation( LogicalPlanDSL.relation("schema", table), ImmutableList - .of(DSL.named("avg(integer_value)", dsl.avg(DSL.ref("integer_value", INTEGER)))), + .of(DSL.named("avg(integer_value)", DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("string_value", DSL.ref("string_value", STRING)))), AstDSL.agg( AstDSL.relation("schema"), @@ -479,7 +479,7 @@ public void sort_with_aggregator() { ImmutableList.of( DSL.named( "avg(integer_value)", - dsl.avg(DSL.ref("integer_value", INTEGER)))), + DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("string_value", DSL.ref("string_value", STRING)))), // Aggregator in Sort AST node is replaced with reference by expression optimizer Pair.of(SortOption.DEFAULT_ASC, DSL.ref("avg(integer_value)", DOUBLE))), @@ -553,7 +553,7 @@ public void window_function() { LogicalPlanDSL.relation("test", table), ImmutablePair.of(DEFAULT_ASC, DSL.ref("string_value", STRING)), ImmutablePair.of(DEFAULT_ASC, DSL.ref("integer_value", INTEGER))), - DSL.named("window_function", dsl.rowNumber()), + DSL.named("window_function", DSL.rowNumber()), new WindowDefinition( ImmutableList.of(DSL.ref("string_value", STRING)), ImmutableList.of( @@ -641,7 +641,7 @@ public void sql_group_by_field() { LogicalPlanDSL.relation("schema", table), ImmutableList .of(DSL - .named("AVG(integer_value)", dsl.avg(DSL.ref("integer_value", INTEGER)))), + .named("AVG(integer_value)", DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("string_value", DSL.ref("string_value", STRING)))), DSL.named("string_value", DSL.ref("string_value", STRING)), DSL.named("AVG(integer_value)", DSL.ref("AVG(integer_value)", DOUBLE))), @@ -669,9 +669,9 @@ public void sql_group_by_function() { LogicalPlanDSL.relation("schema", table), ImmutableList .of(DSL - .named("AVG(integer_value)", dsl.avg(DSL.ref("integer_value", INTEGER)))), + .named("AVG(integer_value)", DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("abs(long_value)", - dsl.abs(DSL.ref("long_value", LONG))))), + DSL.abs(DSL.ref("long_value", LONG))))), DSL.named("abs(long_value)", DSL.ref("abs(long_value)", LONG)), DSL.named("AVG(integer_value)", DSL.ref("AVG(integer_value)", DOUBLE))), AstDSL.project( @@ -699,9 +699,9 @@ public void sql_group_by_function_in_uppercase() { LogicalPlanDSL.relation("schema", table), ImmutableList .of(DSL - .named("AVG(integer_value)", dsl.avg(DSL.ref("integer_value", INTEGER)))), + .named("AVG(integer_value)", DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("ABS(long_value)", - dsl.abs(DSL.ref("long_value", LONG))))), + DSL.abs(DSL.ref("long_value", LONG))))), DSL.named("abs(long_value)", DSL.ref("ABS(long_value)", LONG)), DSL.named("AVG(integer_value)", DSL.ref("AVG(integer_value)", DOUBLE))), AstDSL.project( @@ -729,11 +729,11 @@ public void sql_expression_over_one_aggregation() { LogicalPlanDSL.relation("schema", table), ImmutableList .of(DSL.named("avg(integer_value)", - dsl.avg(DSL.ref("integer_value", INTEGER)))), + DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("abs(long_value)", - dsl.abs(DSL.ref("long_value", LONG))))), + DSL.abs(DSL.ref("long_value", LONG))))), DSL.named("abs(long_value)", DSL.ref("abs(long_value)", LONG)), - DSL.named("abs(avg(integer_value)", dsl.abs(DSL.ref("avg(integer_value)", DOUBLE)))), + DSL.named("abs(avg(integer_value)", DSL.abs(DSL.ref("avg(integer_value)", DOUBLE)))), AstDSL.project( AstDSL.agg( AstDSL.relation("schema"), @@ -760,14 +760,14 @@ public void sql_expression_over_two_aggregation() { LogicalPlanDSL.relation("schema", table), ImmutableList .of(DSL.named("sum(integer_value)", - dsl.sum(DSL.ref("integer_value", INTEGER))), + DSL.sum(DSL.ref("integer_value", INTEGER))), DSL.named("avg(integer_value)", - dsl.avg(DSL.ref("integer_value", INTEGER)))), + DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("abs(long_value)", - dsl.abs(DSL.ref("long_value", LONG))))), + DSL.abs(DSL.ref("long_value", LONG))))), DSL.named("abs(long_value)", DSL.ref("abs(long_value)", LONG)), DSL.named("sum(integer_value)-avg(integer_value)", - dsl.subtract(DSL.ref("sum(integer_value)", INTEGER), + DSL.subtract(DSL.ref("sum(integer_value)", INTEGER), DSL.ref("avg(integer_value)", DOUBLE)))), AstDSL.project( AstDSL.agg( @@ -819,7 +819,7 @@ public void named_aggregator_with_condition() { LogicalPlanDSL.relation("schema", table), ImmutableList.of( DSL.named("count(string_value) filter(where integer_value > 1)", - dsl.count(DSL.ref("string_value", STRING)).condition(dsl.greater(DSL.ref( + DSL.count(DSL.ref("string_value", STRING)).condition(DSL.greater(DSL.ref( "integer_value", INTEGER), DSL.literal(1)))) ), emptyList() @@ -854,7 +854,7 @@ public void ppl_stats_by_fieldAndSpan() { LogicalPlanDSL.aggregation( LogicalPlanDSL.relation("schema", table), ImmutableList.of( - DSL.named("AVG(integer_value)", dsl.avg(DSL.ref("integer_value", INTEGER)))), + DSL.named("AVG(integer_value)", DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of( DSL.named("span", DSL.span(DSL.ref("long_value", LONG), DSL.literal(10), "")), DSL.named("string_value", DSL.ref("string_value", STRING)))), @@ -1043,7 +1043,7 @@ public void table_function() { } @Test - public void table_function_with_no_catalog() { + public void table_function_with_no_datasource() { ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, () -> analyze(AstDSL.tableFunction(List.of("query_range"), unresolvedArg("query", stringLiteral("http_latency")), @@ -1055,7 +1055,7 @@ public void table_function_with_no_catalog() { } @Test - public void table_function_with_wrong_catalog() { + public void table_function_with_wrong_datasource() { ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, () -> analyze(AstDSL.tableFunction(Arrays.asList("prome", "query_range"), unresolvedArg("query", stringLiteral("http_latency")), @@ -1077,10 +1077,10 @@ public void table_function_with_wrong_table_function() { } @Test - public void show_catalogs() { - assertAnalyzeEqual(new LogicalRelation(".CATALOGS", new CatalogTable(catalogService)), - AstDSL.relation(qualifiedName(".CATALOGS"))); - + public void show_datasources() { + assertAnalyzeEqual(new LogicalRelation(DATASOURCES_TABLE_NAME, + new DataSourceTable(dataSourceService)), + AstDSL.relation(qualifiedName(DATASOURCES_TABLE_NAME))); } @Test diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java index 447802c963..a485541a34 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java @@ -15,18 +15,17 @@ import java.util.Map; import java.util.Set; import org.apache.commons.lang3.tuple.Pair; -import org.opensearch.sql.CatalogSchemaName; import org.opensearch.sql.analysis.symbol.Namespace; import org.opensearch.sql.analysis.symbol.Symbol; import org.opensearch.sql.analysis.symbol.SymbolTable; import org.opensearch.sql.ast.tree.UnresolvedPlan; -import org.opensearch.sql.catalog.CatalogService; -import org.opensearch.sql.catalog.model.Catalog; -import org.opensearch.sql.catalog.model.ConnectorType; import org.opensearch.sql.config.TestConfig; import org.opensearch.sql.data.type.ExprType; +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; import org.opensearch.sql.exception.ExpressionEvaluationException; -import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.ReferenceExpression; import org.opensearch.sql.expression.env.Environment; @@ -52,7 +51,7 @@ protected Map typeMapping() { @Bean protected StorageEngine storageEngine() { - return (catalogSchemaName, tableName) -> table; + return (dataSourceSchemaName, tableName) -> table; } @Bean @@ -81,7 +80,7 @@ public PhysicalPlan implement(LogicalPlan plan) { } @Bean - protected Table catalogTable() { + protected Table dataSourceTable() { return new Table() { @Override public Map getFieldTypes() { @@ -96,8 +95,8 @@ public PhysicalPlan implement(LogicalPlan plan) { } @Bean - protected CatalogService catalogService() { - return new DefaultCatalogService(); + protected DataSourceService dataSourceService() { + return new DefaultDataSourceService(); } @@ -124,12 +123,6 @@ protected Environment typeEnv() { }; } - @Autowired - protected BuiltinFunctionRepository functionRepository; - - @Autowired - protected DSL dsl; - @Autowired protected AnalysisContext analysisContext; @@ -143,16 +136,16 @@ protected Environment typeEnv() { protected Table table; @Autowired - protected CatalogService catalogService; + protected DataSourceService dataSourceService; @Autowired protected Environment typeEnv; @Bean - protected Analyzer analyzer(ExpressionAnalyzer expressionAnalyzer, CatalogService catalogService, - StorageEngine storageEngine, BuiltinFunctionRepository functionRepository, + protected Analyzer analyzer(ExpressionAnalyzer expressionAnalyzer, + DataSourceService dataSourceService, Table table) { - catalogService.registerDefaultOpenSearchCatalog(storageEngine); + BuiltinFunctionRepository functionRepository = BuiltinFunctionRepository.getInstance(); functionRepository.register("prometheus", new FunctionResolver() { @Override @@ -170,7 +163,7 @@ public FunctionName getFunctionName() { return FunctionName.of("query_range"); } }); - return new Analyzer(expressionAnalyzer, catalogService, functionRepository); + return new Analyzer(expressionAnalyzer, dataSourceService, functionRepository); } @Bean @@ -184,8 +177,8 @@ protected AnalysisContext analysisContext(TypeEnvironment typeEnvironment) { } @Bean - protected ExpressionAnalyzer expressionAnalyzer(DSL dsl, BuiltinFunctionRepository repo) { - return new ExpressionAnalyzer(repo); + protected ExpressionAnalyzer expressionAnalyzer() { + return new ExpressionAnalyzer(BuiltinFunctionRepository.getInstance()); } protected void assertAnalyzeEqual(LogicalPlan expected, UnresolvedPlan unresolvedPlan) { @@ -196,26 +189,31 @@ protected LogicalPlan analyze(UnresolvedPlan unresolvedPlan) { return analyzer.analyze(unresolvedPlan, analysisContext); } - private class DefaultCatalogService implements CatalogService { + private class DefaultDataSourceService implements DataSourceService { private StorageEngine storageEngine = storageEngine(); - private final Catalog catalog - = new Catalog("prometheus", ConnectorType.PROMETHEUS, storageEngine); + private final DataSource dataSource + = new DataSource("prometheus", DataSourceType.PROMETHEUS, storageEngine); @Override - public Set getCatalogs() { - return ImmutableSet.of(catalog); + public Set getDataSources() { + return ImmutableSet.of(dataSource); + } + + @Override + public DataSource getDataSource(String dataSourceName) { + return dataSource; } @Override - public Catalog getCatalog(String catalogName) { - return catalog; + public void addDataSource(DataSourceMetadata... metadatas) { + throw new UnsupportedOperationException(); } @Override - public void registerDefaultOpenSearchCatalog(StorageEngine storageEngine) { - this.storageEngine = storageEngine; + public void clear() { + throw new UnsupportedOperationException(); } } diff --git a/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java index 84c5005eff..f10fc281b3 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java @@ -49,7 +49,6 @@ import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.LiteralExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.window.aggregation.AggregateWindowFunction; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; @@ -57,13 +56,13 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {AnalyzerTestBase.class}) class ExpressionAnalyzerTest extends AnalyzerTestBase { @Test public void equal() { assertAnalyzeEqual( - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1))), AstDSL.equalTo(AstDSL.unresolvedAttr("integer_value"), AstDSL.intLiteral(1)) ); } @@ -71,7 +70,7 @@ public void equal() { @Test public void and() { assertAnalyzeEqual( - dsl.and(DSL.ref("boolean_value", BOOLEAN), DSL.literal(LITERAL_TRUE)), + DSL.and(DSL.ref("boolean_value", BOOLEAN), DSL.literal(LITERAL_TRUE)), AstDSL.and(AstDSL.unresolvedAttr("boolean_value"), AstDSL.booleanLiteral(true)) ); } @@ -79,7 +78,7 @@ public void and() { @Test public void or() { assertAnalyzeEqual( - dsl.or(DSL.ref("boolean_value", BOOLEAN), DSL.literal(LITERAL_TRUE)), + DSL.or(DSL.ref("boolean_value", BOOLEAN), DSL.literal(LITERAL_TRUE)), AstDSL.or(AstDSL.unresolvedAttr("boolean_value"), AstDSL.booleanLiteral(true)) ); } @@ -87,7 +86,7 @@ public void or() { @Test public void xor() { assertAnalyzeEqual( - dsl.xor(DSL.ref("boolean_value", BOOLEAN), DSL.literal(LITERAL_TRUE)), + DSL.xor(DSL.ref("boolean_value", BOOLEAN), DSL.literal(LITERAL_TRUE)), AstDSL.xor(AstDSL.unresolvedAttr("boolean_value"), AstDSL.booleanLiteral(true)) ); } @@ -95,7 +94,7 @@ public void xor() { @Test public void not() { assertAnalyzeEqual( - dsl.not(DSL.ref("boolean_value", BOOLEAN)), + DSL.not(DSL.ref("boolean_value", BOOLEAN)), AstDSL.not(AstDSL.unresolvedAttr("boolean_value")) ); } @@ -114,10 +113,10 @@ public void case_value() { DSL.cases( DSL.literal("Default value"), DSL.when( - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(30)), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(30)), DSL.literal("Thirty")), DSL.when( - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(50)), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(50)), DSL.literal("Fifty"))), AstDSL.caseWhen( qualifiedName("integer_value"), @@ -132,10 +131,10 @@ public void case_conditions() { DSL.cases( null, DSL.when( - dsl.greater(DSL.ref("integer_value", INTEGER), DSL.literal(50)), + DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(50)), DSL.literal("Fifty")), DSL.when( - dsl.greater(DSL.ref("integer_value", INTEGER), DSL.literal(30)), + DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(30)), DSL.literal("Thirty"))), AstDSL.caseWhen( null, @@ -152,7 +151,7 @@ public void case_conditions() { @Test public void castAnalyzer() { assertAnalyzeEqual( - dsl.castInt(DSL.ref("boolean_value", BOOLEAN)), + DSL.castInt(DSL.ref("boolean_value", BOOLEAN)), AstDSL.cast(AstDSL.unresolvedAttr("boolean_value"), AstDSL.stringLiteral("INT")) ); @@ -178,7 +177,7 @@ public void case_with_default_result_type_different() { @Test public void scalar_window_function() { assertAnalyzeEqual( - dsl.rank(), + DSL.rank(), AstDSL.window(AstDSL.function("rank"), emptyList(), emptyList())); } @@ -186,7 +185,7 @@ public void scalar_window_function() { @Test public void aggregate_window_function() { assertAnalyzeEqual( - new AggregateWindowFunction(dsl.avg(DSL.ref("integer_value", INTEGER))), + new AggregateWindowFunction(DSL.avg(DSL.ref("integer_value", INTEGER))), AstDSL.window( AstDSL.aggregate("avg", qualifiedName("integer_value")), emptyList(), @@ -224,7 +223,7 @@ public void qualified_name_with_qualifier() { @Test public void interval() { assertAnalyzeEqual( - dsl.interval(DSL.literal(1L), DSL.literal("DAY")), + DSL.interval(DSL.literal(1L), DSL.literal("DAY")), AstDSL.intervalLiteral(1L, DataType.LONG, "DAY")); } @@ -241,7 +240,7 @@ public void case_clause() { DSL.cases( DSL.literal(ExprValueUtils.nullValue()), DSL.when( - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(30)), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(30)), DSL.literal("test"))), AstDSL.caseWhen( AstDSL.nullLiteral(), @@ -282,8 +281,8 @@ public void undefined_aggregation_function() { @Test public void aggregation_filter() { assertAnalyzeEqual( - dsl.avg(DSL.ref("integer_value", INTEGER)) - .condition(dsl.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), + DSL.avg(DSL.ref("integer_value", INTEGER)) + .condition(DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), AstDSL.filteredAggregate("avg", qualifiedName("integer_value"), function(">", qualifiedName("integer_value"), intLiteral(1))) ); @@ -292,7 +291,7 @@ public void aggregation_filter() { @Test public void variance_mapto_varPop() { assertAnalyzeEqual( - dsl.varPop(DSL.ref("integer_value", INTEGER)), + DSL.varPop(DSL.ref("integer_value", INTEGER)), AstDSL.aggregate("variance", qualifiedName("integer_value")) ); } @@ -300,7 +299,7 @@ public void variance_mapto_varPop() { @Test public void distinct_count() { assertAnalyzeEqual( - dsl.distinctCount(DSL.ref("integer_value", INTEGER)), + DSL.distinctCount(DSL.ref("integer_value", INTEGER)), AstDSL.distinctAggregate("count", qualifiedName("integer_value")) ); } @@ -308,8 +307,8 @@ public void distinct_count() { @Test public void filtered_distinct_count() { assertAnalyzeEqual( - dsl.distinctCount(DSL.ref("integer_value", INTEGER)) - .condition(dsl.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), + DSL.distinctCount(DSL.ref("integer_value", INTEGER)) + .condition(DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), AstDSL.filteredDistinctCount("count", qualifiedName("integer_value"), function( ">", qualifiedName("integer_value"), intLiteral(1))) ); @@ -318,7 +317,7 @@ public void filtered_distinct_count() { @Test public void take_aggregation() { assertAnalyzeEqual( - dsl.take(DSL.ref("string_value", STRING), DSL.literal(10)), + DSL.take(DSL.ref("string_value", STRING), DSL.literal(10)), AstDSL.aggregate("take", qualifiedName("string_value"), intLiteral(10)) ); } @@ -326,7 +325,7 @@ public void take_aggregation() { @Test public void named_argument() { assertAnalyzeEqual( - dsl.namedArgument("arg_name", DSL.literal("query")), + DSL.namedArgument("arg_name", DSL.literal("query")), AstDSL.unresolvedArg("arg_name", stringLiteral("query")) ); } @@ -358,9 +357,9 @@ public void named_non_parse_expression() { @Test void match_bool_prefix_expression() { assertAnalyzeEqual( - dsl.match_bool_prefix( - dsl.namedArgument("field", DSL.literal("fieldA")), - dsl.namedArgument("query", DSL.literal("sample query"))), + DSL.match_bool_prefix( + DSL.namedArgument("field", DSL.literal("fieldA")), + DSL.namedArgument("query", DSL.literal("sample query"))), AstDSL.function("match_bool_prefix", AstDSL.unresolvedArg("field", stringLiteral("fieldA")), AstDSL.unresolvedArg("query", stringLiteral("sample query")))); @@ -385,11 +384,11 @@ void visit_span() { @Test void visit_in() { assertAnalyzeEqual( - dsl.or( - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(1)), - dsl.or( - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(2)), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(3)))), + DSL.or( + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(1)), + DSL.or( + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(2)), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(3)))), AstDSL.in(field("integer_value"), intLiteral(1), intLiteral(2), intLiteral(3))); assertThrows( @@ -400,11 +399,11 @@ void visit_in() { @Test void multi_match_expression() { assertAnalyzeEqual( - dsl.multi_match( - dsl.namedArgument("fields", DSL.literal( + DSL.multi_match( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", DSL.literal("sample query"))), + DSL.namedArgument("query", DSL.literal("sample query"))), AstDSL.function("multi_match", AstDSL.unresolvedArg("fields", new RelevanceFieldList(Map.of( "field", 1.F))), @@ -414,12 +413,12 @@ void multi_match_expression() { @Test void multi_match_expression_with_params() { assertAnalyzeEqual( - dsl.multi_match( - dsl.namedArgument("fields", DSL.literal( + DSL.multi_match( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", DSL.literal("sample query")), - dsl.namedArgument("analyzer", DSL.literal("keyword"))), + DSL.namedArgument("query", DSL.literal("sample query")), + DSL.namedArgument("analyzer", DSL.literal("keyword"))), AstDSL.function("multi_match", AstDSL.unresolvedArg("fields", new RelevanceFieldList(Map.of( "field", 1.F))), @@ -430,12 +429,12 @@ void multi_match_expression_with_params() { @Test void multi_match_expression_two_fields() { assertAnalyzeEqual( - dsl.multi_match( - dsl.namedArgument("fields", DSL.literal( + DSL.multi_match( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", DSL.literal("sample query"))), + DSL.namedArgument("query", DSL.literal("sample query"))), AstDSL.function("multi_match", AstDSL.unresolvedArg("fields", new RelevanceFieldList(ImmutableMap.of( "field1", 1.F, "field2", .3F))), @@ -445,11 +444,11 @@ void multi_match_expression_two_fields() { @Test void simple_query_string_expression() { assertAnalyzeEqual( - dsl.simple_query_string( - dsl.namedArgument("fields", DSL.literal( + DSL.simple_query_string( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", DSL.literal("sample query"))), + DSL.namedArgument("query", DSL.literal("sample query"))), AstDSL.function("simple_query_string", AstDSL.unresolvedArg("fields", new RelevanceFieldList(Map.of( "field", 1.F))), @@ -459,12 +458,12 @@ void simple_query_string_expression() { @Test void simple_query_string_expression_with_params() { assertAnalyzeEqual( - dsl.simple_query_string( - dsl.namedArgument("fields", DSL.literal( + DSL.simple_query_string( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", DSL.literal("sample query")), - dsl.namedArgument("analyzer", DSL.literal("keyword"))), + DSL.namedArgument("query", DSL.literal("sample query")), + DSL.namedArgument("analyzer", DSL.literal("keyword"))), AstDSL.function("simple_query_string", AstDSL.unresolvedArg("fields", new RelevanceFieldList(Map.of( "field", 1.F))), @@ -475,12 +474,12 @@ void simple_query_string_expression_with_params() { @Test void simple_query_string_expression_two_fields() { assertAnalyzeEqual( - dsl.simple_query_string( - dsl.namedArgument("fields", DSL.literal( + DSL.simple_query_string( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", DSL.literal("sample query"))), + DSL.namedArgument("query", DSL.literal("sample query"))), AstDSL.function("simple_query_string", AstDSL.unresolvedArg("fields", new RelevanceFieldList(ImmutableMap.of( "field1", 1.F, "field2", .3F))), @@ -490,8 +489,8 @@ void simple_query_string_expression_two_fields() { @Test void query_expression() { assertAnalyzeEqual( - dsl.query( - dsl.namedArgument("query", DSL.literal("field:query"))), + DSL.query( + DSL.namedArgument("query", DSL.literal("field:query"))), AstDSL.function("query", AstDSL.unresolvedArg("query", stringLiteral("field:query")))); } @@ -499,11 +498,11 @@ void query_expression() { @Test void query_string_expression() { assertAnalyzeEqual( - dsl.query_string( - dsl.namedArgument("fields", DSL.literal( + DSL.query_string( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", DSL.literal("query_value"))), + DSL.namedArgument("query", DSL.literal("query_value"))), AstDSL.function("query_string", AstDSL.unresolvedArg("fields", new RelevanceFieldList(Map.of( "field", 1.F))), @@ -513,12 +512,12 @@ void query_string_expression() { @Test void query_string_expression_with_params() { assertAnalyzeEqual( - dsl.query_string( - dsl.namedArgument("fields", DSL.literal( + DSL.query_string( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("escape", DSL.literal("false"))), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("escape", DSL.literal("false"))), AstDSL.function("query_string", AstDSL.unresolvedArg("fields", new RelevanceFieldList(Map.of( "field", 1.F))), @@ -529,12 +528,12 @@ void query_string_expression_with_params() { @Test void query_string_expression_two_fields() { assertAnalyzeEqual( - dsl.query_string( - dsl.namedArgument("fields", DSL.literal( + DSL.query_string( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", DSL.literal("query_value"))), + DSL.namedArgument("query", DSL.literal("query_value"))), AstDSL.function("query_string", AstDSL.unresolvedArg("fields", new RelevanceFieldList(ImmutableMap.of( "field1", 1.F, "field2", .3F))), @@ -544,14 +543,14 @@ void query_string_expression_two_fields() { @Test public void match_phrase_prefix_all_params() { assertAnalyzeEqual( - dsl.match_phrase_prefix( - dsl.namedArgument("field", "test"), - dsl.namedArgument("query", "search query"), - dsl.namedArgument("slop", "3"), - dsl.namedArgument("boost", "1.5"), - dsl.namedArgument("analyzer", "standard"), - dsl.namedArgument("max_expansions", "4"), - dsl.namedArgument("zero_terms_query", "NONE") + DSL.match_phrase_prefix( + DSL.namedArgument("field", "test"), + DSL.namedArgument("query", "search query"), + DSL.namedArgument("slop", "3"), + DSL.namedArgument("boost", "1.5"), + DSL.namedArgument("analyzer", "standard"), + DSL.namedArgument("max_expansions", "4"), + DSL.namedArgument("zero_terms_query", "NONE") ), AstDSL.function("match_phrase_prefix", unresolvedArg("field", stringLiteral("test")), diff --git a/core/src/test/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizerTest.java b/core/src/test/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizerTest.java index 105d8f965d..287cff0e3a 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizerTest.java @@ -17,7 +17,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; -import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.BuiltinFunctionRepository; import org.opensearch.sql.expression.window.WindowDefinition; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.logical.LogicalPlanDSL; @@ -27,14 +27,14 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTest.class}) +@ContextConfiguration(classes = {AnalyzerTest.class}) class ExpressionReferenceOptimizerTest extends AnalyzerTestBase { @Test void expression_without_aggregation_should_not_be_replaced() { assertEquals( - dsl.subtract(DSL.ref("age", INTEGER), DSL.literal(1)), - optimize(dsl.subtract(DSL.ref("age", INTEGER), DSL.literal(1))) + DSL.subtract(DSL.ref("age", INTEGER), DSL.literal(1)), + optimize(DSL.subtract(DSL.ref("age", INTEGER), DSL.literal(1))) ); } @@ -42,7 +42,7 @@ void expression_without_aggregation_should_not_be_replaced() { void group_expression_should_be_replaced() { assertEquals( DSL.ref("abs(balance)", INTEGER), - optimize(dsl.abs(DSL.ref("balance", INTEGER))) + optimize(DSL.abs(DSL.ref("balance", INTEGER))) ); } @@ -50,15 +50,15 @@ void group_expression_should_be_replaced() { void aggregation_expression_should_be_replaced() { assertEquals( DSL.ref("AVG(age)", DOUBLE), - optimize(dsl.avg(DSL.ref("age", INTEGER))) + optimize(DSL.avg(DSL.ref("age", INTEGER))) ); } @Test void aggregation_in_expression_should_be_replaced() { assertEquals( - dsl.subtract(DSL.ref("AVG(age)", DOUBLE), DSL.literal(1)), - optimize(dsl.subtract(dsl.avg(DSL.ref("age", INTEGER)), DSL.literal(1))) + DSL.subtract(DSL.ref("AVG(age)", DOUBLE), DSL.literal(1)), + optimize(DSL.subtract(DSL.avg(DSL.ref("age", INTEGER)), DSL.literal(1))) ); } @@ -67,7 +67,7 @@ void case_clause_should_be_replaced() { Expression caseClause = DSL.cases( null, DSL.when( - dsl.equal(DSL.ref("age", INTEGER), DSL.literal(30)), + DSL.equal(DSL.ref("age", INTEGER), DSL.literal(30)), DSL.literal("true"))); LogicalPlan logicalPlan = @@ -91,20 +91,20 @@ void aggregation_in_case_when_clause_should_be_replaced() { Expression caseClause = DSL.cases( null, DSL.when( - dsl.equal(dsl.avg(DSL.ref("age", INTEGER)), DSL.literal(30)), + DSL.equal(DSL.avg(DSL.ref("age", INTEGER)), DSL.literal(30)), DSL.literal("true"))); LogicalPlan logicalPlan = LogicalPlanDSL.aggregation( LogicalPlanDSL.relation("test", table), - ImmutableList.of(DSL.named("AVG(age)", dsl.avg(DSL.ref("age", INTEGER)))), + ImmutableList.of(DSL.named("AVG(age)", DSL.avg(DSL.ref("age", INTEGER)))), ImmutableList.of(DSL.named("name", DSL.ref("name", STRING)))); assertEquals( DSL.cases( null, DSL.when( - dsl.equal(DSL.ref("AVG(age)", DOUBLE), DSL.literal(30)), + DSL.equal(DSL.ref("AVG(age)", DOUBLE), DSL.literal(30)), DSL.literal("true"))), optimize(caseClause, logicalPlan)); } @@ -112,22 +112,22 @@ void aggregation_in_case_when_clause_should_be_replaced() { @Test void aggregation_in_case_else_clause_should_be_replaced() { Expression caseClause = DSL.cases( - dsl.avg(DSL.ref("age", INTEGER)), + DSL.avg(DSL.ref("age", INTEGER)), DSL.when( - dsl.equal(DSL.ref("age", INTEGER), DSL.literal(30)), + DSL.equal(DSL.ref("age", INTEGER), DSL.literal(30)), DSL.literal("true"))); LogicalPlan logicalPlan = LogicalPlanDSL.aggregation( LogicalPlanDSL.relation("test", table), - ImmutableList.of(DSL.named("AVG(age)", dsl.avg(DSL.ref("age", INTEGER)))), + ImmutableList.of(DSL.named("AVG(age)", DSL.avg(DSL.ref("age", INTEGER)))), ImmutableList.of(DSL.named("name", DSL.ref("name", STRING)))); assertEquals( DSL.cases( DSL.ref("AVG(age)", DOUBLE), DSL.when( - dsl.equal(DSL.ref("age", INTEGER), DSL.literal(30)), + DSL.equal(DSL.ref("age", INTEGER), DSL.literal(30)), DSL.literal("true"))), optimize(caseClause, logicalPlan)); } @@ -138,17 +138,17 @@ void window_expression_should_be_replaced() { LogicalPlanDSL.window( LogicalPlanDSL.window( LogicalPlanDSL.relation("test", table), - DSL.named(dsl.rank()), + DSL.named(DSL.rank()), new WindowDefinition(emptyList(), emptyList())), - DSL.named(dsl.denseRank()), + DSL.named(DSL.denseRank()), new WindowDefinition(emptyList(), emptyList())); assertEquals( DSL.ref("rank()", INTEGER), - optimize(dsl.rank(), logicalPlan)); + optimize(DSL.rank(), logicalPlan)); assertEquals( DSL.ref("dense_rank()", INTEGER), - optimize(dsl.denseRank(), logicalPlan)); + optimize(DSL.denseRank(), logicalPlan)); } Expression optimize(Expression expression) { @@ -156,6 +156,7 @@ Expression optimize(Expression expression) { } Expression optimize(Expression expression, LogicalPlan logicalPlan) { + BuiltinFunctionRepository functionRepository = BuiltinFunctionRepository.getInstance(); final ExpressionReferenceOptimizer optimizer = new ExpressionReferenceOptimizer(functionRepository, logicalPlan); return optimizer.optimize(DSL.named(expression), new AnalysisContext()); @@ -165,10 +166,10 @@ LogicalPlan logicalPlan() { return LogicalPlanDSL.aggregation( LogicalPlanDSL.relation("schema", table), ImmutableList - .of(DSL.named("AVG(age)", dsl.avg(DSL.ref("age", INTEGER))), - DSL.named("SUM(age)", dsl.sum(DSL.ref("age", INTEGER)))), + .of(DSL.named("AVG(age)", DSL.avg(DSL.ref("age", INTEGER))), + DSL.named("SUM(age)", DSL.sum(DSL.ref("age", INTEGER)))), ImmutableList.of(DSL.named("balance", DSL.ref("balance", INTEGER)), - DSL.named("abs(balance)", dsl.abs(DSL.ref("balance", INTEGER)))) + DSL.named("abs(balance)", DSL.abs(DSL.ref("balance", INTEGER)))) ); } } diff --git a/core/src/test/java/org/opensearch/sql/analysis/NamedExpressionAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/NamedExpressionAnalyzerTest.java index b944115a48..913593add3 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/NamedExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/NamedExpressionAnalyzerTest.java @@ -17,14 +17,13 @@ import org.opensearch.sql.ast.expression.HighlightFunction; import org.opensearch.sql.ast.expression.Literal; import org.opensearch.sql.expression.NamedExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {AnalyzerTestBase.class}) class NamedExpressionAnalyzerTest extends AnalyzerTestBase { @Test void visit_named_select_item() { diff --git a/core/src/test/java/org/opensearch/sql/analysis/QualifierAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/QualifierAnalyzerTest.java index 3b9635cb37..8c87b24d3e 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/QualifierAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/QualifierAnalyzerTest.java @@ -18,14 +18,13 @@ import org.opensearch.sql.analysis.symbol.Symbol; import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.data.type.ExprType; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {AnalyzerTestBase.class}) class QualifierAnalyzerTest extends AnalyzerTestBase { private QualifierAnalyzer qualifierAnalyzer; diff --git a/core/src/test/java/org/opensearch/sql/analysis/SelectAnalyzeTest.java b/core/src/test/java/org/opensearch/sql/analysis/SelectAnalyzeTest.java index 7ffc97db3b..82f3a87e30 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/SelectAnalyzeTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/SelectAnalyzeTest.java @@ -23,7 +23,6 @@ import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.planner.logical.LogicalPlanDSL; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; @@ -31,7 +30,7 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, SelectAnalyzeTest.class}) +@ContextConfiguration(classes = {SelectAnalyzeTest.class}) public class SelectAnalyzeTest extends AnalyzerTestBase { @Override @@ -114,7 +113,7 @@ public void stats_and_project_all() { LogicalPlanDSL.aggregation( LogicalPlanDSL.relation("schema", table), ImmutableList.of(DSL - .named("avg(integer_value)", dsl.avg(DSL.ref("integer_value", INTEGER)))), + .named("avg(integer_value)", DSL.avg(DSL.ref("integer_value", INTEGER)))), ImmutableList.of(DSL.named("string_value", DSL.ref("string_value", STRING)))), DSL.named("avg(integer_value)", DSL.ref("avg(integer_value)", DOUBLE)), DSL.named("string_value", DSL.ref("string_value", STRING)) diff --git a/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java index 8ad38f5322..a9fb03d2d5 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java @@ -9,13 +9,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; -import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import java.util.Arrays; import java.util.List; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -26,7 +24,6 @@ import org.opensearch.sql.ast.expression.UnresolvedExpression; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.NamedExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -34,7 +31,7 @@ @Configuration @ExtendWith(SpringExtension.class) @ExtendWith(MockitoExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, SelectExpressionAnalyzerTest.class}) +@ContextConfiguration(classes = {SelectExpressionAnalyzerTest.class}) public class SelectExpressionAnalyzerTest extends AnalyzerTestBase { @Mock @@ -80,7 +77,7 @@ public void field_name_with_qualifier_quoted() { public void field_name_in_expression_with_qualifier() { analysisContext.peek().define(new Symbol(Namespace.INDEX_NAME, "index_alias"), STRUCT); assertAnalyzeEqual( - DSL.named("abs(index_alias.integer_value)", dsl.abs(DSL.ref("integer_value", INTEGER))), + DSL.named("abs(index_alias.integer_value)", DSL.abs(DSL.ref("integer_value", INTEGER))), AstDSL.alias("abs(index_alias.integer_value)", AstDSL.function("abs", AstDSL.qualifiedName("index_alias", "integer_value"))) ); diff --git a/core/src/test/java/org/opensearch/sql/analysis/WindowExpressionAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/WindowExpressionAnalyzerTest.java index 3ef279156b..cf0a90a436 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/WindowExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/WindowExpressionAnalyzerTest.java @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableMap; import java.util.Collections; import org.apache.commons.lang3.tuple.ImmutablePair; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -30,7 +29,6 @@ import org.opensearch.sql.ast.expression.Alias; import org.opensearch.sql.ast.tree.Sort.SortOption; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.window.WindowDefinition; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.logical.LogicalPlanDSL; @@ -42,7 +40,7 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, SelectExpressionAnalyzerTest.class}) +@ContextConfiguration(classes = {SelectExpressionAnalyzerTest.class}) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class WindowExpressionAnalyzerTest extends AnalyzerTestBase { @@ -65,7 +63,7 @@ void should_wrap_child_with_window_and_sort_operator_if_project_item_windowed() LogicalPlanDSL.relation("test", table), ImmutablePair.of(DEFAULT_ASC, DSL.ref("string_value", STRING)), ImmutablePair.of(DEFAULT_DESC, DSL.ref("integer_value", INTEGER))), - DSL.named("row_number", dsl.rowNumber()), + DSL.named("row_number", DSL.rowNumber()), new WindowDefinition( ImmutableList.of(DSL.ref("string_value", STRING)), ImmutableList.of( @@ -86,7 +84,7 @@ void should_not_generate_sort_operator_if_no_partition_by_and_order_by_list() { assertEquals( LogicalPlanDSL.window( LogicalPlanDSL.relation("test", table), - DSL.named("row_number", dsl.rowNumber()), + DSL.named("row_number", DSL.rowNumber()), new WindowDefinition( ImmutableList.of(), ImmutableList.of())), diff --git a/core/src/test/java/org/opensearch/sql/analysis/model/CatalogSchemaIdentifierNameResolverTest.java b/core/src/test/java/org/opensearch/sql/analysis/model/CatalogSchemaIdentifierNameResolverTest.java deleted file mode 100644 index 069a1d814f..0000000000 --- a/core/src/test/java/org/opensearch/sql/analysis/model/CatalogSchemaIdentifierNameResolverTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * * Copyright OpenSearch Contributors - * * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.opensearch.sql.analysis.model; - - -import java.util.Arrays; -import java.util.Collections; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.opensearch.sql.analysis.CatalogSchemaIdentifierNameResolver; - -public class CatalogSchemaIdentifierNameResolverTest { - - @Test - void testFullyQualifiedName() { - CatalogSchemaIdentifierNameResolver - catalogSchemaIdentifierNameResolver = new CatalogSchemaIdentifierNameResolver( - Arrays.asList("prom", "information_schema", "tables"), Collections.singleton("prom")); - Assertions.assertEquals("information_schema", - catalogSchemaIdentifierNameResolver.getSchemaName()); - Assertions.assertEquals("prom", catalogSchemaIdentifierNameResolver.getCatalogName()); - Assertions.assertEquals("tables", catalogSchemaIdentifierNameResolver.getIdentifierName()); - } - -} diff --git a/core/src/test/java/org/opensearch/sql/analysis/model/DataSourceSchemaIdentifierNameResolverTest.java b/core/src/test/java/org/opensearch/sql/analysis/model/DataSourceSchemaIdentifierNameResolverTest.java new file mode 100644 index 0000000000..7d7c92f3ed --- /dev/null +++ b/core/src/test/java/org/opensearch/sql/analysis/model/DataSourceSchemaIdentifierNameResolverTest.java @@ -0,0 +1,30 @@ +/* + * + * * Copyright OpenSearch Contributors + * * SPDX-License-Identifier: Apache-2.0 + * + */ + +package org.opensearch.sql.analysis.model; + + +import java.util.Arrays; +import java.util.Collections; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver; + +public class DataSourceSchemaIdentifierNameResolverTest { + + @Test + void testFullyQualifiedName() { + DataSourceSchemaIdentifierNameResolver + dataSourceSchemaIdentifierNameResolver = new DataSourceSchemaIdentifierNameResolver( + Arrays.asList("prom", "information_schema", "tables"), Collections.singleton("prom")); + Assertions.assertEquals("information_schema", + dataSourceSchemaIdentifierNameResolver.getSchemaName()); + Assertions.assertEquals("prom", dataSourceSchemaIdentifierNameResolver.getDataSourceName()); + Assertions.assertEquals("tables", dataSourceSchemaIdentifierNameResolver.getIdentifierName()); + } + +} diff --git a/core/src/test/java/org/opensearch/sql/config/TestConfig.java b/core/src/test/java/org/opensearch/sql/config/TestConfig.java index 7475f577a6..a0ef436162 100644 --- a/core/src/test/java/org/opensearch/sql/config/TestConfig.java +++ b/core/src/test/java/org/opensearch/sql/config/TestConfig.java @@ -8,7 +8,7 @@ import com.google.common.collect.ImmutableMap; import java.util.Map; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.analysis.symbol.Namespace; import org.opensearch.sql.analysis.symbol.Symbol; import org.opensearch.sql.analysis.symbol.SymbolTable; @@ -63,7 +63,7 @@ public class TestConfig { protected StorageEngine storageEngine() { return new StorageEngine() { @Override - public Table getTable(CatalogSchemaName catalogSchemaName, String name) { + public Table getTable(DataSourceSchemaName dataSourceSchemaName, String name) { return new Table() { @Override public boolean exists() { diff --git a/core/src/test/java/org/opensearch/sql/datasource/DataSourceServiceImplTest.java b/core/src/test/java/org/opensearch/sql/datasource/DataSourceServiceImplTest.java new file mode 100644 index 0000000000..2b40b32ee6 --- /dev/null +++ b/core/src/test/java/org/opensearch/sql/datasource/DataSourceServiceImplTest.java @@ -0,0 +1,158 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.datasource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; +import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; + +import com.google.common.collect.ImmutableMap; +import java.util.HashSet; +import java.util.Map; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.storage.DataSourceFactory; +import org.opensearch.sql.storage.StorageEngine; + +@ExtendWith(MockitoExtension.class) +class DataSourceServiceImplTest { + + static final String NAME = "opensearch"; + + @Mock private DataSourceFactory dataSourceFactory; + + @Mock private StorageEngine storageEngine; + + private DataSourceService dataSourceService; + + @BeforeEach + public void setup() { + lenient() + .doAnswer( + invocation -> { + DataSourceMetadata metadata = invocation.getArgument(0); + return new DataSource(metadata.getName(), metadata.getConnector(), storageEngine); + }) + .when(dataSourceFactory) + .createDataSource(any()); + when(dataSourceFactory.getDataSourceType()).thenReturn(DataSourceType.OPENSEARCH); + dataSourceService = + new DataSourceServiceImpl( + new HashSet<>() { + { + add(dataSourceFactory); + } + }); + } + + @AfterEach + public void clear() { + dataSourceService.clear(); + } + + @Test + void getDataSourceSuccess() { + dataSourceService.addDataSource(DataSourceMetadata.defaultOpenSearchDataSourceMetadata()); + + assertEquals( + new DataSource(DEFAULT_DATASOURCE_NAME, DataSourceType.OPENSEARCH, storageEngine), + dataSourceService.getDataSource(DEFAULT_DATASOURCE_NAME)); + } + + @Test + void getNotExistDataSourceShouldFail() { + IllegalArgumentException exception = + assertThrows(IllegalArgumentException.class, () -> dataSourceService.getDataSource("mock")); + assertEquals("DataSource with name mock doesn't exist.", exception.getMessage()); + } + + @Test + void getAddDataSourcesShouldSuccess() { + assertEquals(0, dataSourceService.getDataSources().size()); + + dataSourceService.addDataSource(metadata(NAME, DataSourceType.OPENSEARCH, ImmutableMap.of())); + assertEquals(1, dataSourceService.getDataSources().size()); + } + + @Test + void noDataSourceExistAfterClear() { + dataSourceService.addDataSource(metadata(NAME, DataSourceType.OPENSEARCH, ImmutableMap.of())); + assertEquals(1, dataSourceService.getDataSources().size()); + + dataSourceService.clear(); + assertEquals(0, dataSourceService.getDataSources().size()); + } + + @Test + void metaDataMissingNameShouldFail() { + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + dataSourceService.addDataSource( + metadata(null, DataSourceType.OPENSEARCH, ImmutableMap.of()))); + assertEquals( + "Missing Name Field from a DataSource. Name is a required parameter.", + exception.getMessage()); + } + + @Test + void metaDataHasIllegalDataSourceNameShouldFail() { + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + dataSourceService.addDataSource( + metadata("prometheus.test", DataSourceType.OPENSEARCH, ImmutableMap.of()))); + assertEquals( + "DataSource Name: prometheus.test contains illegal characters. " + + "Allowed characters: a-zA-Z0-9_-*@.", + exception.getMessage()); + } + + @Test + void metaDataMissingPropertiesShouldFail() { + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> dataSourceService.addDataSource(metadata(NAME, DataSourceType.OPENSEARCH, null))); + assertEquals( + "Missing properties field in catalog configuration. Properties are required parameters.", + exception.getMessage()); + } + + @Test + void metaDataHasDuplicateNameShouldFail() { + dataSourceService.addDataSource(metadata(NAME, DataSourceType.OPENSEARCH, ImmutableMap.of())); + assertEquals(1, dataSourceService.getDataSources().size()); + + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> dataSourceService.addDataSource(metadata(NAME, DataSourceType.OPENSEARCH, null))); + assertEquals( + String.format("Datasource name should be unique, Duplicate datasource found %s.", NAME), + exception.getMessage()); + } + + DataSourceMetadata metadata(String name, DataSourceType type, Map properties) { + DataSourceMetadata dataSourceMetadata = new DataSourceMetadata(); + dataSourceMetadata.setName(name); + dataSourceMetadata.setConnector(type); + dataSourceMetadata.setProperties(properties); + return dataSourceMetadata; + } +} diff --git a/core/src/test/java/org/opensearch/sql/datasource/model/auth/AuthenticationTypeTest.java b/core/src/test/java/org/opensearch/sql/datasource/model/auth/AuthenticationTypeTest.java new file mode 100644 index 0000000000..f9e4f3ce59 --- /dev/null +++ b/core/src/test/java/org/opensearch/sql/datasource/model/auth/AuthenticationTypeTest.java @@ -0,0 +1,29 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.datasource.model.auth; + + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + +class AuthenticationTypeTest { + @Test + void getAuthType() { + assertEquals( + AuthenticationType.BASICAUTH, + AuthenticationType.get(AuthenticationType.BASICAUTH.getName())); + assertEquals( + AuthenticationType.AWSSIGV4AUTH, + AuthenticationType.get(AuthenticationType.AWSSIGV4AUTH.getName())); + } + + @Test + void getNotExistAuthType() { + assertNull(AuthenticationType.get("mock")); + } +} diff --git a/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java b/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java index 1a72fd9c3d..c2763e7120 100644 --- a/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java +++ b/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java @@ -64,9 +64,9 @@ class ExplainTest extends ExpressionTestBase { @Test void can_explain_project_filter_table_scan() { Expression filterExpr = - dsl.and( - dsl.equal(ref("balance", INTEGER), literal(10000)), - dsl.greater(ref("age", INTEGER), literal(30))); + DSL.and( + DSL.equal(ref("balance", INTEGER), literal(10000)), + DSL.greater(ref("age", INTEGER), literal(30))); NamedExpression[] projectList = { named("full_name", ref("full_name", STRING), "name"), named("age", ref("age", INTEGER)) @@ -95,7 +95,7 @@ void can_explain_project_filter_table_scan() { void can_explain_aggregations() { List aggExprs = ImmutableList.of(ref("balance", DOUBLE)); List aggList = ImmutableList.of( - named("avg(balance)", dsl.avg(aggExprs.toArray(new Expression[0])))); + named("avg(balance)", DSL.avg(aggExprs.toArray(new Expression[0])))); List groupByList = ImmutableList.of( named("state", ref("state", STRING))); @@ -135,7 +135,7 @@ void can_explain_window() { List> sortList = ImmutableList.of( ImmutablePair.of(DEFAULT_ASC, ref("age", INTEGER))); - PhysicalPlan plan = window(tableScan, named(dsl.rank()), + PhysicalPlan plan = window(tableScan, named(DSL.rank()), new WindowDefinition(partitionByList, sortList)); assertEquals( @@ -160,7 +160,7 @@ void can_explain_other_operators() { Map renameMapping = ImmutableMap.of( ref("state", STRING), ref("s", STRING)); Pair evalExprs = ImmutablePair.of( - ref("age", INTEGER), dsl.add(ref("age", INTEGER), literal(2))); + ref("age", INTEGER), DSL.add(ref("age", INTEGER), literal(2))); Expression[] dedupeList = {ref("age", INTEGER)}; Pair sortList = ImmutablePair.of( DEFAULT_ASC, ref("age", INTEGER)); diff --git a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java index b1b22bedb1..47fe9dad0f 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java @@ -24,14 +24,11 @@ import org.opensearch.sql.expression.aggregation.AvgAggregator; import org.opensearch.sql.expression.conditional.cases.CaseClause; import org.opensearch.sql.expression.conditional.cases.WhenClause; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.parse.ParseExpression; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class ExpressionNodeVisitorTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - @Test void should_return_null_by_default() { ExpressionNodeVisitor visitor = new ExpressionNodeVisitor(){}; @@ -39,13 +36,13 @@ void should_return_null_by_default() { assertNull(literal(10).accept(visitor, null)); assertNull(ref("name", STRING).accept(visitor, null)); assertNull(named("bool", literal(true)).accept(visitor, null)); - assertNull(dsl.abs(literal(-10)).accept(visitor, null)); - assertNull(dsl.sum(literal(10)).accept(visitor, null)); + assertNull(DSL.abs(literal(-10)).accept(visitor, null)); + assertNull(DSL.sum(literal(10)).accept(visitor, null)); assertNull(named("avg", new AvgAggregator(Collections.singletonList(ref("age", INTEGER)), INTEGER)).accept(visitor, null)); assertNull(new CaseClause(ImmutableList.of(), null).accept(visitor, null)); assertNull(new WhenClause(literal("test"), literal(10)).accept(visitor, null)); - assertNull(dsl.namedArgument("field", literal("message")).accept(visitor, null)); + assertNull(DSL.namedArgument("field", literal("message")).accept(visitor, null)); assertNull(DSL.span(ref("age", INTEGER), literal(1), "").accept(visitor, null)); assertNull(DSL.regex(ref("name", STRING), DSL.literal("(?\\d+)"), DSL.literal("group")) .accept(visitor, null)); @@ -55,9 +52,9 @@ void should_return_null_by_default() { void can_visit_all_types_of_expression_node() { Expression expr = DSL.regex( - dsl.castString( - dsl.sum( - dsl.add( + DSL.castString( + DSL.sum( + DSL.add( ref("balance", INTEGER), literal(10)) )), @@ -82,12 +79,12 @@ public Expression visitParse(ParseExpression node, Object context) { @Override public Expression visitFunction(FunctionExpression node, Object context) { - return dsl.add(visitArguments(node.getArguments(), context)); + return DSL.add(visitArguments(node.getArguments(), context)); } @Override public Expression visitAggregator(Aggregator node, Object context) { - return dsl.sum(visitArguments(node.getArguments(), context)); + return DSL.sum(visitArguments(node.getArguments(), context)); } private Expression[] visitArguments(List arguments, Object context) { diff --git a/core/src/test/java/org/opensearch/sql/expression/ExpressionTestBase.java b/core/src/test/java/org/opensearch/sql/expression/ExpressionTestBase.java index fea985042a..d2154e26f4 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionTestBase.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionTestBase.java @@ -33,7 +33,6 @@ import org.opensearch.sql.config.TestConfig; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.type.ExprType; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.BuiltinFunctionName; import org.springframework.beans.factory.annotation.Autowired; @@ -44,11 +43,9 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, ExpressionTestBase.class, +@ContextConfiguration(classes = {ExpressionTestBase.class, TestConfig.class}) public class ExpressionTestBase { - @Autowired - protected DSL dsl; @Autowired protected Environment typeEnv; @@ -102,15 +99,15 @@ protected Function, FunctionExpression> functionMapping( BuiltinFunctionName builtinFunctionName) { switch (builtinFunctionName) { case ADD: - return (expressions) -> dsl.add(expressions.get(0), expressions.get(1)); + return (expressions) -> DSL.add(expressions.get(0), expressions.get(1)); case SUBTRACT: - return (expressions) -> dsl.subtract(expressions.get(0), expressions.get(1)); + return (expressions) -> DSL.subtract(expressions.get(0), expressions.get(1)); case MULTIPLY: - return (expressions) -> dsl.multiply(expressions.get(0), expressions.get(1)); + return (expressions) -> DSL.multiply(expressions.get(0), expressions.get(1)); case DIVIDE: - return (expressions) -> dsl.divide(expressions.get(0), expressions.get(1)); + return (expressions) -> DSL.divide(expressions.get(0), expressions.get(1)); case MODULES: - return (expressions) -> dsl.module(expressions.get(0), expressions.get(1)); + return (expressions) -> DSL.module(expressions.get(0), expressions.get(1)); default: throw new RuntimeException(); } diff --git a/core/src/test/java/org/opensearch/sql/expression/NamedArgumentExpressionTest.java b/core/src/test/java/org/opensearch/sql/expression/NamedArgumentExpressionTest.java index dad701d802..e4e3f55111 100644 --- a/core/src/test/java/org/opensearch/sql/expression/NamedArgumentExpressionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/NamedArgumentExpressionTest.java @@ -16,7 +16,7 @@ public class NamedArgumentExpressionTest extends ExpressionTestBase { @Test void name_an_argument() { LiteralExpression value = DSL.literal("search"); - NamedArgumentExpression namedArgument = dsl.namedArgument("query", value); + NamedArgumentExpression namedArgument = DSL.namedArgument("query", value); assertEquals("query", namedArgument.getArgName()); assertEquals(value.type(), namedArgument.type()); diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java index 93d327257f..1fb7a1061c 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java @@ -22,62 +22,62 @@ class AvgAggregatorTest extends AggregationTest { @Test public void avg_field_expression() { - ExprValue result = aggregation(dsl.avg(DSL.ref("integer_value", INTEGER)), tuples); + ExprValue result = aggregation(DSL.avg(DSL.ref("integer_value", INTEGER)), tuples); assertEquals(2.5, result.value()); } @Test public void avg_arithmetic_expression() { - ExprValue result = aggregation(dsl.avg( - dsl.multiply(DSL.ref("integer_value", INTEGER), + ExprValue result = aggregation(DSL.avg( + DSL.multiply(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))), tuples); assertEquals(25.0, result.value()); } @Test public void filtered_avg() { - ExprValue result = aggregation(dsl.avg(DSL.ref("integer_value", INTEGER)) - .condition(dsl.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); + ExprValue result = aggregation(DSL.avg(DSL.ref("integer_value", INTEGER)) + .condition(DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); assertEquals(3.0, result.value()); } @Test public void avg_with_missing() { ExprValue result = - aggregation(dsl.avg(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); + aggregation(DSL.avg(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); assertEquals(1.5, result.value()); } @Test public void avg_with_null() { ExprValue result = - aggregation(dsl.avg(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); + aggregation(DSL.avg(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); assertEquals(3.5, result.value()); } @Test public void avg_with_all_missing_or_null() { ExprValue result = - aggregation(dsl.avg(DSL.ref("integer_value", INTEGER)), tuples_with_all_null_or_missing); + aggregation(DSL.avg(DSL.ref("integer_value", INTEGER)), tuples_with_all_null_or_missing); assertTrue(result.isNull()); } @Test public void valueOf() { ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> dsl.avg(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); + () -> DSL.avg(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); assertEquals("can't evaluate on aggregator: avg", exception.getMessage()); } @Test public void test_to_string() { - Aggregator avgAggregator = dsl.avg(DSL.ref("integer_value", INTEGER)); + Aggregator avgAggregator = DSL.avg(DSL.ref("integer_value", INTEGER)); assertEquals("avg(integer_value)", avgAggregator.toString()); } @Test public void test_nested_to_string() { - Aggregator avgAggregator = dsl.avg(dsl.multiply(DSL.ref("integer_value", INTEGER), + Aggregator avgAggregator = DSL.avg(DSL.multiply(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))); assertEquals(String.format("avg(*(%s, %d))", DSL.ref("integer_value", INTEGER), 10), avgAggregator.toString()); diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java index 5ea19e4e92..fd27529a70 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java @@ -30,159 +30,159 @@ class CountAggregatorTest extends AggregationTest { @Test public void count_integer_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("integer_value", INTEGER)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("integer_value", INTEGER)), tuples); assertEquals(4, result.value()); } @Test public void count_long_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("long_value", LONG)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("long_value", LONG)), tuples); assertEquals(4, result.value()); } @Test public void count_float_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("float_value", FLOAT)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("float_value", FLOAT)), tuples); assertEquals(4, result.value()); } @Test public void count_double_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("double_value", DOUBLE)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("double_value", DOUBLE)), tuples); assertEquals(4, result.value()); } @Test public void count_date_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("date_value", DATE)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("date_value", DATE)), tuples); assertEquals(4, result.value()); } @Test public void count_timestamp_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("timestamp_value", TIMESTAMP)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("timestamp_value", TIMESTAMP)), tuples); assertEquals(4, result.value()); } @Test public void count_datetime_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("datetime_value", DATETIME)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("datetime_value", DATETIME)), tuples); assertEquals(4, result.value()); } @Test public void count_arithmetic_expression() { - ExprValue result = aggregation(dsl.count( - dsl.multiply(DSL.ref("integer_value", INTEGER), + ExprValue result = aggregation(DSL.count( + DSL.multiply(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))), tuples); assertEquals(4, result.value()); } @Test public void count_string_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("string_value", STRING)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("string_value", STRING)), tuples); assertEquals(4, result.value()); } @Test public void count_boolean_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("boolean_value", BOOLEAN)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("boolean_value", BOOLEAN)), tuples); assertEquals(1, result.value()); } @Test public void count_struct_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("struct_value", STRUCT)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("struct_value", STRUCT)), tuples); assertEquals(1, result.value()); } @Test public void count_array_field_expression() { - ExprValue result = aggregation(dsl.count(DSL.ref("array_value", ARRAY)), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("array_value", ARRAY)), tuples); assertEquals(1, result.value()); } @Test public void filtered_count() { - ExprValue result = aggregation(dsl.count(DSL.ref("integer_value", INTEGER)) - .condition(dsl.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); + ExprValue result = aggregation(DSL.count(DSL.ref("integer_value", INTEGER)) + .condition(DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); assertEquals(3, result.value()); } @Test public void distinct_count() { - ExprValue result = aggregation(dsl.distinctCount(DSL.ref("integer_value", INTEGER)), + ExprValue result = aggregation(DSL.distinctCount(DSL.ref("integer_value", INTEGER)), tuples_with_duplicates); assertEquals(3, result.value()); } @Test public void filtered_distinct_count() { - ExprValue result = aggregation(dsl.distinctCount(DSL.ref("integer_value", INTEGER)) - .condition(dsl.greater(DSL.ref("double_value", DOUBLE), DSL.literal(1d))), + ExprValue result = aggregation(DSL.distinctCount(DSL.ref("integer_value", INTEGER)) + .condition(DSL.greater(DSL.ref("double_value", DOUBLE), DSL.literal(1d))), tuples_with_duplicates); assertEquals(2, result.value()); } @Test public void distinct_count_map() { - ExprValue result = aggregation(dsl.distinctCount(DSL.ref("struct_value", STRUCT)), + ExprValue result = aggregation(DSL.distinctCount(DSL.ref("struct_value", STRUCT)), tuples_with_duplicates); assertEquals(3, result.value()); } @Test public void distinct_count_array() { - ExprValue result = aggregation(dsl.distinctCount(DSL.ref("array_value", ARRAY)), + ExprValue result = aggregation(DSL.distinctCount(DSL.ref("array_value", ARRAY)), tuples_with_duplicates); assertEquals(3, result.value()); } @Test public void count_with_missing() { - ExprValue result = aggregation(dsl.count(DSL.ref("integer_value", INTEGER)), + ExprValue result = aggregation(DSL.count(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); assertEquals(2, result.value()); } @Test public void count_with_null() { - ExprValue result = aggregation(dsl.count(DSL.ref("double_value", DOUBLE)), + ExprValue result = aggregation(DSL.count(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); assertEquals(2, result.value()); } @Test public void count_star_with_null_and_missing() { - ExprValue result = aggregation(dsl.count(DSL.literal("*")), tuples_with_null_and_missing); + ExprValue result = aggregation(DSL.count(DSL.literal("*")), tuples_with_null_and_missing); assertEquals(3, result.value()); } @Test public void count_literal_with_null_and_missing() { - ExprValue result = aggregation(dsl.count(DSL.literal(1)), tuples_with_null_and_missing); + ExprValue result = aggregation(DSL.count(DSL.literal(1)), tuples_with_null_and_missing); assertEquals(3, result.value()); } @Test public void valueOf() { ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> dsl.count(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); + () -> DSL.count(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); assertEquals("can't evaluate on aggregator: count", exception.getMessage()); } @Test public void test_to_string() { - Aggregator countAggregator = dsl.count(DSL.ref("integer_value", INTEGER)); + Aggregator countAggregator = DSL.count(DSL.ref("integer_value", INTEGER)); assertEquals("count(integer_value)", countAggregator.toString()); - countAggregator = dsl.distinctCount(DSL.ref("integer_value", INTEGER)); + countAggregator = DSL.distinctCount(DSL.ref("integer_value", INTEGER)); assertEquals("count(distinct integer_value)", countAggregator.toString()); } @Test public void test_nested_to_string() { - Aggregator countAggregator = dsl.count(dsl.abs(DSL.ref("integer_value", INTEGER))); + Aggregator countAggregator = DSL.count(DSL.abs(DSL.ref("integer_value", INTEGER))); assertEquals(String.format("count(abs(%s))", DSL.ref("integer_value", INTEGER)), countAggregator.toString()); } diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java index 4c06716ee9..6886622704 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java @@ -29,110 +29,110 @@ public class MaxAggregatorTest extends AggregationTest { @Test public void test_max_integer() { - ExprValue result = aggregation(dsl.max(DSL.ref("integer_value", INTEGER)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("integer_value", INTEGER)), tuples); assertEquals(4, result.value()); } @Test public void test_max_long() { - ExprValue result = aggregation(dsl.max(DSL.ref("long_value", LONG)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("long_value", LONG)), tuples); assertEquals(4L, result.value()); } @Test public void test_max_float() { - ExprValue result = aggregation(dsl.max(DSL.ref("float_value", FLOAT)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("float_value", FLOAT)), tuples); assertEquals(4F, result.value()); } @Test public void test_max_double() { - ExprValue result = aggregation(dsl.max(DSL.ref("double_value", DOUBLE)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("double_value", DOUBLE)), tuples); assertEquals(4D, result.value()); } @Test public void test_max_string() { - ExprValue result = aggregation(dsl.max(DSL.ref("string_value", STRING)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("string_value", STRING)), tuples); assertEquals("n", result.value()); } @Test public void test_max_date() { - ExprValue result = aggregation(dsl.max(DSL.ref("date_value", DATE)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("date_value", DATE)), tuples); assertEquals("2040-01-01", result.value()); } @Test public void test_max_datetime() { - ExprValue result = aggregation(dsl.max(DSL.ref("datetime_value", DATETIME)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("datetime_value", DATETIME)), tuples); assertEquals("2040-01-01 07:00:00", result.value()); } @Test public void test_max_time() { - ExprValue result = aggregation(dsl.max(DSL.ref("time_value", TIME)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("time_value", TIME)), tuples); assertEquals("19:00:00", result.value()); } @Test public void test_max_timestamp() { - ExprValue result = aggregation(dsl.max(DSL.ref("timestamp_value", TIMESTAMP)), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("timestamp_value", TIMESTAMP)), tuples); assertEquals("2040-01-01 07:00:00", result.value()); } @Test public void test_max_arithmetic_expression() { ExprValue result = aggregation( - dsl.max(dsl.add(DSL.ref("integer_value", INTEGER), + DSL.max(DSL.add(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(0)))), tuples); assertEquals(4, result.value()); } @Test public void filtered_max() { - ExprValue result = aggregation(dsl.max(DSL.ref("integer_value", INTEGER)) - .condition(dsl.less(DSL.ref("integer_value", INTEGER), DSL.literal(4))), tuples); + ExprValue result = aggregation(DSL.max(DSL.ref("integer_value", INTEGER)) + .condition(DSL.less(DSL.ref("integer_value", INTEGER), DSL.literal(4))), tuples); assertEquals(3, result.value()); } @Test public void test_max_null() { ExprValue result = - aggregation(dsl.max(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); + aggregation(DSL.max(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); assertEquals(4.0, result.value()); } @Test public void test_max_missing() { ExprValue result = - aggregation(dsl.max(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); + aggregation(DSL.max(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); assertEquals(2, result.value()); } @Test public void test_max_all_missing_or_null() { ExprValue result = - aggregation(dsl.max(DSL.ref("integer_value", INTEGER)), tuples_with_all_null_or_missing); + aggregation(DSL.max(DSL.ref("integer_value", INTEGER)), tuples_with_all_null_or_missing); assertTrue(result.isNull()); } @Test public void test_value_of() { ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> dsl.max(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); + () -> DSL.max(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); assertEquals("can't evaluate on aggregator: max", exception.getMessage()); } @Test public void test_to_string() { - Aggregator maxAggregator = dsl.max(DSL.ref("integer_value", INTEGER)); + Aggregator maxAggregator = DSL.max(DSL.ref("integer_value", INTEGER)); assertEquals("max(integer_value)", maxAggregator.toString()); } @Test public void test_nested_to_string() { - Aggregator maxAggregator = dsl.max(dsl.add(DSL.ref("integer_value", INTEGER), + Aggregator maxAggregator = DSL.max(DSL.add(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))); assertEquals(String.format("max(+(%s, %d))", DSL.ref("integer_value", INTEGER), 10), maxAggregator.toString()); diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java index e9fe8c102a..1437f4dfda 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java @@ -29,110 +29,110 @@ public class MinAggregatorTest extends AggregationTest { @Test public void test_min_integer() { - ExprValue result = aggregation(dsl.min(DSL.ref("integer_value", INTEGER)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("integer_value", INTEGER)), tuples); assertEquals(1, result.value()); } @Test public void test_min_long() { - ExprValue result = aggregation(dsl.min(DSL.ref("long_value", LONG)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("long_value", LONG)), tuples); assertEquals(1L, result.value()); } @Test public void test_min_float() { - ExprValue result = aggregation(dsl.min(DSL.ref("float_value", FLOAT)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("float_value", FLOAT)), tuples); assertEquals(1F, result.value()); } @Test public void test_min_double() { - ExprValue result = aggregation(dsl.min(DSL.ref("double_value", DOUBLE)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("double_value", DOUBLE)), tuples); assertEquals(1D, result.value()); } @Test public void test_min_string() { - ExprValue result = aggregation(dsl.min(DSL.ref("string_value", STRING)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("string_value", STRING)), tuples); assertEquals("f", result.value()); } @Test public void test_min_date() { - ExprValue result = aggregation(dsl.min(DSL.ref("date_value", DATE)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("date_value", DATE)), tuples); assertEquals("1970-01-01", result.value()); } @Test public void test_min_datetime() { - ExprValue result = aggregation(dsl.min(DSL.ref("datetime_value", DATETIME)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("datetime_value", DATETIME)), tuples); assertEquals("1970-01-01 19:00:00", result.value()); } @Test public void test_min_time() { - ExprValue result = aggregation(dsl.min(DSL.ref("time_value", TIME)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("time_value", TIME)), tuples); assertEquals("00:00:00", result.value()); } @Test public void test_min_timestamp() { - ExprValue result = aggregation(dsl.min(DSL.ref("timestamp_value", TIMESTAMP)), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("timestamp_value", TIMESTAMP)), tuples); assertEquals("1970-01-01 19:00:00", result.value()); } @Test public void test_min_arithmetic_expression() { ExprValue result = aggregation( - dsl.min(dsl.add(DSL.ref("integer_value", INTEGER), + DSL.min(DSL.add(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(0)))), tuples); assertEquals(1, result.value()); } @Test public void filtered_min() { - ExprValue result = aggregation(dsl.min(DSL.ref("integer_value", INTEGER)) - .condition(dsl.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); + ExprValue result = aggregation(DSL.min(DSL.ref("integer_value", INTEGER)) + .condition(DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); assertEquals(2, result.value()); } @Test public void test_min_null() { ExprValue result = - aggregation(dsl.min(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); + aggregation(DSL.min(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); assertEquals(3.0, result.value()); } @Test public void test_min_missing() { ExprValue result = - aggregation(dsl.min(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); + aggregation(DSL.min(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); assertEquals(1, result.value()); } @Test public void test_min_all_missing_or_null() { ExprValue result = - aggregation(dsl.min(DSL.ref("integer_value", INTEGER)), tuples_with_all_null_or_missing); + aggregation(DSL.min(DSL.ref("integer_value", INTEGER)), tuples_with_all_null_or_missing); assertTrue(result.isNull()); } @Test public void test_value_of() { ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> dsl.min(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); + () -> DSL.min(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); assertEquals("can't evaluate on aggregator: min", exception.getMessage()); } @Test public void test_to_string() { - Aggregator minAggregator = dsl.min(DSL.ref("integer_value", INTEGER)); + Aggregator minAggregator = DSL.min(DSL.ref("integer_value", INTEGER)); assertEquals("min(integer_value)", minAggregator.toString()); } @Test public void test_nested_to_string() { - Aggregator minAggregator = dsl.min(dsl.add(DSL.ref("integer_value", INTEGER), + Aggregator minAggregator = DSL.min(DSL.add(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))); assertEquals(String.format("min(+(%s, %d))", DSL.ref("integer_value", INTEGER), 10), minAggregator.toString()); diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/StdDevAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/StdDevAggregatorTest.java index ef085a81d3..fe4923d4df 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/StdDevAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/StdDevAggregatorTest.java @@ -67,7 +67,7 @@ public void stddev_population_field_expression() { public void stddev_sample_arithmetic_expression() { ExprValue result = aggregation( - dsl.stddevSamp(dsl.multiply(ref("integer_value", INTEGER), DSL.literal(10))), tuples); + DSL.stddevSamp(DSL.multiply(ref("integer_value", INTEGER), DSL.literal(10))), tuples); assertEquals(12.909944487358056, result.value()); } @@ -75,7 +75,7 @@ public void stddev_sample_arithmetic_expression() { public void stddev_population_arithmetic_expression() { ExprValue result = aggregation( - dsl.stddevPop(dsl.multiply(ref("integer_value", INTEGER), DSL.literal(10))), tuples); + DSL.stddevPop(DSL.multiply(ref("integer_value", INTEGER), DSL.literal(10))), tuples); assertEquals(11.180339887498949, result.value()); } @@ -83,8 +83,8 @@ public void stddev_population_arithmetic_expression() { public void filtered_stddev_sample() { ExprValue result = aggregation( - dsl.stddevSamp(ref("integer_value", INTEGER)) - .condition(dsl.greater(ref("integer_value", INTEGER), DSL.literal(1))), + DSL.stddevSamp(ref("integer_value", INTEGER)) + .condition(DSL.greater(ref("integer_value", INTEGER), DSL.literal(1))), tuples); assertEquals(1.0, result.value()); } @@ -93,8 +93,8 @@ public void filtered_stddev_sample() { public void filtered_stddev_population() { ExprValue result = aggregation( - dsl.stddevPop(ref("integer_value", INTEGER)) - .condition(dsl.greater(ref("integer_value", INTEGER), DSL.literal(1))), + DSL.stddevPop(ref("integer_value", INTEGER)) + .condition(DSL.greater(ref("integer_value", INTEGER), DSL.literal(1))), tuples); assertEquals(0.816496580927726, result.value()); } @@ -137,21 +137,21 @@ public void stddev_pop_with_all_missing_or_null() { @Test public void stddev_sample_to_string() { - Aggregator aggregator = dsl.stddevSamp(ref("integer_value", INTEGER)); + Aggregator aggregator = DSL.stddevSamp(ref("integer_value", INTEGER)); assertEquals("stddev_samp(integer_value)", aggregator.toString()); } @Test public void stddev_pop_to_string() { - Aggregator aggregator = dsl.stddevPop(ref("integer_value", INTEGER)); + Aggregator aggregator = DSL.stddevPop(ref("integer_value", INTEGER)); assertEquals("stddev_pop(integer_value)", aggregator.toString()); } @Test public void stddev_sample_nested_to_string() { Aggregator avgAggregator = - dsl.stddevSamp( - dsl.multiply( + DSL.stddevSamp( + DSL.multiply( ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))); assertEquals( String.format("stddev_samp(*(%s, %d))", ref("integer_value", INTEGER), 10), @@ -161,13 +161,13 @@ public void stddev_sample_nested_to_string() { private ExprValue stddevSample(ExprValue value, ExprValue... values) { when(expression.valueOf(any())).thenReturn(value, values); when(expression.type()).thenReturn(DOUBLE); - return aggregation(dsl.stddevSamp(expression), mockTuples(value, values)); + return aggregation(DSL.stddevSamp(expression), mockTuples(value, values)); } private ExprValue stddevPop(ExprValue value, ExprValue... values) { when(expression.valueOf(any())).thenReturn(value, values); when(expression.type()).thenReturn(DOUBLE); - return aggregation(dsl.stddevPop(expression), mockTuples(value, values)); + return aggregation(DSL.stddevPop(expression), mockTuples(value, values)); } private List mockTuples(ExprValue value, ExprValue... values) { diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/SumAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/SumAggregatorTest.java index 3b534e0a54..676306041e 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/SumAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/SumAggregatorTest.java @@ -29,32 +29,32 @@ class SumAggregatorTest extends AggregationTest { @Test public void sum_integer_field_expression() { - ExprValue result = aggregation(dsl.sum(DSL.ref("integer_value", INTEGER)), tuples); + ExprValue result = aggregation(DSL.sum(DSL.ref("integer_value", INTEGER)), tuples); assertEquals(10, result.value()); } @Test public void sum_long_field_expression() { - ExprValue result = aggregation(dsl.sum(DSL.ref("long_value", LONG)), tuples); + ExprValue result = aggregation(DSL.sum(DSL.ref("long_value", LONG)), tuples); assertEquals(10L, result.value()); } @Test public void sum_float_field_expression() { - ExprValue result = aggregation(dsl.sum(DSL.ref("float_value", FLOAT)), tuples); + ExprValue result = aggregation(DSL.sum(DSL.ref("float_value", FLOAT)), tuples); assertEquals(10f, result.value()); } @Test public void sum_double_field_expression() { - ExprValue result = aggregation(dsl.sum(DSL.ref("double_value", DOUBLE)), tuples); + ExprValue result = aggregation(DSL.sum(DSL.ref("double_value", DOUBLE)), tuples); assertEquals(10d, result.value()); } @Test public void sum_arithmetic_expression() { - ExprValue result = aggregation(dsl.sum( - dsl.multiply(DSL.ref("integer_value", INTEGER), + ExprValue result = aggregation(DSL.sum( + DSL.multiply(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))), tuples); assertEquals(100, result.value()); } @@ -75,48 +75,48 @@ public void sum_string_field_expression() { @Test public void filtered_sum() { - ExprValue result = aggregation(dsl.sum(DSL.ref("integer_value", INTEGER)) - .condition(dsl.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); + ExprValue result = aggregation(DSL.sum(DSL.ref("integer_value", INTEGER)) + .condition(DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); assertEquals(9, result.value()); } @Test public void sum_with_missing() { ExprValue result = - aggregation(dsl.sum(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); + aggregation(DSL.sum(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); assertEquals(3, result.value()); } @Test public void sum_with_null() { ExprValue result = - aggregation(dsl.sum(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); + aggregation(DSL.sum(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); assertEquals(7.0, result.value()); } @Test public void sum_with_all_missing_or_null() { ExprValue result = - aggregation(dsl.sum(DSL.ref("double_value", DOUBLE)), tuples_with_all_null_or_missing); + aggregation(DSL.sum(DSL.ref("double_value", DOUBLE)), tuples_with_all_null_or_missing); assertTrue(result.isNull()); } @Test public void valueOf() { ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> dsl.sum(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); + () -> DSL.sum(DSL.ref("double_value", DOUBLE)).valueOf(valueEnv())); assertEquals("can't evaluate on aggregator: sum", exception.getMessage()); } @Test public void test_to_string() { - Aggregator sumAggregator = dsl.sum(DSL.ref("integer_value", INTEGER)); + Aggregator sumAggregator = DSL.sum(DSL.ref("integer_value", INTEGER)); assertEquals("sum(integer_value)", sumAggregator.toString()); } @Test public void test_nested_to_string() { - Aggregator sumAggregator = dsl.sum(dsl.multiply(DSL.ref("integer_value", INTEGER), + Aggregator sumAggregator = DSL.sum(DSL.multiply(DSL.ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))); assertEquals(String.format("sum(*(%s, %d))", DSL.ref("integer_value", INTEGER), 10), sumAggregator.toString()); diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/TakeAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/TakeAggregatorTest.java index 900d0d1963..6d9aac4957 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/TakeAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/TakeAggregatorTest.java @@ -21,29 +21,29 @@ class TakeAggregatorTest extends AggregationTest { @Test public void take_string_field_expression() { ExprValue result = - aggregation(dsl.take(DSL.ref("string_value", STRING), DSL.literal(2)), tuples); + aggregation(DSL.take(DSL.ref("string_value", STRING), DSL.literal(2)), tuples); assertEquals(ImmutableList.of("m", "f"), result.value()); } @Test public void take_string_field_expression_with_large_size() { ExprValue result = - aggregation(dsl.take(DSL.ref("string_value", STRING), DSL.literal(10)), tuples); + aggregation(DSL.take(DSL.ref("string_value", STRING), DSL.literal(10)), tuples); assertEquals(ImmutableList.of("m", "f", "m", "n"), result.value()); } @Test public void filtered_take() { ExprValue result = - aggregation(dsl.take(DSL.ref("string_value", STRING), DSL.literal(10)) - .condition(dsl.equal(DSL.ref("string_value", STRING), DSL.literal("m"))), tuples); + aggregation(DSL.take(DSL.ref("string_value", STRING), DSL.literal(10)) + .condition(DSL.equal(DSL.ref("string_value", STRING), DSL.literal("m"))), tuples); assertEquals(ImmutableList.of("m", "m"), result.value()); } @Test public void test_take_null() { ExprValue result = - aggregation(dsl.take(DSL.ref("string_value", STRING), DSL.literal(10)), + aggregation(DSL.take(DSL.ref("string_value", STRING), DSL.literal(10)), tuples_with_null_and_missing); assertEquals(ImmutableList.of("m", "f"), result.value()); } @@ -51,7 +51,7 @@ public void test_take_null() { @Test public void test_take_missing() { ExprValue result = - aggregation(dsl.take(DSL.ref("string_value", STRING), DSL.literal(10)), + aggregation(DSL.take(DSL.ref("string_value", STRING), DSL.literal(10)), tuples_with_null_and_missing); assertEquals(ImmutableList.of("m", "f"), result.value()); } @@ -59,7 +59,7 @@ public void test_take_missing() { @Test public void test_take_all_missing_or_null() { ExprValue result = - aggregation(dsl.take(DSL.ref("string_value", STRING), DSL.literal(10)), + aggregation(DSL.take(DSL.ref("string_value", STRING), DSL.literal(10)), tuples_with_all_null_or_missing); assertEquals(ImmutableList.of(), result.value()); } @@ -67,20 +67,20 @@ public void test_take_all_missing_or_null() { @Test public void test_take_with_invalid_size() { IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, - () -> aggregation(dsl.take(DSL.ref("string_value", STRING), DSL.literal(0)), tuples)); + () -> aggregation(DSL.take(DSL.ref("string_value", STRING), DSL.literal(0)), tuples)); assertEquals("size must be greater than 0", exception.getMessage()); } @Test public void test_value_of() { ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> dsl.take(DSL.ref("string_value", STRING), DSL.literal(10)).valueOf(valueEnv())); + () -> DSL.take(DSL.ref("string_value", STRING), DSL.literal(10)).valueOf(valueEnv())); assertEquals("can't evaluate on aggregator: take", exception.getMessage()); } @Test public void test_to_string() { - Aggregator takeAggregator = dsl.take(DSL.ref("string_value", STRING), DSL.literal(10)); + Aggregator takeAggregator = DSL.take(DSL.ref("string_value", STRING), DSL.literal(10)); assertEquals("take(string_value,10)", takeAggregator.toString()); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/VarianceAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/VarianceAggregatorTest.java index 09fb8b8012..64ab6474ed 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/VarianceAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/VarianceAggregatorTest.java @@ -66,7 +66,7 @@ public void variance_population_field_expression() { public void variance_sample_arithmetic_expression() { ExprValue result = aggregation( - dsl.varSamp(dsl.multiply(ref("integer_value", INTEGER), DSL.literal(10))), tuples); + DSL.varSamp(DSL.multiply(ref("integer_value", INTEGER), DSL.literal(10))), tuples); assertEquals(166.66666666666666, result.value()); } @@ -74,7 +74,7 @@ public void variance_sample_arithmetic_expression() { public void variance_pop_arithmetic_expression() { ExprValue result = aggregation( - dsl.varPop(dsl.multiply(ref("integer_value", INTEGER), DSL.literal(10))), tuples); + DSL.varPop(DSL.multiply(ref("integer_value", INTEGER), DSL.literal(10))), tuples); assertEquals(125d, result.value()); } @@ -82,8 +82,8 @@ public void variance_pop_arithmetic_expression() { public void filtered_variance_sample() { ExprValue result = aggregation( - dsl.varSamp(ref("integer_value", INTEGER)) - .condition(dsl.greater(ref("integer_value", INTEGER), DSL.literal(1))), + DSL.varSamp(ref("integer_value", INTEGER)) + .condition(DSL.greater(ref("integer_value", INTEGER), DSL.literal(1))), tuples); assertEquals(1.0, result.value()); } @@ -92,8 +92,8 @@ public void filtered_variance_sample() { public void filtered_variance_pop() { ExprValue result = aggregation( - dsl.varPop(ref("integer_value", INTEGER)) - .condition(dsl.greater(ref("integer_value", INTEGER), DSL.literal(1))), + DSL.varPop(ref("integer_value", INTEGER)) + .condition(DSL.greater(ref("integer_value", INTEGER), DSL.literal(1))), tuples); assertEquals(0.6666666666666666, result.value()); } @@ -139,27 +139,27 @@ public void valueOf() { ExpressionEvaluationException exception = assertThrows( ExpressionEvaluationException.class, - () -> dsl.avg(ref("double_value", DOUBLE)).valueOf(valueEnv())); + () -> DSL.avg(ref("double_value", DOUBLE)).valueOf(valueEnv())); assertEquals("can't evaluate on aggregator: avg", exception.getMessage()); } @Test public void variance_sample_to_string() { - Aggregator avgAggregator = dsl.varSamp(ref("integer_value", INTEGER)); + Aggregator avgAggregator = DSL.varSamp(ref("integer_value", INTEGER)); assertEquals("var_samp(integer_value)", avgAggregator.toString()); } @Test public void variance_pop_to_string() { - Aggregator avgAggregator = dsl.varPop(ref("integer_value", INTEGER)); + Aggregator avgAggregator = DSL.varPop(ref("integer_value", INTEGER)); assertEquals("var_pop(integer_value)", avgAggregator.toString()); } @Test public void variance_sample_nested_to_string() { Aggregator avgAggregator = - dsl.varSamp( - dsl.multiply( + DSL.varSamp( + DSL.multiply( ref("integer_value", INTEGER), DSL.literal(ExprValueUtils.integerValue(10)))); assertEquals( String.format("var_samp(*(%s, %d))", ref("integer_value", INTEGER), 10), @@ -169,13 +169,13 @@ public void variance_sample_nested_to_string() { private ExprValue varianceSample(ExprValue value, ExprValue... values) { when(expression.valueOf(any())).thenReturn(value, values); when(expression.type()).thenReturn(DOUBLE); - return aggregation(dsl.varSamp(expression), mockTuples(value, values)); + return aggregation(DSL.varSamp(expression), mockTuples(value, values)); } private ExprValue variancePop(ExprValue value, ExprValue... values) { when(expression.valueOf(any())).thenReturn(value, values); when(expression.type()).thenReturn(DOUBLE); - return aggregation(dsl.varPop(expression), mockTuples(value, values)); + return aggregation(DSL.varPop(expression), mockTuples(value, values)); } private List mockTuples(ExprValue value, ExprValue... values) { diff --git a/core/src/test/java/org/opensearch/sql/expression/conditional/ConditionalFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/conditional/ConditionalFunctionTest.java index 4e26f89468..ae8b714dd8 100644 --- a/core/src/test/java/org/opensearch/sql/expression/conditional/ConditionalFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/conditional/ConditionalFunctionTest.java @@ -62,8 +62,8 @@ void case_value(int value, Expression cases = DSL.cases( DSL.literal(defaultVal), - DSL.when(dsl.equal(DSL.literal(cond1), DSL.literal(value)), DSL.literal(result1)), - DSL.when(dsl.equal(DSL.literal(cond2), DSL.literal(value)), DSL.literal(result2))); + DSL.when(DSL.equal(DSL.literal(cond1), DSL.literal(value)), DSL.literal(result1)), + DSL.when(DSL.equal(DSL.literal(cond2), DSL.literal(value)), DSL.literal(result2))); assertEquals( new ExprIntegerValue(expect.call()), diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java index 0da651fb54..38cb3c5a63 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java @@ -33,7 +33,7 @@ class ConvertTZTest extends ExpressionTestBase { @Test public void invalidDate() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2021-04-31 10:00:00")), DSL.literal("+00:00"), DSL.literal("+00:00")); @@ -43,7 +43,7 @@ public void invalidDate() { @Test public void conversionFromNoOffset() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("+10:00")); @@ -53,7 +53,7 @@ public void conversionFromNoOffset() { @Test public void conversionToInvalidInput3Over() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("+16:00")); @@ -63,7 +63,7 @@ public void conversionToInvalidInput3Over() { @Test public void conversionToInvalidInput3Under() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("-16:00")); @@ -73,7 +73,7 @@ public void conversionToInvalidInput3Under() { @Test public void conversionFromPositiveToPositive() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("+15:00"), DSL.literal("+01:00")); @@ -83,7 +83,7 @@ public void conversionFromPositiveToPositive() { @Test public void invalidInput2Under() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("-15:00"), DSL.literal("+01:00")); @@ -93,7 +93,7 @@ public void invalidInput2Under() { @Test public void invalidInput3Over() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("-12:00"), DSL.literal("+15:00")); @@ -103,7 +103,7 @@ public void invalidInput3Over() { @Test public void conversionToPositiveEdge() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("+14:00")); @@ -113,7 +113,7 @@ public void conversionToPositiveEdge() { @Test public void conversionToNegativeEdge() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:01"), DSL.literal("-13:59")); @@ -123,7 +123,7 @@ public void conversionToNegativeEdge() { @Test public void invalidInput2() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("+)()"), DSL.literal("+12:00")); @@ -133,7 +133,7 @@ public void invalidInput2() { @Test public void invalidInput3() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("test")); @@ -143,7 +143,7 @@ public void invalidInput3() { @Test public void invalidInput1() { - FunctionExpression expr = dsl.convert_tz( + FunctionExpression expr = DSL.convert_tz( DSL.literal("test"), DSL.literal("+00:00"), DSL.literal("+00:00")); @@ -153,7 +153,7 @@ public void invalidInput1() { @Test public void invalidDateFeb30() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2021-02-30 10:00:00")), DSL.literal("+00:00"), DSL.literal("+00:00")); @@ -163,7 +163,7 @@ public void invalidDateFeb30() { @Test public void invalidDateApril31() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2021-04-31 10:00:00")), DSL.literal("+00:00"), DSL.literal("+00:00")); @@ -173,7 +173,7 @@ public void invalidDateApril31() { @Test public void invalidMonth13() { - FunctionExpression expr = dsl.convert_tz(dsl.datetime( + FunctionExpression expr = DSL.convert_tz(DSL.datetime( DSL.literal("2021-13-03 10:00:00")), DSL.literal("+00:00"), DSL.literal("+00:00")); diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java index 29bfa3d91b..28a7113ca9 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java @@ -154,100 +154,100 @@ String getFormatted() { } FunctionExpression getDateFormatExpression() { - return dsl.date_format(DSL.literal(date), DSL.literal(getFormatter())); + return DSL.date_format(DSL.literal(date), DSL.literal(getFormatter())); } } @Test public void adddate() { - FunctionExpression expr = dsl.adddate(dsl.date(DSL.literal("2020-08-26")), DSL.literal(7)); + FunctionExpression expr = DSL.adddate(DSL.date(DSL.literal("2020-08-26")), DSL.literal(7)); assertEquals(DATE, expr.type()); assertEquals(new ExprDateValue("2020-09-02"), expr.valueOf(env)); assertEquals("adddate(date(\"2020-08-26\"), 7)", expr.toString()); - expr = dsl.adddate(dsl.timestamp(DSL.literal("2020-08-26 12:05:00")), DSL.literal(7)); + expr = DSL.adddate(DSL.timestamp(DSL.literal("2020-08-26 12:05:00")), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-09-02 12:05:00"), expr.valueOf(env)); assertEquals("adddate(timestamp(\"2020-08-26 12:05:00\"), 7)", expr.toString()); - expr = dsl.adddate( - dsl.date(DSL.literal("2020-08-26")), dsl.interval(DSL.literal(1), DSL.literal("hour"))); + expr = DSL.adddate( + DSL.date(DSL.literal("2020-08-26")), DSL.interval(DSL.literal(1), DSL.literal("hour"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-26 01:00:00"), expr.valueOf(env)); assertEquals("adddate(date(\"2020-08-26\"), interval(1, \"hour\"))", expr.toString()); - expr = dsl.adddate(DSL.literal("2020-08-26"), DSL.literal(7)); + expr = DSL.adddate(DSL.literal("2020-08-26"), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDateValue("2020-09-02"), expr.valueOf(env)); assertEquals("adddate(\"2020-08-26\", 7)", expr.toString()); - expr = dsl.adddate(DSL.literal("2020-08-26 12:05:00"), DSL.literal(7)); + expr = DSL.adddate(DSL.literal("2020-08-26 12:05:00"), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-09-02 12:05:00"), expr.valueOf(env)); assertEquals("adddate(\"2020-08-26 12:05:00\", 7)", expr.toString()); - expr = dsl - .adddate(DSL.literal("2020-08-26"), dsl.interval(DSL.literal(1), DSL.literal("hour"))); + expr = DSL + .adddate(DSL.literal("2020-08-26"), DSL.interval(DSL.literal(1), DSL.literal("hour"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-26 01:00:00"), expr.valueOf(env)); assertEquals("adddate(\"2020-08-26\", interval(1, \"hour\"))", expr.toString()); - expr = dsl - .adddate(DSL.literal("2020-08-26"), dsl.interval(DSL.literal(1), DSL.literal("day"))); + expr = DSL + .adddate(DSL.literal("2020-08-26"), DSL.interval(DSL.literal(1), DSL.literal("day"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDateValue("2020-08-27"), expr.valueOf(env)); assertEquals("adddate(\"2020-08-26\", interval(1, \"day\"))", expr.toString()); when(nullRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.adddate(nullRef, DSL.literal(1L)))); + assertEquals(nullValue(), eval(DSL.adddate(nullRef, DSL.literal(1L)))); assertEquals(nullValue(), - eval(dsl.adddate(nullRef, dsl.interval(DSL.literal(1), DSL.literal("month"))))); + eval(DSL.adddate(nullRef, DSL.interval(DSL.literal(1), DSL.literal("month"))))); when(missingRef.type()).thenReturn(DATE); - assertEquals(missingValue(), eval(dsl.adddate(missingRef, DSL.literal(1L)))); + assertEquals(missingValue(), eval(DSL.adddate(missingRef, DSL.literal(1L)))); assertEquals(missingValue(), - eval(dsl.adddate(missingRef, dsl.interval(DSL.literal(1), DSL.literal("month"))))); + eval(DSL.adddate(missingRef, DSL.interval(DSL.literal(1), DSL.literal("month"))))); when(nullRef.type()).thenReturn(LONG); when(missingRef.type()).thenReturn(LONG); - assertEquals(nullValue(), eval(dsl.adddate(dsl.date(DSL.literal("2020-08-26")), nullRef))); + assertEquals(nullValue(), eval(DSL.adddate(DSL.date(DSL.literal("2020-08-26")), nullRef))); assertEquals(missingValue(), - eval(dsl.adddate(dsl.date(DSL.literal("2020-08-26")), missingRef))); + eval(DSL.adddate(DSL.date(DSL.literal("2020-08-26")), missingRef))); when(nullRef.type()).thenReturn(INTERVAL); when(missingRef.type()).thenReturn(INTERVAL); - assertEquals(nullValue(), eval(dsl.adddate(dsl.date(DSL.literal("2020-08-26")), nullRef))); + assertEquals(nullValue(), eval(DSL.adddate(DSL.date(DSL.literal("2020-08-26")), nullRef))); assertEquals(missingValue(), - eval(dsl.adddate(dsl.date(DSL.literal("2020-08-26")), missingRef))); + eval(DSL.adddate(DSL.date(DSL.literal("2020-08-26")), missingRef))); when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(INTERVAL); - assertEquals(missingValue(), eval(dsl.adddate(nullRef, missingRef))); + assertEquals(missingValue(), eval(DSL.adddate(nullRef, missingRef))); } @Test public void date() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.date(nullRef))); - assertEquals(missingValue(), eval(dsl.date(missingRef))); + assertEquals(nullValue(), eval(DSL.date(nullRef))); + assertEquals(missingValue(), eval(DSL.date(missingRef))); - FunctionExpression expr = dsl.date(DSL.literal("2020-08-17")); + FunctionExpression expr = DSL.date(DSL.literal("2020-08-17")); assertEquals(DATE, expr.type()); assertEquals(new ExprDateValue("2020-08-17"), eval(expr)); assertEquals("date(\"2020-08-17\")", expr.toString()); - expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17"))); + expr = DSL.date(DSL.literal(new ExprDateValue("2020-08-17"))); assertEquals(DATE, expr.type()); assertEquals(new ExprDateValue("2020-08-17"), eval(expr)); assertEquals("date(DATE '2020-08-17')", expr.toString()); - expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17 12:12:00"))); + expr = DSL.date(DSL.literal(new ExprDateValue("2020-08-17 12:12:00"))); assertEquals(DATE, expr.type()); assertEquals(new ExprDateValue("2020-08-17 12:12:00"), eval(expr)); assertEquals("date(DATE '2020-08-17')", expr.toString()); - expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17 12:12"))); + expr = DSL.date(DSL.literal(new ExprDateValue("2020-08-17 12:12"))); assertEquals(DATE, expr.type()); assertEquals(new ExprDateValue("2020-08-17 12:12"), eval(expr)); assertEquals("date(DATE '2020-08-17')", expr.toString()); @@ -257,136 +257,136 @@ public void date() { @Test public void date_add() { - FunctionExpression expr = dsl.date_add(dsl.date(DSL.literal("2020-08-26")), DSL.literal(7)); + FunctionExpression expr = DSL.date_add(DSL.date(DSL.literal("2020-08-26")), DSL.literal(7)); assertEquals(DATE, expr.type()); assertEquals(new ExprDateValue("2020-09-02"), expr.valueOf(env)); assertEquals("date_add(date(\"2020-08-26\"), 7)", expr.toString()); - expr = dsl.date_add(DSL.literal("2020-08-26 12:05:00"), DSL.literal(7)); + expr = DSL.date_add(DSL.literal("2020-08-26 12:05:00"), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-09-02 12:05:00"), expr.valueOf(env)); assertEquals("date_add(\"2020-08-26 12:05:00\", 7)", expr.toString()); - expr = dsl.date_add(dsl.timestamp(DSL.literal("2020-08-26 12:05:00")), DSL.literal(7)); + expr = DSL.date_add(DSL.timestamp(DSL.literal("2020-08-26 12:05:00")), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-09-02 12:05:00"), expr.valueOf(env)); assertEquals("date_add(timestamp(\"2020-08-26 12:05:00\"), 7)", expr.toString()); - expr = dsl.date_add( - dsl.date(DSL.literal("2020-08-26")), dsl.interval(DSL.literal(1), DSL.literal("hour"))); + expr = DSL.date_add( + DSL.date(DSL.literal("2020-08-26")), DSL.interval(DSL.literal(1), DSL.literal("hour"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-26 01:00:00"), expr.valueOf(env)); assertEquals("date_add(date(\"2020-08-26\"), interval(1, \"hour\"))", expr.toString()); - expr = dsl - .date_add(DSL.literal("2020-08-26"), dsl.interval(DSL.literal(1), DSL.literal("hour"))); + expr = DSL + .date_add(DSL.literal("2020-08-26"), DSL.interval(DSL.literal(1), DSL.literal("hour"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-26 01:00:00"), expr.valueOf(env)); assertEquals("date_add(\"2020-08-26\", interval(1, \"hour\"))", expr.toString()); when(nullRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.date_add(nullRef, DSL.literal(1L)))); + assertEquals(nullValue(), eval(DSL.date_add(nullRef, DSL.literal(1L)))); assertEquals(nullValue(), - eval(dsl.date_add(nullRef, dsl.interval(DSL.literal(1), DSL.literal("month"))))); + eval(DSL.date_add(nullRef, DSL.interval(DSL.literal(1), DSL.literal("month"))))); when(missingRef.type()).thenReturn(DATE); - assertEquals(missingValue(), eval(dsl.date_add(missingRef, DSL.literal(1L)))); + assertEquals(missingValue(), eval(DSL.date_add(missingRef, DSL.literal(1L)))); assertEquals(missingValue(), - eval(dsl.date_add(missingRef, dsl.interval(DSL.literal(1), DSL.literal("month"))))); + eval(DSL.date_add(missingRef, DSL.interval(DSL.literal(1), DSL.literal("month"))))); when(nullRef.type()).thenReturn(LONG); when(missingRef.type()).thenReturn(LONG); - assertEquals(nullValue(), eval(dsl.date_add(dsl.date(DSL.literal("2020-08-26")), nullRef))); + assertEquals(nullValue(), eval(DSL.date_add(DSL.date(DSL.literal("2020-08-26")), nullRef))); assertEquals(missingValue(), - eval(dsl.date_add(dsl.date(DSL.literal("2020-08-26")), missingRef))); + eval(DSL.date_add(DSL.date(DSL.literal("2020-08-26")), missingRef))); when(nullRef.type()).thenReturn(INTERVAL); when(missingRef.type()).thenReturn(INTERVAL); - assertEquals(nullValue(), eval(dsl.date_add(dsl.date(DSL.literal("2020-08-26")), nullRef))); + assertEquals(nullValue(), eval(DSL.date_add(DSL.date(DSL.literal("2020-08-26")), nullRef))); assertEquals(missingValue(), - eval(dsl.date_add(dsl.date(DSL.literal("2020-08-26")), missingRef))); + eval(DSL.date_add(DSL.date(DSL.literal("2020-08-26")), missingRef))); when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(INTERVAL); - assertEquals(missingValue(), eval(dsl.date_add(nullRef, missingRef))); + assertEquals(missingValue(), eval(DSL.date_add(nullRef, missingRef))); } @Test public void date_sub() { - FunctionExpression expr = dsl.date_sub(dsl.date(DSL.literal("2020-08-26")), DSL.literal(7)); + FunctionExpression expr = DSL.date_sub(DSL.date(DSL.literal("2020-08-26")), DSL.literal(7)); assertEquals(DATE, expr.type()); assertEquals(new ExprDateValue("2020-08-19"), expr.valueOf(env)); assertEquals("date_sub(date(\"2020-08-26\"), 7)", expr.toString()); - expr = dsl.date_sub(DSL.literal("2020-08-26"), DSL.literal(7)); + expr = DSL.date_sub(DSL.literal("2020-08-26"), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDateValue("2020-08-19"), expr.valueOf(env)); assertEquals("date_sub(\"2020-08-26\", 7)", expr.toString()); - expr = dsl.date_sub(dsl.timestamp(DSL.literal("2020-08-26 12:05:00")), DSL.literal(7)); + expr = DSL.date_sub(DSL.timestamp(DSL.literal("2020-08-26 12:05:00")), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-19 12:05:00"), expr.valueOf(env)); assertEquals("date_sub(timestamp(\"2020-08-26 12:05:00\"), 7)", expr.toString()); - expr = dsl.date_sub(DSL.literal("2020-08-26 12:05:00"), DSL.literal(7)); + expr = DSL.date_sub(DSL.literal("2020-08-26 12:05:00"), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-19 12:05:00"), expr.valueOf(env)); assertEquals("date_sub(\"2020-08-26 12:05:00\", 7)", expr.toString()); - expr = dsl.date_sub(dsl.timestamp(DSL.literal("2020-08-26 12:05:00")), - dsl.interval(DSL.literal(1), DSL.literal("hour"))); + expr = DSL.date_sub(DSL.timestamp(DSL.literal("2020-08-26 12:05:00")), + DSL.interval(DSL.literal(1), DSL.literal("hour"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-26 11:05:00"), expr.valueOf(env)); assertEquals("date_sub(timestamp(\"2020-08-26 12:05:00\"), interval(1, \"hour\"))", expr.toString()); - expr = dsl.date_sub(DSL.literal("2020-08-26 12:05:00"), - dsl.interval(DSL.literal(1), DSL.literal("year"))); + expr = DSL.date_sub(DSL.literal("2020-08-26 12:05:00"), + DSL.interval(DSL.literal(1), DSL.literal("year"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2019-08-26 12:05:00"), expr.valueOf(env)); assertEquals("date_sub(\"2020-08-26 12:05:00\", interval(1, \"year\"))", expr.toString()); when(nullRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.date_sub(nullRef, DSL.literal(1L)))); + assertEquals(nullValue(), eval(DSL.date_sub(nullRef, DSL.literal(1L)))); assertEquals(nullValue(), - eval(dsl.date_sub(nullRef, dsl.interval(DSL.literal(1), DSL.literal("month"))))); + eval(DSL.date_sub(nullRef, DSL.interval(DSL.literal(1), DSL.literal("month"))))); when(missingRef.type()).thenReturn(DATE); - assertEquals(missingValue(), eval(dsl.date_sub(missingRef, DSL.literal(1L)))); + assertEquals(missingValue(), eval(DSL.date_sub(missingRef, DSL.literal(1L)))); assertEquals(missingValue(), - eval(dsl.date_sub(missingRef, dsl.interval(DSL.literal(1), DSL.literal("month"))))); + eval(DSL.date_sub(missingRef, DSL.interval(DSL.literal(1), DSL.literal("month"))))); when(nullRef.type()).thenReturn(LONG); when(missingRef.type()).thenReturn(LONG); - assertEquals(nullValue(), eval(dsl.date_sub(dsl.date(DSL.literal("2020-08-26")), nullRef))); + assertEquals(nullValue(), eval(DSL.date_sub(DSL.date(DSL.literal("2020-08-26")), nullRef))); assertEquals(missingValue(), - eval(dsl.date_sub(dsl.date(DSL.literal("2020-08-26")), missingRef))); + eval(DSL.date_sub(DSL.date(DSL.literal("2020-08-26")), missingRef))); when(nullRef.type()).thenReturn(INTERVAL); when(missingRef.type()).thenReturn(INTERVAL); - assertEquals(nullValue(), eval(dsl.date_sub(dsl.date(DSL.literal("2020-08-26")), nullRef))); + assertEquals(nullValue(), eval(DSL.date_sub(DSL.date(DSL.literal("2020-08-26")), nullRef))); assertEquals(missingValue(), - eval(dsl.date_sub(dsl.date(DSL.literal("2020-08-26")), missingRef))); + eval(DSL.date_sub(DSL.date(DSL.literal("2020-08-26")), missingRef))); when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(INTERVAL); - assertEquals(missingValue(), eval(dsl.date_sub(nullRef, missingRef))); + assertEquals(missingValue(), eval(DSL.date_sub(nullRef, missingRef))); } @Test public void day() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.day(nullRef))); - assertEquals(missingValue(), eval(dsl.day(missingRef))); + assertEquals(nullValue(), eval(DSL.day(nullRef))); + assertEquals(missingValue(), eval(DSL.day(missingRef))); - FunctionExpression expression = dsl.day(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.day(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(INTEGER, expression.type()); assertEquals("day(DATE '2020-08-07')", expression.toString()); assertEquals(integerValue(7), eval(expression)); - expression = dsl.day(DSL.literal("2020-08-07")); + expression = DSL.day(DSL.literal("2020-08-07")); assertEquals(INTEGER, expression.type()); assertEquals("day(\"2020-08-07\")", expression.toString()); assertEquals(integerValue(7), eval(expression)); @@ -396,15 +396,15 @@ public void day() { public void dayName() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.dayname(nullRef))); - assertEquals(missingValue(), eval(dsl.dayname(missingRef))); + assertEquals(nullValue(), eval(DSL.dayname(nullRef))); + assertEquals(missingValue(), eval(DSL.dayname(missingRef))); - FunctionExpression expression = dsl.dayname(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.dayname(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(STRING, expression.type()); assertEquals("dayname(DATE '2020-08-07')", expression.toString()); assertEquals(stringValue("Friday"), eval(expression)); - expression = dsl.dayname(DSL.literal("2020-08-07")); + expression = DSL.dayname(DSL.literal("2020-08-07")); assertEquals(STRING, expression.type()); assertEquals("dayname(\"2020-08-07\")", expression.toString()); assertEquals(stringValue("Friday"), eval(expression)); @@ -414,15 +414,15 @@ public void dayName() { public void dayOfMonth() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.dayofmonth(nullRef))); - assertEquals(missingValue(), eval(dsl.dayofmonth(missingRef))); + assertEquals(nullValue(), eval(DSL.dayofmonth(nullRef))); + assertEquals(missingValue(), eval(DSL.dayofmonth(missingRef))); - FunctionExpression expression = dsl.dayofmonth(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.dayofmonth(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(INTEGER, expression.type()); assertEquals("dayofmonth(DATE '2020-08-07')", expression.toString()); assertEquals(integerValue(7), eval(expression)); - expression = dsl.dayofmonth(DSL.literal("2020-07-08")); + expression = DSL.dayofmonth(DSL.literal("2020-07-08")); assertEquals(INTEGER, expression.type()); assertEquals("dayofmonth(\"2020-07-08\")", expression.toString()); assertEquals(integerValue(8), eval(expression)); @@ -432,25 +432,25 @@ public void dayOfMonth() { public void dayOfWeek() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.dayofweek(nullRef))); - assertEquals(missingValue(), eval(dsl.dayofweek(missingRef))); + assertEquals(nullValue(), eval(DSL.dayofweek(nullRef))); + assertEquals(missingValue(), eval(DSL.dayofweek(missingRef))); - FunctionExpression expression = dsl.dayofweek(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.dayofweek(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(INTEGER, expression.type()); assertEquals("dayofweek(DATE '2020-08-07')", expression.toString()); assertEquals(integerValue(6), eval(expression)); - expression = dsl.dayofweek(DSL.literal(new ExprDateValue("2020-08-09"))); + expression = DSL.dayofweek(DSL.literal(new ExprDateValue("2020-08-09"))); assertEquals(INTEGER, expression.type()); assertEquals("dayofweek(DATE '2020-08-09')", expression.toString()); assertEquals(integerValue(1), eval(expression)); - expression = dsl.dayofweek(DSL.literal("2020-08-09")); + expression = DSL.dayofweek(DSL.literal("2020-08-09")); assertEquals(INTEGER, expression.type()); assertEquals("dayofweek(\"2020-08-09\")", expression.toString()); assertEquals(integerValue(1), eval(expression)); - expression = dsl.dayofweek(DSL.literal("2020-08-09 01:02:03")); + expression = DSL.dayofweek(DSL.literal("2020-08-09 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals("dayofweek(\"2020-08-09 01:02:03\")", expression.toString()); assertEquals(integerValue(1), eval(expression)); @@ -460,20 +460,20 @@ public void dayOfWeek() { public void dayOfYear() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.dayofyear(nullRef))); - assertEquals(missingValue(), eval(dsl.dayofyear(missingRef))); + assertEquals(nullValue(), eval(DSL.dayofyear(nullRef))); + assertEquals(missingValue(), eval(DSL.dayofyear(missingRef))); - FunctionExpression expression = dsl.dayofyear(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.dayofyear(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(INTEGER, expression.type()); assertEquals("dayofyear(DATE '2020-08-07')", expression.toString()); assertEquals(integerValue(220), eval(expression)); - expression = dsl.dayofyear(DSL.literal("2020-08-07")); + expression = DSL.dayofyear(DSL.literal("2020-08-07")); assertEquals(INTEGER, expression.type()); assertEquals("dayofyear(\"2020-08-07\")", expression.toString()); assertEquals(integerValue(220), eval(expression)); - expression = dsl.dayofyear(DSL.literal("2020-08-07 01:02:03")); + expression = DSL.dayofyear(DSL.literal("2020-08-07 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals("dayofyear(\"2020-08-07 01:02:03\")", expression.toString()); assertEquals(integerValue(220), eval(expression)); @@ -483,10 +483,10 @@ public void dayOfYear() { public void from_days() { when(nullRef.type()).thenReturn(LONG); when(missingRef.type()).thenReturn(LONG); - assertEquals(nullValue(), eval(dsl.from_days(nullRef))); - assertEquals(missingValue(), eval(dsl.from_days(missingRef))); + assertEquals(nullValue(), eval(DSL.from_days(nullRef))); + assertEquals(missingValue(), eval(DSL.from_days(missingRef))); - FunctionExpression expression = dsl.from_days(DSL.literal(new ExprLongValue(730669))); + FunctionExpression expression = DSL.from_days(DSL.literal(new ExprLongValue(730669))); assertEquals(DATE, expression.type()); assertEquals("from_days(730669)", expression.toString()); assertEquals(new ExprDateValue("2000-07-03"), expression.valueOf(env)); @@ -496,30 +496,30 @@ public void from_days() { public void hour() { when(nullRef.type()).thenReturn(TIME); when(missingRef.type()).thenReturn(TIME); - assertEquals(nullValue(), eval(dsl.hour(nullRef))); - assertEquals(missingValue(), eval(dsl.hour(missingRef))); + assertEquals(nullValue(), eval(DSL.hour(nullRef))); + assertEquals(missingValue(), eval(DSL.hour(missingRef))); - FunctionExpression expression = dsl.hour(DSL.literal(new ExprTimeValue("01:02:03"))); + FunctionExpression expression = DSL.hour(DSL.literal(new ExprTimeValue("01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(1), eval(expression)); assertEquals("hour(TIME '01:02:03')", expression.toString()); - expression = dsl.hour(DSL.literal("01:02:03")); + expression = DSL.hour(DSL.literal("01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(1), eval(expression)); assertEquals("hour(\"01:02:03\")", expression.toString()); - expression = dsl.hour(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03"))); + expression = DSL.hour(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(1), expression.valueOf(env)); assertEquals("hour(TIMESTAMP '2020-08-17 01:02:03')", expression.toString()); - expression = dsl.hour(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); + expression = DSL.hour(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(1), expression.valueOf(env)); assertEquals("hour(DATETIME '2020-08-17 01:02:03')", expression.toString()); - expression = dsl.hour(DSL.literal("2020-08-17 01:02:03")); + expression = DSL.hour(DSL.literal("2020-08-17 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(1), expression.valueOf(env)); assertEquals("hour(\"2020-08-17 01:02:03\")", expression.toString()); @@ -529,41 +529,41 @@ public void hour() { public void microsecond() { when(nullRef.type()).thenReturn(TIME); when(missingRef.type()).thenReturn(TIME); - assertEquals(nullValue(), eval(dsl.microsecond(nullRef))); - assertEquals(missingValue(), eval(dsl.microsecond(missingRef))); + assertEquals(nullValue(), eval(DSL.microsecond(nullRef))); + assertEquals(missingValue(), eval(DSL.microsecond(missingRef))); - FunctionExpression expression = dsl + FunctionExpression expression = DSL .microsecond(DSL.literal(new ExprTimeValue("01:02:03.123456"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(123456), eval(expression)); assertEquals("microsecond(TIME '01:02:03.123456')", expression.toString()); - expression = dsl.microsecond(DSL.literal(new ExprTimeValue("01:02:03.00"))); + expression = DSL.microsecond(DSL.literal(new ExprTimeValue("01:02:03.00"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(0), eval(expression)); assertEquals("microsecond(TIME '01:02:03')", expression.toString()); - expression = dsl.microsecond(DSL.literal("01:02:03.12")); + expression = DSL.microsecond(DSL.literal("01:02:03.12")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(120000), eval(expression)); assertEquals("microsecond(\"01:02:03.12\")", expression.toString()); - expression = dsl.microsecond(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03.000010"))); + expression = DSL.microsecond(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03.000010"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(10), expression.valueOf(env)); assertEquals("microsecond(DATETIME '2020-08-17 01:02:03.00001')", expression.toString()); - expression = dsl.microsecond(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03.123456"))); + expression = DSL.microsecond(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03.123456"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(123456), expression.valueOf(env)); assertEquals("microsecond(DATETIME '2020-08-17 01:02:03.123456')", expression.toString()); - expression = dsl.microsecond(DSL.literal("2020-08-17 01:02:03.123456")); + expression = DSL.microsecond(DSL.literal("2020-08-17 01:02:03.123456")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(123456), expression.valueOf(env)); assertEquals("microsecond(\"2020-08-17 01:02:03.123456\")", expression.toString()); - expression = dsl.microsecond(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03.000010"))); + expression = DSL.microsecond(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03.000010"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(10), expression.valueOf(env)); assertEquals("microsecond(TIMESTAMP '2020-08-17 01:02:03.00001')", expression.toString()); @@ -573,30 +573,30 @@ public void microsecond() { public void minute() { when(nullRef.type()).thenReturn(TIME); when(missingRef.type()).thenReturn(TIME); - assertEquals(nullValue(), eval(dsl.minute(nullRef))); - assertEquals(missingValue(), eval(dsl.minute(missingRef))); + assertEquals(nullValue(), eval(DSL.minute(nullRef))); + assertEquals(missingValue(), eval(DSL.minute(missingRef))); - FunctionExpression expression = dsl.minute(DSL.literal(new ExprTimeValue("01:02:03"))); + FunctionExpression expression = DSL.minute(DSL.literal(new ExprTimeValue("01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(2), eval(expression)); assertEquals("minute(TIME '01:02:03')", expression.toString()); - expression = dsl.minute(DSL.literal("01:02:03")); + expression = DSL.minute(DSL.literal("01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(2), eval(expression)); assertEquals("minute(\"01:02:03\")", expression.toString()); - expression = dsl.minute(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03"))); + expression = DSL.minute(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(2), expression.valueOf(env)); assertEquals("minute(TIMESTAMP '2020-08-17 01:02:03')", expression.toString()); - expression = dsl.minute(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); + expression = DSL.minute(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(2), expression.valueOf(env)); assertEquals("minute(DATETIME '2020-08-17 01:02:03')", expression.toString()); - expression = dsl.minute(DSL.literal("2020-08-17 01:02:03")); + expression = DSL.minute(DSL.literal("2020-08-17 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(2), expression.valueOf(env)); assertEquals("minute(\"2020-08-17 01:02:03\")", expression.toString()); @@ -606,20 +606,20 @@ public void minute() { public void month() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.month(nullRef))); - assertEquals(missingValue(), eval(dsl.month(missingRef))); + assertEquals(nullValue(), eval(DSL.month(nullRef))); + assertEquals(missingValue(), eval(DSL.month(missingRef))); - FunctionExpression expression = dsl.month(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.month(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(INTEGER, expression.type()); assertEquals("month(DATE '2020-08-07')", expression.toString()); assertEquals(integerValue(8), eval(expression)); - expression = dsl.month(DSL.literal("2020-08-07")); + expression = DSL.month(DSL.literal("2020-08-07")); assertEquals(INTEGER, expression.type()); assertEquals("month(\"2020-08-07\")", expression.toString()); assertEquals(integerValue(8), eval(expression)); - expression = dsl.month(DSL.literal("2020-08-07 01:02:03")); + expression = DSL.month(DSL.literal("2020-08-07 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals("month(\"2020-08-07 01:02:03\")", expression.toString()); assertEquals(integerValue(8), eval(expression)); @@ -629,20 +629,20 @@ public void month() { public void monthName() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.monthname(nullRef))); - assertEquals(missingValue(), eval(dsl.monthname(missingRef))); + assertEquals(nullValue(), eval(DSL.monthname(nullRef))); + assertEquals(missingValue(), eval(DSL.monthname(missingRef))); - FunctionExpression expression = dsl.monthname(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.monthname(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(STRING, expression.type()); assertEquals("monthname(DATE '2020-08-07')", expression.toString()); assertEquals(stringValue("August"), eval(expression)); - expression = dsl.monthname(DSL.literal("2020-08-07")); + expression = DSL.monthname(DSL.literal("2020-08-07")); assertEquals(STRING, expression.type()); assertEquals("monthname(\"2020-08-07\")", expression.toString()); assertEquals(stringValue("August"), eval(expression)); - expression = dsl.monthname(DSL.literal("2020-08-07 01:02:03")); + expression = DSL.monthname(DSL.literal("2020-08-07 01:02:03")); assertEquals(STRING, expression.type()); assertEquals("monthname(\"2020-08-07 01:02:03\")", expression.toString()); assertEquals(stringValue("August"), eval(expression)); @@ -652,20 +652,20 @@ public void monthName() { public void quarter() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.quarter(nullRef))); - assertEquals(missingValue(), eval(dsl.quarter(missingRef))); + assertEquals(nullValue(), eval(DSL.quarter(nullRef))); + assertEquals(missingValue(), eval(DSL.quarter(missingRef))); - FunctionExpression expression = dsl.quarter(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.quarter(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(INTEGER, expression.type()); assertEquals("quarter(DATE '2020-08-07')", expression.toString()); assertEquals(integerValue(3), eval(expression)); - expression = dsl.quarter(DSL.literal("2020-12-07")); + expression = DSL.quarter(DSL.literal("2020-12-07")); assertEquals(INTEGER, expression.type()); assertEquals("quarter(\"2020-12-07\")", expression.toString()); assertEquals(integerValue(4), eval(expression)); - expression = dsl.quarter(DSL.literal("2020-12-07 01:02:03")); + expression = DSL.quarter(DSL.literal("2020-12-07 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals("quarter(\"2020-12-07 01:02:03\")", expression.toString()); assertEquals(integerValue(4), eval(expression)); @@ -675,30 +675,30 @@ public void quarter() { public void second() { when(nullRef.type()).thenReturn(TIME); when(missingRef.type()).thenReturn(TIME); - assertEquals(nullValue(), eval(dsl.second(nullRef))); - assertEquals(missingValue(), eval(dsl.second(missingRef))); + assertEquals(nullValue(), eval(DSL.second(nullRef))); + assertEquals(missingValue(), eval(DSL.second(missingRef))); - FunctionExpression expression = dsl.second(DSL.literal(new ExprTimeValue("01:02:03"))); + FunctionExpression expression = DSL.second(DSL.literal(new ExprTimeValue("01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(3), eval(expression)); assertEquals("second(TIME '01:02:03')", expression.toString()); - expression = dsl.second(DSL.literal("01:02:03")); + expression = DSL.second(DSL.literal("01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(3), eval(expression)); assertEquals("second(\"01:02:03\")", expression.toString()); - expression = dsl.second(DSL.literal("2020-08-17 01:02:03")); + expression = DSL.second(DSL.literal("2020-08-17 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(3), eval(expression)); assertEquals("second(\"2020-08-17 01:02:03\")", expression.toString()); - expression = dsl.second(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03"))); + expression = DSL.second(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(3), expression.valueOf(env)); assertEquals("second(TIMESTAMP '2020-08-17 01:02:03')", expression.toString()); - expression = dsl.second(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); + expression = DSL.second(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(3), expression.valueOf(env)); assertEquals("second(DATETIME '2020-08-17 01:02:03')", expression.toString()); @@ -706,87 +706,87 @@ public void second() { @Test public void subdate() { - FunctionExpression expr = dsl.subdate(dsl.date(DSL.literal("2020-08-26")), DSL.literal(7)); + FunctionExpression expr = DSL.subdate(DSL.date(DSL.literal("2020-08-26")), DSL.literal(7)); assertEquals(DATE, expr.type()); assertEquals(new ExprDateValue("2020-08-19"), expr.valueOf(env)); assertEquals("subdate(date(\"2020-08-26\"), 7)", expr.toString()); - expr = dsl.subdate(DSL.literal("2020-08-26"), DSL.literal(7)); + expr = DSL.subdate(DSL.literal("2020-08-26"), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDateValue("2020-08-19"), expr.valueOf(env)); assertEquals("subdate(\"2020-08-26\", 7)", expr.toString()); - expr = dsl.subdate(dsl.timestamp(DSL.literal("2020-08-26 12:05:00")), DSL.literal(7)); + expr = DSL.subdate(DSL.timestamp(DSL.literal("2020-08-26 12:05:00")), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-19 12:05:00"), expr.valueOf(env)); assertEquals("subdate(timestamp(\"2020-08-26 12:05:00\"), 7)", expr.toString()); - expr = dsl.subdate(DSL.literal("2020-08-26 12:05:00"), DSL.literal(7)); + expr = DSL.subdate(DSL.literal("2020-08-26 12:05:00"), DSL.literal(7)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-19 12:05:00"), expr.valueOf(env)); assertEquals("subdate(\"2020-08-26 12:05:00\", 7)", expr.toString()); - expr = dsl.subdate(dsl.timestamp(DSL.literal("2020-08-26 12:05:00")), - dsl.interval(DSL.literal(1), DSL.literal("hour"))); + expr = DSL.subdate(DSL.timestamp(DSL.literal("2020-08-26 12:05:00")), + DSL.interval(DSL.literal(1), DSL.literal("hour"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-26 11:05:00"), expr.valueOf(env)); assertEquals("subdate(timestamp(\"2020-08-26 12:05:00\"), interval(1, \"hour\"))", expr.toString()); - expr = dsl.subdate(DSL.literal("2020-08-26 12:05:00"), - dsl.interval(DSL.literal(1), DSL.literal("hour"))); + expr = DSL.subdate(DSL.literal("2020-08-26 12:05:00"), + DSL.interval(DSL.literal(1), DSL.literal("hour"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2020-08-26 11:05:00"), expr.valueOf(env)); assertEquals("subdate(\"2020-08-26 12:05:00\", interval(1, \"hour\"))", expr.toString()); - expr = dsl.subdate(DSL.literal("2020-08-26"), - dsl.interval(DSL.literal(1), DSL.literal("day"))); + expr = DSL.subdate(DSL.literal("2020-08-26"), + DSL.interval(DSL.literal(1), DSL.literal("day"))); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDateValue("2020-08-25"), expr.valueOf(env)); assertEquals("subdate(\"2020-08-26\", interval(1, \"day\"))", expr.toString()); when(nullRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.subdate(nullRef, DSL.literal(1L)))); + assertEquals(nullValue(), eval(DSL.subdate(nullRef, DSL.literal(1L)))); assertEquals(nullValue(), - eval(dsl.subdate(nullRef, dsl.interval(DSL.literal(1), DSL.literal("month"))))); + eval(DSL.subdate(nullRef, DSL.interval(DSL.literal(1), DSL.literal("month"))))); when(missingRef.type()).thenReturn(DATE); - assertEquals(missingValue(), eval(dsl.subdate(missingRef, DSL.literal(1L)))); + assertEquals(missingValue(), eval(DSL.subdate(missingRef, DSL.literal(1L)))); assertEquals(missingValue(), - eval(dsl.subdate(missingRef, dsl.interval(DSL.literal(1), DSL.literal("month"))))); + eval(DSL.subdate(missingRef, DSL.interval(DSL.literal(1), DSL.literal("month"))))); when(nullRef.type()).thenReturn(LONG); when(missingRef.type()).thenReturn(LONG); - assertEquals(nullValue(), eval(dsl.subdate(dsl.date(DSL.literal("2020-08-26")), nullRef))); + assertEquals(nullValue(), eval(DSL.subdate(DSL.date(DSL.literal("2020-08-26")), nullRef))); assertEquals(missingValue(), - eval(dsl.subdate(dsl.date(DSL.literal("2020-08-26")), missingRef))); + eval(DSL.subdate(DSL.date(DSL.literal("2020-08-26")), missingRef))); when(nullRef.type()).thenReturn(INTERVAL); when(missingRef.type()).thenReturn(INTERVAL); - assertEquals(nullValue(), eval(dsl.subdate(dsl.date(DSL.literal("2020-08-26")), nullRef))); + assertEquals(nullValue(), eval(DSL.subdate(DSL.date(DSL.literal("2020-08-26")), nullRef))); assertEquals(missingValue(), - eval(dsl.subdate(dsl.date(DSL.literal("2020-08-26")), missingRef))); + eval(DSL.subdate(DSL.date(DSL.literal("2020-08-26")), missingRef))); when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(INTERVAL); - assertEquals(missingValue(), eval(dsl.subdate(nullRef, missingRef))); + assertEquals(missingValue(), eval(DSL.subdate(nullRef, missingRef))); } @Test public void time_to_sec() { when(nullRef.type()).thenReturn(TIME); when(missingRef.type()).thenReturn(TIME); - assertEquals(nullValue(), eval(dsl.time_to_sec(nullRef))); - assertEquals(missingValue(), eval(dsl.time_to_sec(missingRef))); + assertEquals(nullValue(), eval(DSL.time_to_sec(nullRef))); + assertEquals(missingValue(), eval(DSL.time_to_sec(missingRef))); - FunctionExpression expression = dsl.time_to_sec(DSL.literal(new ExprTimeValue("22:23:00"))); + FunctionExpression expression = DSL.time_to_sec(DSL.literal(new ExprTimeValue("22:23:00"))); assertEquals(LONG, expression.type()); assertEquals("time_to_sec(TIME '22:23:00')", expression.toString()); assertEquals(longValue(80580L), eval(expression)); - expression = dsl.time_to_sec(DSL.literal("22:23:00")); + expression = DSL.time_to_sec(DSL.literal("22:23:00")); assertEquals(LONG, expression.type()); assertEquals("time_to_sec(\"22:23:00\")", expression.toString()); assertEquals(longValue(80580L), eval(expression)); @@ -796,40 +796,40 @@ public void time_to_sec() { public void time() { when(nullRef.type()).thenReturn(TIME); when(missingRef.type()).thenReturn(TIME); - assertEquals(nullValue(), eval(dsl.time(nullRef))); - assertEquals(missingValue(), eval(dsl.time(missingRef))); + assertEquals(nullValue(), eval(DSL.time(nullRef))); + assertEquals(missingValue(), eval(DSL.time(missingRef))); - FunctionExpression expr = dsl.time(DSL.literal("01:01:01")); + FunctionExpression expr = DSL.time(DSL.literal("01:01:01")); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("01:01:01"), eval(expr)); assertEquals("time(\"01:01:01\")", expr.toString()); - expr = dsl.time(DSL.literal(new ExprTimeValue("01:01:01"))); + expr = DSL.time(DSL.literal(new ExprTimeValue("01:01:01"))); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("01:01:01"), eval(expr)); assertEquals("time(TIME '01:01:01')", expr.toString()); - expr = dsl.time(DSL.literal(new ExprTimeValue("01:01"))); + expr = DSL.time(DSL.literal(new ExprTimeValue("01:01"))); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("01:01"), eval(expr)); assertEquals("time(TIME '01:01:00')", expr.toString()); - expr = dsl.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01:01"))); + expr = DSL.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01:01"))); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("2019-04-19 01:01:01"), eval(expr)); assertEquals("time(TIME '01:01:01')", expr.toString()); - expr = dsl.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01"))); + expr = DSL.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01"))); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("2019-04-19 01:01"), eval(expr)); assertEquals("time(TIME '01:01:00')", expr.toString()); - expr = dsl.time(DSL.literal(new ExprTimeValue("01:01:01.0123"))); + expr = DSL.time(DSL.literal(new ExprTimeValue("01:01:01.0123"))); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("01:01:01.0123"), eval(expr)); assertEquals("time(TIME '01:01:01.0123')", expr.toString()); - expr = dsl.time(dsl.date(DSL.literal("2020-01-02"))); + expr = DSL.time(DSL.date(DSL.literal("2020-01-02"))); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("00:00:00"), expr.valueOf()); } @@ -838,22 +838,22 @@ public void time() { public void timestamp() { when(nullRef.type()).thenReturn(TIMESTAMP); when(missingRef.type()).thenReturn(TIMESTAMP); - assertEquals(nullValue(), eval(dsl.timestamp(nullRef))); - assertEquals(missingValue(), eval(dsl.timestamp(missingRef))); + assertEquals(nullValue(), eval(DSL.timestamp(nullRef))); + assertEquals(missingValue(), eval(DSL.timestamp(missingRef))); - FunctionExpression expr = dsl.timestamp(DSL.literal("2020-08-17 01:01:01")); + FunctionExpression expr = DSL.timestamp(DSL.literal("2020-08-17 01:01:01")); assertEquals(TIMESTAMP, expr.type()); assertEquals(new ExprTimestampValue("2020-08-17 01:01:01"), expr.valueOf(env)); assertEquals("timestamp(\"2020-08-17 01:01:01\")", expr.toString()); - expr = dsl.timestamp(DSL.literal(new ExprTimestampValue("2020-08-17 01:01:01"))); + expr = DSL.timestamp(DSL.literal(new ExprTimestampValue("2020-08-17 01:01:01"))); assertEquals(TIMESTAMP, expr.type()); assertEquals(new ExprTimestampValue("2020-08-17 01:01:01"), expr.valueOf(env)); assertEquals("timestamp(TIMESTAMP '2020-08-17 01:01:01')", expr.toString()); } private void testWeek(String date, int mode, int expectedResult) { - FunctionExpression expression = dsl + FunctionExpression expression = DSL .week(DSL.literal(new ExprDateValue(date)), DSL.literal(mode)); assertEquals(INTEGER, expression.type()); assertEquals(String.format("week(DATE '%s', %d)", date, mode), expression.toString()); @@ -863,8 +863,8 @@ private void testWeek(String date, int mode, int expectedResult) { private void testNullMissingWeek(ExprCoreType date) { when(nullRef.type()).thenReturn(date); when(missingRef.type()).thenReturn(date); - assertEquals(nullValue(), eval(dsl.week(nullRef))); - assertEquals(missingValue(), eval(dsl.week(missingRef))); + assertEquals(nullValue(), eval(DSL.week(nullRef))); + assertEquals(missingValue(), eval(DSL.week(missingRef))); } @Test @@ -876,25 +876,25 @@ public void week() { when(nullRef.type()).thenReturn(INTEGER); when(missingRef.type()).thenReturn(INTEGER); - assertEquals(nullValue(), eval(dsl.week(DSL.literal("2019-01-05"), nullRef))); - assertEquals(missingValue(), eval(dsl.week(DSL.literal("2019-01-05"), missingRef))); + assertEquals(nullValue(), eval(DSL.week(DSL.literal("2019-01-05"), nullRef))); + assertEquals(missingValue(), eval(DSL.week(DSL.literal("2019-01-05"), missingRef))); when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(INTEGER); - assertEquals(missingValue(), eval(dsl.week(nullRef, missingRef))); + assertEquals(missingValue(), eval(DSL.week(nullRef, missingRef))); - FunctionExpression expression = dsl + FunctionExpression expression = DSL .week(DSL.literal(new ExprTimestampValue("2019-01-05 01:02:03"))); assertEquals(INTEGER, expression.type()); assertEquals("week(TIMESTAMP '2019-01-05 01:02:03')", expression.toString()); assertEquals(integerValue(0), eval(expression)); - expression = dsl.week(DSL.literal("2019-01-05")); + expression = DSL.week(DSL.literal("2019-01-05")); assertEquals(INTEGER, expression.type()); assertEquals("week(\"2019-01-05\")", expression.toString()); assertEquals(integerValue(0), eval(expression)); - expression = dsl.week(DSL.literal("2019-01-05 00:01:00")); + expression = DSL.week(DSL.literal("2019-01-05 00:01:00")); assertEquals(INTEGER, expression.type()); assertEquals("week(\"2019-01-05 00:01:00\")", expression.toString()); assertEquals(integerValue(0), eval(expression)); @@ -935,14 +935,14 @@ public void week() { public void modeInUnsupportedFormat() { testNullMissingWeek(DATE); - FunctionExpression expression1 = dsl + FunctionExpression expression1 = DSL .week(DSL.literal(new ExprDateValue("2019-01-05")), DSL.literal(8)); SemanticCheckException exception = assertThrows(SemanticCheckException.class, () -> eval(expression1)); assertEquals("mode:8 is invalid, please use mode value between 0-7", exception.getMessage()); - FunctionExpression expression2 = dsl + FunctionExpression expression2 = DSL .week(DSL.literal(new ExprDateValue("2019-01-05")), DSL.literal(-1)); exception = assertThrows(SemanticCheckException.class, () -> eval(expression2)); assertEquals("mode:-1 is invalid, please use mode value between 0-7", @@ -953,20 +953,20 @@ public void modeInUnsupportedFormat() { public void to_days() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.to_days(nullRef))); - assertEquals(missingValue(), eval(dsl.to_days(missingRef))); + assertEquals(nullValue(), eval(DSL.to_days(nullRef))); + assertEquals(missingValue(), eval(DSL.to_days(missingRef))); - FunctionExpression expression = dsl.to_days(DSL.literal(new ExprDateValue("2008-10-07"))); + FunctionExpression expression = DSL.to_days(DSL.literal(new ExprDateValue("2008-10-07"))); assertEquals(LONG, expression.type()); assertEquals("to_days(DATE '2008-10-07')", expression.toString()); assertEquals(longValue(733687L), eval(expression)); - expression = dsl.to_days(DSL.literal("1969-12-31")); + expression = DSL.to_days(DSL.literal("1969-12-31")); assertEquals(LONG, expression.type()); assertEquals("to_days(\"1969-12-31\")", expression.toString()); assertEquals(longValue(719527L), eval(expression)); - expression = dsl.to_days(DSL.literal("1969-12-31 01:01:01")); + expression = DSL.to_days(DSL.literal("1969-12-31 01:01:01")); assertEquals(LONG, expression.type()); assertEquals("to_days(\"1969-12-31 01:01:01\")", expression.toString()); assertEquals(longValue(719527L), eval(expression)); @@ -976,20 +976,20 @@ public void to_days() { public void year() { when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.year(nullRef))); - assertEquals(missingValue(), eval(dsl.year(missingRef))); + assertEquals(nullValue(), eval(DSL.year(nullRef))); + assertEquals(missingValue(), eval(DSL.year(missingRef))); - FunctionExpression expression = dsl.year(DSL.literal(new ExprDateValue("2020-08-07"))); + FunctionExpression expression = DSL.year(DSL.literal(new ExprDateValue("2020-08-07"))); assertEquals(INTEGER, expression.type()); assertEquals("year(DATE '2020-08-07')", expression.toString()); assertEquals(integerValue(2020), eval(expression)); - expression = dsl.year(DSL.literal("2020-08-07")); + expression = DSL.year(DSL.literal("2020-08-07")); assertEquals(INTEGER, expression.type()); assertEquals("year(\"2020-08-07\")", expression.toString()); assertEquals(integerValue(2020), eval(expression)); - expression = dsl.year(DSL.literal("2020-08-07 01:01:01")); + expression = DSL.year(DSL.literal("2020-08-07 01:01:01")); assertEquals(INTEGER, expression.type()); assertEquals("year(\"2020-08-07 01:01:01\")", expression.toString()); assertEquals(integerValue(2020), eval(expression)); @@ -1004,31 +1004,31 @@ public void date_format() { String timestampFormatted = "Sat Jan 01 31st 31 31 12345 13 01 01 14 031 13 1 " + "January 01 PM 01:14:15 PM 15 15 13:14:15 % P"; - FunctionExpression expr = dsl.date_format(DSL.literal(timestamp), DSL.literal(timestampFormat)); + FunctionExpression expr = DSL.date_format(DSL.literal(timestamp), DSL.literal(timestampFormat)); assertEquals(STRING, expr.type()); assertEquals(timestampFormatted, eval(expr).stringValue()); when(nullRef.type()).thenReturn(DATE); when(missingRef.type()).thenReturn(DATE); - assertEquals(nullValue(), eval(dsl.date_format(nullRef, DSL.literal("")))); - assertEquals(missingValue(), eval(dsl.date_format(missingRef, DSL.literal("")))); + assertEquals(nullValue(), eval(DSL.date_format(nullRef, DSL.literal("")))); + assertEquals(missingValue(), eval(DSL.date_format(missingRef, DSL.literal("")))); when(nullRef.type()).thenReturn(DATETIME); when(missingRef.type()).thenReturn(DATETIME); - assertEquals(nullValue(), eval(dsl.date_format(nullRef, DSL.literal("")))); - assertEquals(missingValue(), eval(dsl.date_format(missingRef, DSL.literal("")))); + assertEquals(nullValue(), eval(DSL.date_format(nullRef, DSL.literal("")))); + assertEquals(missingValue(), eval(DSL.date_format(missingRef, DSL.literal("")))); when(nullRef.type()).thenReturn(TIMESTAMP); when(missingRef.type()).thenReturn(TIMESTAMP); - assertEquals(nullValue(), eval(dsl.date_format(nullRef, DSL.literal("")))); - assertEquals(missingValue(), eval(dsl.date_format(missingRef, DSL.literal("")))); + assertEquals(nullValue(), eval(DSL.date_format(nullRef, DSL.literal("")))); + assertEquals(missingValue(), eval(DSL.date_format(missingRef, DSL.literal("")))); when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(nullValue(), eval(dsl.date_format(nullRef, DSL.literal("")))); - assertEquals(missingValue(), eval(dsl.date_format(missingRef, DSL.literal("")))); - assertEquals(nullValue(), eval(dsl.date_format(DSL.literal(""), nullRef))); - assertEquals(missingValue(), eval(dsl.date_format(DSL.literal(""), missingRef))); + assertEquals(nullValue(), eval(DSL.date_format(nullRef, DSL.literal("")))); + assertEquals(missingValue(), eval(DSL.date_format(missingRef, DSL.literal("")))); + assertEquals(nullValue(), eval(DSL.date_format(DSL.literal(""), nullRef))); + assertEquals(missingValue(), eval(DSL.date_format(DSL.literal(""), missingRef))); } void testDateFormat(DateFormatTester dft) { diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java index 7728a1cac3..b5e184dbf0 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java @@ -37,21 +37,21 @@ class DateTimeTest extends ExpressionTestBase { @Test public void noTimeZoneNoField2() { - FunctionExpression expr = dsl.datetime(DSL.literal("2008-05-15 22:00:00")); + FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00")); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2008-05-15 22:00:00"), expr.valueOf(env)); } @Test public void positiveTimeZoneNoField2() { - FunctionExpression expr = dsl.datetime(DSL.literal("2008-05-15 22:00:00+01:00")); + FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00+01:00")); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2008-05-15 22:00:00"), expr.valueOf(env)); } @Test public void positiveField1WrittenField2() { - FunctionExpression expr = dsl.datetime(DSL.literal("2008-05-15 22:00:00+01:00"), + FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00+01:00"), DSL.literal("America/Los_Angeles")); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2008-05-15 14:00:00"), expr.valueOf(env)); @@ -67,7 +67,7 @@ public void localDateTimeConversion() { LocalDateTime timeConverted = LocalDateTime.parse(dt, formatter); ZonedDateTime timeZoneLocal = timeConverted.atZone(ZoneId.of(TimeZone.getDefault().getID())) .withZoneSameInstant(ZoneId.of(timeZone)); - FunctionExpression expr = dsl.datetime(DSL.literal(dt), + FunctionExpression expr = DSL.datetime(DSL.literal(dt), DSL.literal(timeZone)); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue(timeZoneLocal.toLocalDateTime()), expr.valueOf(env)); @@ -75,7 +75,7 @@ public void localDateTimeConversion() { @Test public void negativeField1WrittenField2() { - FunctionExpression expr = dsl.datetime(DSL.literal("2008-05-15 22:00:00-11:00"), + FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00-11:00"), DSL.literal("America/Los_Angeles")); assertEquals(DATETIME, expr.type()); assertEquals(new ExprDatetimeValue("2008-05-16 02:00:00"), expr.valueOf(env)); @@ -83,7 +83,7 @@ public void negativeField1WrittenField2() { @Test public void negativeField1PositiveField2() { - FunctionExpression expr = dsl.datetime(DSL.literal("2008-05-15 22:00:00-12:00"), + FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00-12:00"), DSL.literal("+15:00")); assertEquals(DATETIME, expr.type()); assertEquals(nullValue(), expr.valueOf(env)); @@ -91,7 +91,7 @@ public void negativeField1PositiveField2() { @Test public void twentyFourHourDifference() { - FunctionExpression expr = dsl.datetime(DSL.literal("2008-05-15 22:00:00-14:00"), + FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00-14:00"), DSL.literal("+10:00")); assertEquals(DATETIME, expr.type()); assertEquals(nullValue(), expr.valueOf(env)); @@ -99,7 +99,7 @@ public void twentyFourHourDifference() { @Test public void negativeToNull() { - FunctionExpression expr = dsl.datetime(DSL.literal("2008-05-15 22:00:00-11:00"), + FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00-11:00"), DSL.literal(nullValue())); assertEquals(DATETIME, expr.type()); assertEquals(nullValue(), expr.valueOf(env)); @@ -107,7 +107,7 @@ public void negativeToNull() { @Test public void invalidDate() { - FunctionExpression expr = dsl.datetime(DSL.literal("2008-04-31 22:00:00-11:00")); + FunctionExpression expr = DSL.datetime(DSL.literal("2008-04-31 22:00:00-11:00")); assertEquals(DATETIME, expr.type()); assertEquals(nullValue(), expr.valueOf(env)); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java index bee16cb92a..7c8464e79c 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java @@ -44,24 +44,23 @@ public class DateTimeTestBase extends ExpressionTestBase { @Mock protected Expression missingRef; - @Autowired - protected BuiltinFunctionRepository functionRepository; - protected ExprValue eval(Expression expression) { return expression.valueOf(env); } protected FunctionExpression fromUnixTime(Expression value) { - var func = functionRepository.resolve(Collections.singletonList(DEFAULT_NAMESPACE), - new FunctionSignature(new FunctionName("from_unixtime"), - List.of(value.type()))); + var func = BuiltinFunctionRepository.getInstance() + .resolve(Collections.singletonList(DEFAULT_NAMESPACE), + new FunctionSignature(new FunctionName("from_unixtime"), + List.of(value.type()))); return (FunctionExpression)func.apply(List.of(value)); } protected FunctionExpression fromUnixTime(Expression value, Expression format) { - var func = functionRepository.resolve(Collections.singletonList(DEFAULT_NAMESPACE), - new FunctionSignature(new FunctionName("from_unixtime"), - List.of(value.type(), format.type()))); + var func = BuiltinFunctionRepository.getInstance() + .resolve(Collections.singletonList(DEFAULT_NAMESPACE), + new FunctionSignature(new FunctionName("from_unixtime"), + List.of(value.type(), format.type()))); return (FunctionExpression)func.apply(List.of(value, format)); } @@ -82,9 +81,10 @@ protected String fromUnixTime(Double value, String format) { } protected FunctionExpression makedate(Expression year, Expression dayOfYear) { - var func = functionRepository.resolve(Collections.singletonList(DEFAULT_NAMESPACE), - new FunctionSignature(new FunctionName("makedate"), - List.of(DOUBLE, DOUBLE))); + var func = BuiltinFunctionRepository.getInstance() + .resolve(Collections.singletonList(DEFAULT_NAMESPACE), + new FunctionSignature(new FunctionName("makedate"), + List.of(DOUBLE, DOUBLE))); return (FunctionExpression)func.apply(List.of(year, dayOfYear)); } @@ -93,9 +93,10 @@ protected LocalDate makedate(Double year, Double dayOfYear) { } protected FunctionExpression maketime(Expression hour, Expression minute, Expression second) { - var func = functionRepository.resolve(Collections.singletonList(DEFAULT_NAMESPACE), - new FunctionSignature(new FunctionName("maketime"), - List.of(DOUBLE, DOUBLE, DOUBLE))); + var func = BuiltinFunctionRepository.getInstance() + .resolve(Collections.singletonList(DEFAULT_NAMESPACE), + new FunctionSignature(new FunctionName("maketime"), + List.of(DOUBLE, DOUBLE, DOUBLE))); return (FunctionExpression)func.apply(List.of(hour, minute, second)); } @@ -105,9 +106,10 @@ protected LocalTime maketime(Double hour, Double minute, Double second) { } protected FunctionExpression period_add(Expression period, Expression months) { - var func = functionRepository.resolve(Collections.singletonList(DEFAULT_NAMESPACE), - new FunctionSignature(new FunctionName("period_add"), - List.of(INTEGER, INTEGER))); + var func = BuiltinFunctionRepository.getInstance() + .resolve(Collections.singletonList(DEFAULT_NAMESPACE), + new FunctionSignature(new FunctionName("period_add"), + List.of(INTEGER, INTEGER))); return (FunctionExpression)func.apply(List.of(period, months)); } @@ -116,9 +118,10 @@ protected Integer period_add(Integer period, Integer months) { } protected FunctionExpression period_diff(Expression first, Expression second) { - var func = functionRepository.resolve(Collections.singletonList(DEFAULT_NAMESPACE), - new FunctionSignature(new FunctionName("period_diff"), - List.of(INTEGER, INTEGER))); + var func = BuiltinFunctionRepository.getInstance() + .resolve(Collections.singletonList(DEFAULT_NAMESPACE), + new FunctionSignature(new FunctionName("period_diff"), + List.of(INTEGER, INTEGER))); return (FunctionExpression)func.apply(List.of(first, second)); } @@ -127,8 +130,9 @@ protected Integer period_diff(Integer first, Integer second) { } protected FunctionExpression unixTimeStampExpr() { - var func = functionRepository.resolve(Collections.singletonList(DEFAULT_NAMESPACE), - new FunctionSignature(new FunctionName("unix_timestamp"), List.of())); + var func = BuiltinFunctionRepository.getInstance() + .resolve(Collections.singletonList(DEFAULT_NAMESPACE), + new FunctionSignature(new FunctionName("unix_timestamp"), List.of())); return (FunctionExpression)func.apply(List.of()); } @@ -137,9 +141,10 @@ protected Long unixTimeStamp() { } protected FunctionExpression unixTimeStampOf(Expression value) { - var func = functionRepository.resolve(Collections.singletonList(DEFAULT_NAMESPACE), - new FunctionSignature(new FunctionName("unix_timestamp"), - List.of(value.type()))); + var func = BuiltinFunctionRepository.getInstance() + .resolve(Collections.singletonList(DEFAULT_NAMESPACE), + new FunctionSignature(new FunctionName("unix_timestamp"), + List.of(value.type()))); return (FunctionExpression)func.apply(List.of(value)); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/IntervalClauseTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/IntervalClauseTest.java index f8636e016c..3e2d7f04cb 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/IntervalClauseTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/IntervalClauseTest.java @@ -42,77 +42,77 @@ public class IntervalClauseTest extends ExpressionTestBase { @Test public void microsecond() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("microsecond")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("microsecond")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Duration.ofNanos(1000)), expr.valueOf(env)); } @Test public void second() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("second")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("second")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Duration.ofSeconds(1)), expr.valueOf(env)); } @Test public void minute() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("minute")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("minute")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Duration.ofMinutes(1)), expr.valueOf(env)); } @Test public void hour() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("HOUR")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("HOUR")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Duration.ofHours(1)), expr.valueOf(env)); } @Test public void day() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("day")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("day")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Duration.ofDays(1)), expr.valueOf(env)); } @Test public void week() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("week")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("week")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Period.ofWeeks(1)), expr.valueOf(env)); } @Test public void month() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("month")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("month")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Period.ofMonths(1)), expr.valueOf(env)); } @Test public void quarter() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("quarter")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("quarter")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Period.ofMonths(3)), expr.valueOf(env)); } @Test public void year() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("year")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("year")); assertEquals(INTERVAL, expr.type()); assertEquals(intervalValue(Period.ofYears(1)), expr.valueOf(env)); } @Test public void unsupported_unit() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("year_month")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("year_month")); assertThrows(ExpressionEvaluationException.class, () -> expr.valueOf(env), "interval unit year_month is not supported"); } @Test public void to_string() { - FunctionExpression expr = dsl.interval(DSL.literal(1), DSL.literal("day")); + FunctionExpression expr = DSL.interval(DSL.literal(1), DSL.literal("day")); assertEquals("interval(1, \"day\")", expr.toString()); } @@ -120,7 +120,7 @@ public void to_string() { public void null_value() { when(nullRef.type()).thenReturn(INTEGER); when(nullRef.valueOf(env)).thenReturn(nullValue()); - FunctionExpression expr = dsl.interval(nullRef, DSL.literal("day")); + FunctionExpression expr = DSL.interval(nullRef, DSL.literal("day")); assertEquals(INTERVAL, expr.type()); assertEquals(nullValue(), expr.valueOf(env)); } @@ -129,7 +129,7 @@ public void null_value() { public void missing_value() { when(missingRef.type()).thenReturn(INTEGER); when(missingRef.valueOf(env)).thenReturn(missingValue()); - FunctionExpression expr = dsl.interval(missingRef, DSL.literal("day")); + FunctionExpression expr = DSL.interval(missingRef, DSL.literal("day")); assertEquals(INTERVAL, expr.type()); assertEquals(missingValue(), expr.valueOf(env)); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java index b6b82fe8fb..437f484e80 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java @@ -31,30 +31,28 @@ import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.ExpressionTestBase; import org.opensearch.sql.expression.FunctionExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; public class NowLikeFunctionTest extends ExpressionTestBase { private static Stream functionNames() { - var dsl = new DSL(new ExpressionConfig().functionRepository()); return Stream.of( - Arguments.of((Function)dsl::now, + Arguments.of((Function) DSL::now, "now", DATETIME, false, (Supplier)LocalDateTime::now), - Arguments.of((Function)dsl::current_timestamp, + Arguments.of((Function) DSL::current_timestamp, "current_timestamp", DATETIME, false, (Supplier)LocalDateTime::now), - Arguments.of((Function)dsl::localtimestamp, + Arguments.of((Function) DSL::localtimestamp, "localtimestamp", DATETIME, false, (Supplier)LocalDateTime::now), - Arguments.of((Function)dsl::localtime, + Arguments.of((Function) DSL::localtime, "localtime", DATETIME, false, (Supplier)LocalDateTime::now), - Arguments.of((Function)dsl::sysdate, + Arguments.of((Function) DSL::sysdate, "sysdate", DATETIME, true, (Supplier)LocalDateTime::now), - Arguments.of((Function)dsl::curtime, + Arguments.of((Function) DSL::curtime, "curtime", TIME, false, (Supplier)LocalTime::now), - Arguments.of((Function)dsl::current_time, + Arguments.of((Function) DSL::current_time, "current_time", TIME, false, (Supplier)LocalTime::now), - Arguments.of((Function)dsl::curdate, + Arguments.of((Function) DSL::curdate, "curdate", DATE, false, (Supplier)LocalDate::now), - Arguments.of((Function)dsl::current_date, + Arguments.of((Function) DSL::current_date, "current_date", DATE, false, (Supplier)LocalDate::now)); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java index dc509d175b..a5ddee2d0c 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java @@ -8,30 +8,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import java.time.Instant; -import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; -import java.util.List; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.opensearch.sql.data.model.ExprDateValue; import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprLongValue; -import org.opensearch.sql.data.model.ExprTimestampValue; -import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.Expression; -import org.opensearch.sql.expression.ExpressionTestBase; -import org.opensearch.sql.expression.FunctionExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; -import org.opensearch.sql.expression.env.Environment; -import org.opensearch.sql.expression.function.FunctionName; -import org.opensearch.sql.expression.function.FunctionSignature; public class UnixTwoWayConversionTest extends DateTimeTestBase { diff --git a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java index 5dd98dfedf..f63304e6b5 100644 --- a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java @@ -87,7 +87,7 @@ void register() { } @Test - void register_under_catalog_namespace() { + void register_under_datasource_namespace() { when(mockNamespaceMap.containsKey(TEST_NAMESPACE)).thenReturn(false); when(mockNamespaceMap.put(eq(TEST_NAMESPACE), any())).thenReturn(null); when(mockNamespaceMap.get(TEST_NAMESPACE)).thenReturn(mockMap); @@ -120,7 +120,7 @@ void compile() { @Test - void compile_function_under_catalog_namespace() { + void compile_function_under_datasource_namespace() { when(mockExpression.type()).thenReturn(UNDEFINED); when(functionSignature.getParamTypeList()).thenReturn(Arrays.asList(UNDEFINED)); when(mockfunctionResolver.getFunctionName()).thenReturn(mockFunctionName); diff --git a/core/src/test/java/org/opensearch/sql/expression/function/OpenSearchFunctionsTest.java b/core/src/test/java/org/opensearch/sql/expression/function/OpenSearchFunctionsTest.java index 620bdbf1b4..787ca016c9 100644 --- a/core/src/test/java/org/opensearch/sql/expression/function/OpenSearchFunctionsTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/function/OpenSearchFunctionsTest.java @@ -61,62 +61,62 @@ public class OpenSearchFunctionsTest extends ExpressionTestBase { @Test void match() { - FunctionExpression expr = dsl.match(field, query); + FunctionExpression expr = DSL.match(field, query); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match(field, query, analyzer); + expr = DSL.match(field, query, analyzer); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match(field, query, analyzer, autoGenerateSynonymsPhrase); + expr = DSL.match(field, query, analyzer, autoGenerateSynonymsPhrase); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match(field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness); + expr = DSL.match(field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match(field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions); + expr = DSL.match(field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength, fuzzyTranspositions); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength, fuzzyTranspositions, fuzzyRewrite); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength, fuzzyTranspositions, fuzzyRewrite, lenient); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength, fuzzyTranspositions, fuzzyRewrite, lenient, operator); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength, fuzzyTranspositions, fuzzyRewrite, lenient, operator); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength, fuzzyTranspositions, fuzzyRewrite, lenient, operator, minimumShouldMatch); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength, fuzzyTranspositions, fuzzyRewrite, lenient, operator, minimumShouldMatch, zeroTermsQueryAll); assertEquals(BOOLEAN, expr.type()); - expr = dsl.match( + expr = DSL.match( field, query, analyzer, autoGenerateSynonymsPhrase, fuzziness, maxExpansions, prefixLength, fuzzyTranspositions, fuzzyRewrite, lenient, operator, minimumShouldMatch, zeroTermsQueryNone, boost); @@ -133,16 +133,16 @@ void match_phrase() { List match_phrase_dsl_expressions() { return List.of( - dsl.match_phrase(field, query), - dsl.match_phrase(field, query, analyzer), - dsl.match_phrase(field, query, analyzer, zeroTermsQueryAll), - dsl.match_phrase(field, query, analyzer, zeroTermsQueryNone, slop) + DSL.match_phrase(field, query), + DSL.match_phrase(field, query, analyzer), + DSL.match_phrase(field, query, analyzer, zeroTermsQueryAll), + DSL.match_phrase(field, query, analyzer, zeroTermsQueryNone, slop) ); } List match_phrase_prefix_dsl_expressions() { return List.of( - dsl.match_phrase_prefix(field, query) + DSL.match_phrase_prefix(field, query) ); } @@ -155,7 +155,7 @@ public void match_phrase_prefix() { @Test void match_in_memory() { - FunctionExpression expr = dsl.match(field, query); + FunctionExpression expr = DSL.match(field, query); assertThrows(UnsupportedOperationException.class, () -> expr.valueOf(valueEnv()), "OpenSearch defined function [match] is only supported in WHERE and HAVING clause."); @@ -163,13 +163,13 @@ void match_in_memory() { @Test void match_to_string() { - FunctionExpression expr = dsl.match(field, query); + FunctionExpression expr = DSL.match(field, query); assertEquals("match(field=\"message\", query=\"search query\")", expr.toString()); } @Test void multi_match() { - FunctionExpression expr = dsl.multi_match(fields, query); + FunctionExpression expr = DSL.multi_match(fields, query); assertEquals(String.format("multi_match(fields=%s, query=%s)", fields.getValue(), query.getValue()), expr.toString()); @@ -177,7 +177,7 @@ void multi_match() { @Test void simple_query_string() { - FunctionExpression expr = dsl.simple_query_string(fields, query); + FunctionExpression expr = DSL.simple_query_string(fields, query); assertEquals(String.format("simple_query_string(fields=%s, query=%s)", fields.getValue(), query.getValue()), expr.toString()); @@ -185,14 +185,14 @@ void simple_query_string() { @Test void query() { - FunctionExpression expr = dsl.query(query); + FunctionExpression expr = DSL.query(query); assertEquals(String.format("query(query=%s)", query.getValue()), expr.toString()); } @Test void query_string() { - FunctionExpression expr = dsl.query_string(fields, query); + FunctionExpression expr = DSL.query_string(fields, query); assertEquals(String.format("query_string(fields=%s, query=%s)", fields.getValue(), query.getValue()), expr.toString()); diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunctionTest.java index 44af20a690..7c0c6f8a82 100644 --- a/core/src/test/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunctionTest.java @@ -39,6 +39,7 @@ import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.data.type.WideningTypeRule; +import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.ExpressionTestBase; import org.opensearch.sql.expression.FunctionExpression; @@ -68,7 +69,7 @@ private static Stream arithmeticOperatorArguments() { @ParameterizedTest(name = "add({1}, {2})") @MethodSource("arithmeticFunctionArguments") public void add(ExprValue op1, ExprValue op2) { - FunctionExpression expression = dsl.add(literal(op1), literal(op2)); + FunctionExpression expression = DSL.add(literal(op1), literal(op2)); ExprType expectedType = WideningTypeRule.max(op1.type(), op2.type()); assertEquals(expectedType, expression.type()); assertValueEqual(BuiltinFunctionName.ADD, expectedType, op1, op2, expression.valueOf()); @@ -143,7 +144,7 @@ public void arithmetic_null_missing(BuiltinFunctionName builtinFunctionName) { @ParameterizedTest(name = "subtract({1}, {2})") @MethodSource("arithmeticFunctionArguments") public void subtract(ExprValue op1, ExprValue op2) { - FunctionExpression expression = dsl.subtract(literal(op1), literal(op2)); + FunctionExpression expression = DSL.subtract(literal(op1), literal(op2)); ExprType expectedType = WideningTypeRule.max(op1.type(), op2.type()); assertEquals(expectedType, expression.type()); assertValueEqual(BuiltinFunctionName.SUBTRACT, expectedType, op1, op2, @@ -155,7 +156,7 @@ public void subtract(ExprValue op1, ExprValue op2) { @ParameterizedTest(name = "multiply({1}, {2})") @MethodSource("arithmeticFunctionArguments") public void multiply(ExprValue op1, ExprValue op2) { - FunctionExpression expression = dsl.multiply(literal(op1), literal(op2)); + FunctionExpression expression = DSL.multiply(literal(op1), literal(op2)); ExprType expectedType = WideningTypeRule.max(op1.type(), op2.type()); assertEquals(expectedType, expression.type()); assertValueEqual(BuiltinFunctionName.MULTIPLY, expectedType, op1, op2, @@ -167,14 +168,14 @@ public void multiply(ExprValue op1, ExprValue op2) { @ParameterizedTest(name = "divide({1}, {2})") @MethodSource("arithmeticFunctionArguments") public void divide(ExprValue op1, ExprValue op2) { - FunctionExpression expression = dsl.divide(literal(op1), literal(op2)); + FunctionExpression expression = DSL.divide(literal(op1), literal(op2)); ExprType expectedType = WideningTypeRule.max(op1.type(), op2.type()); assertEquals(expectedType, expression.type()); assertValueEqual(BuiltinFunctionName.DIVIDE, expectedType, op1, op2, expression.valueOf()); assertEquals(String.format("/(%s, %s)", op1.toString(), op2.toString()), expression.toString()); - expression = dsl.divide(literal(op1), literal(new ExprShortValue(0))); + expression = DSL.divide(literal(op1), literal(new ExprShortValue(0))); expectedType = WideningTypeRule.max(op1.type(), SHORT); assertEquals(expectedType, expression.type()); assertTrue(expression.valueOf(valueEnv()).isNull()); @@ -184,14 +185,14 @@ public void divide(ExprValue op1, ExprValue op2) { @ParameterizedTest(name = "module({1}, {2})") @MethodSource("arithmeticFunctionArguments") public void module(ExprValue op1, ExprValue op2) { - FunctionExpression expression = dsl.module(literal(op1), literal(op2)); + FunctionExpression expression = DSL.module(literal(op1), literal(op2)); ExprType expectedType = WideningTypeRule.max(op1.type(), op2.type()); assertEquals(expectedType, expression.type()); assertValueEqual(BuiltinFunctionName.MODULES, expectedType, op1, op2, expression.valueOf()); assertEquals(String.format("%%(%s, %s)", op1.toString(), op2.toString()), expression.toString()); - expression = dsl.module(literal(op1), literal(new ExprShortValue(0))); + expression = DSL.module(literal(op1), literal(new ExprShortValue(0))); expectedType = WideningTypeRule.max(op1.type(), SHORT); assertEquals(expectedType, expression.type()); assertTrue(expression.valueOf(valueEnv()).isNull()); diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunctionTest.java index 4ce975c7d2..59e12a4155 100644 --- a/core/src/test/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunctionTest.java @@ -101,7 +101,7 @@ private static Stream trigonometricDoubleArguments() { @ParameterizedTest(name = "abs({0})") @ValueSource(bytes = {-2, 2}) public void abs_byte_value(Byte value) { - FunctionExpression abs = dsl.abs(DSL.literal(value)); + FunctionExpression abs = DSL.abs(DSL.literal(value)); assertThat(abs.valueOf(valueEnv()), allOf(hasType(BYTE), hasValue(((byte) Math.abs(value))))); assertEquals(String.format("abs(%s)", value.toString()), abs.toString()); } @@ -112,7 +112,7 @@ public void abs_byte_value(Byte value) { @ParameterizedTest(name = "abs({0})") @ValueSource(ints = {-2, 2}) public void abs_int_value(Integer value) { - FunctionExpression abs = dsl.abs(DSL.literal(value)); + FunctionExpression abs = DSL.abs(DSL.literal(value)); assertThat( abs.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue(Math.abs(value)))); @@ -125,7 +125,7 @@ public void abs_int_value(Integer value) { @ParameterizedTest(name = "abs({0})") @ValueSource(longs = {-2L, 2L}) public void abs_long_value(Long value) { - FunctionExpression abs = dsl.abs(DSL.literal(value)); + FunctionExpression abs = DSL.abs(DSL.literal(value)); assertThat( abs.valueOf(valueEnv()), allOf(hasType(LONG), hasValue(Math.abs(value)))); @@ -138,7 +138,7 @@ public void abs_long_value(Long value) { @ParameterizedTest(name = "abs({0})") @ValueSource(floats = {-2f, 2f}) public void abs_float_value(Float value) { - FunctionExpression abs = dsl.abs(DSL.literal(value)); + FunctionExpression abs = DSL.abs(DSL.literal(value)); assertThat( abs.valueOf(valueEnv()), allOf(hasType(FLOAT), hasValue(Math.abs(value)))); @@ -151,7 +151,7 @@ public void abs_float_value(Float value) { @ParameterizedTest(name = "abs({0})") @ValueSource(doubles = {-2L, 2L}) public void abs_double_value(Double value) { - FunctionExpression abs = dsl.abs(DSL.literal(value)); + FunctionExpression abs = DSL.abs(DSL.literal(value)); assertThat( abs.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.abs(value)))); @@ -164,7 +164,7 @@ public void abs_double_value(Double value) { @ParameterizedTest(name = "abs({0})") @ValueSource(shorts = {-2, 2}) public void abs_short_value(Short value) { - FunctionExpression abs = dsl.abs(DSL.literal(new ExprShortValue(value))); + FunctionExpression abs = DSL.abs(DSL.literal(new ExprShortValue(value))); assertThat( abs.valueOf(valueEnv()), allOf(hasType(SHORT), hasValue(Integer.valueOf(Math.abs(value)).shortValue()))); @@ -173,13 +173,13 @@ public void abs_short_value(Short value) { @Test public void abs_null_value() { - assertTrue(dsl.abs(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)).valueOf(valueEnv()).isNull()); + assertTrue(DSL.abs(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)).valueOf(valueEnv()).isNull()); } @Test public void abs_missing_value() { assertTrue( - dsl.abs(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)).valueOf(valueEnv()).isMissing()); + DSL.abs(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)).valueOf(valueEnv()).isMissing()); } /** @@ -188,13 +188,13 @@ public void abs_missing_value() { @ParameterizedTest(name = "ceil({0})") @ValueSource(ints = {2, -2}) public void ceil_int_value(Integer value) { - FunctionExpression ceil = dsl.ceil(DSL.literal(value)); + FunctionExpression ceil = DSL.ceil(DSL.literal(value)); assertThat( ceil.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); assertEquals(String.format("ceil(%s)", value.toString()), ceil.toString()); - FunctionExpression ceiling = dsl.ceiling(DSL.literal(value)); + FunctionExpression ceiling = DSL.ceiling(DSL.literal(value)); assertThat( ceiling.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); assertEquals(String.format("ceiling(%s)", value.toString()), ceiling.toString()); @@ -206,12 +206,12 @@ public void ceil_int_value(Integer value) { @ParameterizedTest(name = "ceil({0})") @ValueSource(longs = {2L, -2L}) public void ceil_long_value(Long value) { - FunctionExpression ceil = dsl.ceil(DSL.literal(value)); + FunctionExpression ceil = DSL.ceil(DSL.literal(value)); assertThat( ceil.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); assertEquals(String.format("ceil(%s)", value.toString()), ceil.toString()); - FunctionExpression ceiling = dsl.ceiling(DSL.literal(value)); + FunctionExpression ceiling = DSL.ceiling(DSL.literal(value)); assertThat( ceiling.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); assertEquals(String.format("ceiling(%s)", value.toString()), ceiling.toString()); @@ -223,12 +223,12 @@ public void ceil_long_value(Long value) { @ParameterizedTest(name = "ceil({0})") @ValueSource(floats = {2F, -2F}) public void ceil_float_value(Float value) { - FunctionExpression ceil = dsl.ceil(DSL.literal(value)); + FunctionExpression ceil = DSL.ceil(DSL.literal(value)); assertThat( ceil.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); assertEquals(String.format("ceil(%s)", value.toString()), ceil.toString()); - FunctionExpression ceiling = dsl.ceiling(DSL.literal(value)); + FunctionExpression ceiling = DSL.ceiling(DSL.literal(value)); assertThat( ceiling.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); assertEquals(String.format("ceiling(%s)", value.toString()), ceiling.toString()); @@ -240,12 +240,12 @@ public void ceil_float_value(Float value) { @ParameterizedTest(name = "ceil({0})") @ValueSource(doubles = {-2L, 2L}) public void ceil_double_value(Double value) { - FunctionExpression ceil = dsl.ceil(DSL.literal(value)); + FunctionExpression ceil = DSL.ceil(DSL.literal(value)); assertThat( ceil.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); assertEquals(String.format("ceil(%s)", value.toString()), ceil.toString()); - FunctionExpression ceiling = dsl.ceiling(DSL.literal(value)); + FunctionExpression ceiling = DSL.ceiling(DSL.literal(value)); assertThat( ceiling.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); assertEquals(String.format("ceiling(%s)", value.toString()), ceiling.toString()); @@ -256,11 +256,11 @@ public void ceil_double_value(Double value) { */ @Test public void ceil_null_value() { - FunctionExpression ceil = dsl.ceil(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression ceil = DSL.ceil(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(INTEGER, ceil.type()); assertTrue(ceil.valueOf(valueEnv()).isNull()); - FunctionExpression ceiling = dsl.ceiling(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression ceiling = DSL.ceiling(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(INTEGER, ceiling.type()); assertTrue(ceiling.valueOf(valueEnv()).isNull()); } @@ -270,11 +270,11 @@ public void ceil_null_value() { */ @Test public void ceil_missing_value() { - FunctionExpression ceil = dsl.ceil(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression ceil = DSL.ceil(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(INTEGER, ceil.type()); assertTrue(ceil.valueOf(valueEnv()).isMissing()); - FunctionExpression ceiling = dsl.ceiling(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression ceiling = DSL.ceiling(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(INTEGER, ceiling.type()); assertTrue(ceiling.valueOf(valueEnv()).isMissing()); } @@ -285,19 +285,19 @@ public void ceil_missing_value() { @ParameterizedTest(name = "conv({0})") @ValueSource(strings = {"1", "0", "-1"}) public void conv_from_decimal(String value) { - FunctionExpression conv = dsl.conv(DSL.literal(value), DSL.literal(10), DSL.literal(2)); + FunctionExpression conv = DSL.conv(DSL.literal(value), DSL.literal(10), DSL.literal(2)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value), 2)))); assertEquals(String.format("conv(\"%s\", 10, 2)", value), conv.toString()); - conv = dsl.conv(DSL.literal(value), DSL.literal(10), DSL.literal(8)); + conv = DSL.conv(DSL.literal(value), DSL.literal(10), DSL.literal(8)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value), 8)))); assertEquals(String.format("conv(\"%s\", 10, 8)", value), conv.toString()); - conv = dsl.conv(DSL.literal(value), DSL.literal(10), DSL.literal(16)); + conv = DSL.conv(DSL.literal(value), DSL.literal(10), DSL.literal(16)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value), 16)))); @@ -310,19 +310,19 @@ public void conv_from_decimal(String value) { @ParameterizedTest(name = "conv({0})") @ValueSource(ints = {1, 0, -1}) public void conv_from_decimal(Integer value) { - FunctionExpression conv = dsl.conv(DSL.literal(value), DSL.literal(10), DSL.literal(2)); + FunctionExpression conv = DSL.conv(DSL.literal(value), DSL.literal(10), DSL.literal(2)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(value, 2)))); assertEquals(String.format("conv(%s, 10, 2)", value), conv.toString()); - conv = dsl.conv(DSL.literal(value), DSL.literal(10), DSL.literal(8)); + conv = DSL.conv(DSL.literal(value), DSL.literal(10), DSL.literal(8)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(value, 8)))); assertEquals(String.format("conv(%s, 10, 8)", value), conv.toString()); - conv = dsl.conv(DSL.literal(value), DSL.literal(10), DSL.literal(16)); + conv = DSL.conv(DSL.literal(value), DSL.literal(10), DSL.literal(16)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(value, 16)))); @@ -335,19 +335,19 @@ public void conv_from_decimal(Integer value) { @ParameterizedTest(name = "conv({0})") @ValueSource(strings = {"11", "0", "11111"}) public void conv_to_decimal(String value) { - FunctionExpression conv = dsl.conv(DSL.literal(value), DSL.literal(2), DSL.literal(10)); + FunctionExpression conv = DSL.conv(DSL.literal(value), DSL.literal(2), DSL.literal(10)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value, 2))))); assertEquals(String.format("conv(\"%s\", 2, 10)", value), conv.toString()); - conv = dsl.conv(DSL.literal(value), DSL.literal(8), DSL.literal(10)); + conv = DSL.conv(DSL.literal(value), DSL.literal(8), DSL.literal(10)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value, 8))))); assertEquals(String.format("conv(\"%s\", 8, 10)", value), conv.toString()); - conv = dsl.conv(DSL.literal(value), DSL.literal(16), DSL.literal(10)); + conv = DSL.conv(DSL.literal(value), DSL.literal(16), DSL.literal(10)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value, 16))))); @@ -360,19 +360,19 @@ public void conv_to_decimal(String value) { @ParameterizedTest(name = "conv({0})") @ValueSource(ints = {11, 0, 11111}) public void conv_to_decimal(Integer value) { - FunctionExpression conv = dsl.conv(DSL.literal(value), DSL.literal(2), DSL.literal(10)); + FunctionExpression conv = DSL.conv(DSL.literal(value), DSL.literal(2), DSL.literal(10)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value.toString(), 2))))); assertEquals(String.format("conv(%s, 2, 10)", value), conv.toString()); - conv = dsl.conv(DSL.literal(value), DSL.literal(8), DSL.literal(10)); + conv = DSL.conv(DSL.literal(value), DSL.literal(8), DSL.literal(10)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value.toString(), 8))))); assertEquals(String.format("conv(%s, 8, 10)", value), conv.toString()); - conv = dsl.conv(DSL.literal(value), DSL.literal(16), DSL.literal(10)); + conv = DSL.conv(DSL.literal(value), DSL.literal(16), DSL.literal(10)); assertThat( conv.valueOf(valueEnv()), allOf(hasType(STRING), hasValue(Integer.toString(Integer.parseInt(value.toString(), 16))))); @@ -384,17 +384,17 @@ public void conv_to_decimal(Integer value) { */ @Test public void conv_null_value() { - FunctionExpression conv = dsl.conv( + FunctionExpression conv = DSL.conv( DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING), DSL.literal(10), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isNull()); - conv = dsl.conv( + conv = DSL.conv( DSL.literal("1"), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isNull()); - conv = dsl.conv( + conv = DSL.conv( DSL.literal("1"), DSL.literal(10), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isNull()); @@ -405,17 +405,17 @@ public void conv_null_value() { */ @Test public void conv_missing_value() { - FunctionExpression conv = dsl.conv( + FunctionExpression conv = DSL.conv( DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), DSL.literal(10), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isMissing()); - conv = dsl.conv( + conv = DSL.conv( DSL.literal("1"), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isMissing()); - conv = dsl.conv( + conv = DSL.conv( DSL.literal("1"), DSL.literal(10), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isMissing()); @@ -426,7 +426,7 @@ public void conv_missing_value() { */ @Test public void conv_null_missing() { - FunctionExpression conv = dsl.conv(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), + FunctionExpression conv = DSL.conv(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isMissing()); @@ -438,7 +438,7 @@ public void conv_null_missing() { @ParameterizedTest(name = "crc({0})") @ValueSource(strings = {"odfe", "sql"}) public void crc32_string_value(String value) { - FunctionExpression crc = dsl.crc32(DSL.literal(value)); + FunctionExpression crc = DSL.crc32(DSL.literal(value)); CRC32 crc32 = new CRC32(); crc32.update(value.getBytes()); assertThat( @@ -452,7 +452,7 @@ public void crc32_string_value(String value) { */ @Test public void crc32_null_value() { - FunctionExpression crc = dsl.crc32(DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING)); + FunctionExpression crc = DSL.crc32(DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING)); assertEquals(LONG, crc.type()); assertTrue(crc.valueOf(valueEnv()).isNull()); } @@ -462,7 +462,7 @@ public void crc32_null_value() { */ @Test public void crc32_missing_value() { - FunctionExpression crc = dsl.crc32(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING)); + FunctionExpression crc = DSL.crc32(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING)); assertEquals(LONG, crc.type()); assertTrue(crc.valueOf(valueEnv()).isMissing()); } @@ -472,7 +472,7 @@ public void crc32_missing_value() { */ @Test public void test_e() { - FunctionExpression e = dsl.euler(); + FunctionExpression e = DSL.euler(); assertThat(e.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.E))); } @@ -482,7 +482,7 @@ public void test_e() { @ParameterizedTest(name = "exp({0})") @ValueSource(ints = {-2, 2}) public void exp_int_value(Integer value) { - FunctionExpression exp = dsl.exp(DSL.literal(value)); + FunctionExpression exp = DSL.exp(DSL.literal(value)); assertThat( exp.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.exp(value)))); @@ -495,7 +495,7 @@ public void exp_int_value(Integer value) { @ParameterizedTest(name = "exp({0})") @ValueSource(longs = {-2L, 2L}) public void exp_long_value(Long value) { - FunctionExpression exp = dsl.exp(DSL.literal(value)); + FunctionExpression exp = DSL.exp(DSL.literal(value)); assertThat( exp.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.exp(value)))); @@ -508,7 +508,7 @@ public void exp_long_value(Long value) { @ParameterizedTest(name = "exp({0})") @ValueSource(floats = {-2F, 2F}) public void exp_float_value(Float value) { - FunctionExpression exp = dsl.exp(DSL.literal(value)); + FunctionExpression exp = DSL.exp(DSL.literal(value)); assertThat( exp.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.exp(value)))); @@ -521,7 +521,7 @@ public void exp_float_value(Float value) { @ParameterizedTest(name = "exp({0})") @ValueSource(doubles = {-2D, 2D}) public void exp_double_value(Double value) { - FunctionExpression exp = dsl.exp(DSL.literal(value)); + FunctionExpression exp = DSL.exp(DSL.literal(value)); assertThat( exp.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.exp(value)))); @@ -533,7 +533,7 @@ public void exp_double_value(Double value) { */ @Test public void exp_null_value() { - FunctionExpression exp = dsl.exp(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression exp = DSL.exp(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, exp.type()); assertTrue(exp.valueOf(valueEnv()).isNull()); } @@ -543,7 +543,7 @@ public void exp_null_value() { */ @Test public void exp_missing_value() { - FunctionExpression exp = dsl.exp(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression exp = DSL.exp(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, exp.type()); assertTrue(exp.valueOf(valueEnv()).isMissing()); } @@ -554,7 +554,7 @@ public void exp_missing_value() { @ParameterizedTest(name = "floor({0})") @ValueSource(ints = {-2, 2}) public void floor_int_value(Integer value) { - FunctionExpression floor = dsl.floor(DSL.literal(value)); + FunctionExpression floor = DSL.floor(DSL.literal(value)); assertThat( floor.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.floor(value)))); @@ -567,7 +567,7 @@ public void floor_int_value(Integer value) { @ParameterizedTest(name = "floor({0})") @ValueSource(longs = {-2L, 2L}) public void floor_long_value(Long value) { - FunctionExpression floor = dsl.floor(DSL.literal(value)); + FunctionExpression floor = DSL.floor(DSL.literal(value)); assertThat( floor.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.floor(value)))); @@ -580,7 +580,7 @@ public void floor_long_value(Long value) { @ParameterizedTest(name = "floor({0})") @ValueSource(floats = {-2F, 2F}) public void floor_float_value(Float value) { - FunctionExpression floor = dsl.floor(DSL.literal(value)); + FunctionExpression floor = DSL.floor(DSL.literal(value)); assertThat( floor.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.floor(value)))); @@ -593,7 +593,7 @@ public void floor_float_value(Float value) { @ParameterizedTest(name = "floor({0})") @ValueSource(doubles = {-2D, 2D}) public void floor_double_value(Double value) { - FunctionExpression floor = dsl.floor(DSL.literal(value)); + FunctionExpression floor = DSL.floor(DSL.literal(value)); assertThat( floor.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.floor(value)))); @@ -605,7 +605,7 @@ public void floor_double_value(Double value) { */ @Test public void floor_null_value() { - FunctionExpression floor = dsl.floor(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression floor = DSL.floor(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(INTEGER, floor.type()); assertTrue(floor.valueOf(valueEnv()).isNull()); } @@ -615,7 +615,7 @@ public void floor_null_value() { */ @Test public void floor_missing_value() { - FunctionExpression floor = dsl.floor(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression floor = DSL.floor(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(INTEGER, floor.type()); assertTrue(floor.valueOf(valueEnv()).isMissing()); } @@ -626,7 +626,7 @@ public void floor_missing_value() { @ParameterizedTest(name = "ln({0})") @ValueSource(ints = {2, -2}) public void ln_int_value(Integer value) { - FunctionExpression ln = dsl.ln(DSL.literal(value)); + FunctionExpression ln = DSL.ln(DSL.literal(value)); assertThat( ln.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.log(value)))); @@ -639,7 +639,7 @@ public void ln_int_value(Integer value) { @ParameterizedTest(name = "ln({0})") @ValueSource(longs = {2L, -2L}) public void ln_long_value(Long value) { - FunctionExpression ln = dsl.ln(DSL.literal(value)); + FunctionExpression ln = DSL.ln(DSL.literal(value)); assertThat( ln.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.log(value)))); @@ -652,7 +652,7 @@ public void ln_long_value(Long value) { @ParameterizedTest(name = "ln({0})") @ValueSource(floats = {2F, -2F}) public void ln_float_value(Float value) { - FunctionExpression ln = dsl.ln(DSL.literal(value)); + FunctionExpression ln = DSL.ln(DSL.literal(value)); assertThat( ln.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.log(value)))); @@ -665,7 +665,7 @@ public void ln_float_value(Float value) { @ParameterizedTest(name = "ln({0})") @ValueSource(doubles = {2D, -2D}) public void ln_double_value(Double value) { - FunctionExpression ln = dsl.ln(DSL.literal(value)); + FunctionExpression ln = DSL.ln(DSL.literal(value)); assertThat( ln.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.log(value)))); @@ -677,7 +677,7 @@ public void ln_double_value(Double value) { */ @Test public void ln_null_value() { - FunctionExpression ln = dsl.ln(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression ln = DSL.ln(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, ln.type()); assertTrue(ln.valueOf(valueEnv()).isNull()); } @@ -687,7 +687,7 @@ public void ln_null_value() { */ @Test public void ln_missing_value() { - FunctionExpression ln = dsl.ln(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression ln = DSL.ln(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, ln.type()); assertTrue(ln.valueOf(valueEnv()).isMissing()); } @@ -698,7 +698,7 @@ public void ln_missing_value() { @ParameterizedTest(name = "log({0})") @ValueSource(ints = {2, 3}) public void log_int_value(Integer v) { - FunctionExpression log = dsl.log(DSL.literal(v)); + FunctionExpression log = DSL.log(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -713,7 +713,7 @@ public void log_int_value(Integer v) { @ParameterizedTest(name = "log({0})") @ValueSource(longs = {2L, 3L}) public void log_int_value(Long v) { - FunctionExpression log = dsl.log(DSL.literal(v)); + FunctionExpression log = DSL.log(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -728,7 +728,7 @@ public void log_int_value(Long v) { @ParameterizedTest(name = "log({0})") @ValueSource(floats = {2F, 3F}) public void log_float_value(Float v) { - FunctionExpression log = dsl.log(DSL.literal(v)); + FunctionExpression log = DSL.log(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -743,7 +743,7 @@ public void log_float_value(Float v) { @ParameterizedTest(name = "log({0})") @ValueSource(doubles = {2D, 3D}) public void log_double_value(Double v) { - FunctionExpression log = dsl.log(DSL.literal(v)); + FunctionExpression log = DSL.log(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -757,7 +757,7 @@ public void log_double_value(Double v) { */ @Test public void log_null_value() { - FunctionExpression log = dsl.log( + FunctionExpression log = DSL.log( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); @@ -768,7 +768,7 @@ public void log_null_value() { */ @Test public void log_missing_value() { - FunctionExpression log = dsl.log( + FunctionExpression log = DSL.log( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); @@ -780,7 +780,7 @@ public void log_missing_value() { @ParameterizedTest(name = "log({0}, {1})") @MethodSource("testLogIntegerArguments") public void log_two_int_value(Integer v1, Integer v2) { - FunctionExpression log = dsl.log(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression log = DSL.log(DSL.literal(v1), DSL.literal(v2)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -794,7 +794,7 @@ public void log_two_int_value(Integer v1, Integer v2) { @ParameterizedTest(name = "log({0}, {1})") @MethodSource("testLogLongArguments") public void log_two_long_value(Long v1, Long v2) { - FunctionExpression log = dsl.log(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression log = DSL.log(DSL.literal(v1), DSL.literal(v2)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -808,7 +808,7 @@ public void log_two_long_value(Long v1, Long v2) { @ParameterizedTest(name = "log({0}, {1})") @MethodSource("testLogFloatArguments") public void log_two_double_value(Float v1, Float v2) { - FunctionExpression log = dsl.log(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression log = DSL.log(DSL.literal(v1), DSL.literal(v2)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -822,7 +822,7 @@ public void log_two_double_value(Float v1, Float v2) { @ParameterizedTest(name = "log({0}, {1})") @MethodSource("testLogDoubleArguments") public void log_two_double_value(Double v1, Double v2) { - FunctionExpression log = dsl.log(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression log = DSL.log(DSL.literal(v1), DSL.literal(v2)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -835,16 +835,16 @@ public void log_two_double_value(Double v1, Double v2) { */ @Test public void log_two_null_value() { - FunctionExpression log = dsl.log( + FunctionExpression log = DSL.log( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.literal(2D)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); - log = dsl.log(DSL.literal(2D), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + log = DSL.log(DSL.literal(2D), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); - log = dsl.log( + log = DSL.log( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); @@ -856,16 +856,16 @@ public void log_two_null_value() { */ @Test public void log_two_missing_value() { - FunctionExpression log = dsl.log( + FunctionExpression log = DSL.log( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.literal(2D)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); - log = dsl.log(DSL.literal(2D), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + log = DSL.log(DSL.literal(2D), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); - log = dsl.log( + log = DSL.log( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); @@ -877,13 +877,13 @@ public void log_two_missing_value() { */ @Test public void log_null_missing() { - FunctionExpression log = dsl.log( + FunctionExpression log = DSL.log( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); - log = dsl.log( + log = DSL.log( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); @@ -896,7 +896,7 @@ public void log_null_missing() { @ParameterizedTest(name = "log10({0})") @ValueSource(ints = {2, 3}) public void log10_int_value(Integer v) { - FunctionExpression log = dsl.log10(DSL.literal(v)); + FunctionExpression log = DSL.log10(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -911,7 +911,7 @@ public void log10_int_value(Integer v) { @ParameterizedTest(name = "log10({0})") @ValueSource(longs = {2L, 3L}) public void log10_long_value(Long v) { - FunctionExpression log = dsl.log10(DSL.literal(v)); + FunctionExpression log = DSL.log10(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -926,7 +926,7 @@ public void log10_long_value(Long v) { @ParameterizedTest(name = "log10({0})") @ValueSource(floats = {2F, 3F}) public void log10_float_value(Float v) { - FunctionExpression log = dsl.log10(DSL.literal(v)); + FunctionExpression log = DSL.log10(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -941,7 +941,7 @@ public void log10_float_value(Float v) { @ParameterizedTest(name = "log10({0})") @ValueSource(doubles = {2D, 3D}) public void log10_double_value(Double v) { - FunctionExpression log = dsl.log10(DSL.literal(v)); + FunctionExpression log = DSL.log10(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -955,7 +955,7 @@ public void log10_double_value(Double v) { */ @Test public void log10_null_value() { - FunctionExpression log = dsl.log10( + FunctionExpression log = DSL.log10( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); @@ -966,7 +966,7 @@ public void log10_null_value() { */ @Test public void log10_missing_value() { - FunctionExpression log = dsl.log10( + FunctionExpression log = DSL.log10( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); @@ -978,7 +978,7 @@ public void log10_missing_value() { @ParameterizedTest(name = "log10({0})") @ValueSource(ints = {2, 3}) public void log2_int_value(Integer v) { - FunctionExpression log = dsl.log2(DSL.literal(v)); + FunctionExpression log = DSL.log2(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -993,7 +993,7 @@ public void log2_int_value(Integer v) { @ParameterizedTest(name = "log10({0})") @ValueSource(longs = {2L, 3L}) public void log2_long_value(Long v) { - FunctionExpression log = dsl.log2(DSL.literal(v)); + FunctionExpression log = DSL.log2(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -1008,7 +1008,7 @@ public void log2_long_value(Long v) { @ParameterizedTest(name = "log10({0})") @ValueSource(floats = {2F, 3F}) public void log2_float_value(Float v) { - FunctionExpression log = dsl.log2(DSL.literal(v)); + FunctionExpression log = DSL.log2(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -1023,7 +1023,7 @@ public void log2_float_value(Float v) { @ParameterizedTest(name = "log10({0})") @ValueSource(doubles = {2D, 3D}) public void log2_double_value(Double v) { - FunctionExpression log = dsl.log2(DSL.literal(v)); + FunctionExpression log = DSL.log2(DSL.literal(v)); assertEquals(log.type(), DOUBLE); assertThat( getDoubleValue(log.valueOf(valueEnv())), @@ -1037,7 +1037,7 @@ public void log2_double_value(Double v) { */ @Test public void log2_null_value() { - FunctionExpression log = dsl.log2( + FunctionExpression log = DSL.log2( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); @@ -1048,7 +1048,7 @@ public void log2_null_value() { */ @Test public void log2_missing_value() { - FunctionExpression log = dsl.log2( + FunctionExpression log = DSL.log2( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); @@ -1060,14 +1060,14 @@ public void log2_missing_value() { @ParameterizedTest(name = "mod({0}, {1})") @MethodSource("testLogByteArguments") public void mod_byte_value(Byte v1, Byte v2) { - FunctionExpression mod = dsl.mod(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression mod = DSL.mod(DSL.literal(v1), DSL.literal(v2)); assertThat( mod.valueOf(valueEnv()), allOf(hasType(BYTE), hasValue(Integer.valueOf(v1 % v2).byteValue()))); assertEquals(String.format("mod(%s, %s)", v1, v2), mod.toString()); - mod = dsl.mod(DSL.literal(v1), DSL.literal(new ExprByteValue(0))); + mod = DSL.mod(DSL.literal(v1), DSL.literal(new ExprByteValue(0))); assertEquals(BYTE, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); } @@ -1078,7 +1078,7 @@ public void mod_byte_value(Byte v1, Byte v2) { @ParameterizedTest(name = "mod({0}, {1})") @MethodSource("testLogShortArguments") public void mod_short_value(Short v1, Short v2) { - FunctionExpression mod = dsl.mod(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression mod = DSL.mod(DSL.literal(v1), DSL.literal(v2)); assertThat( mod.valueOf(valueEnv()), @@ -1086,7 +1086,7 @@ public void mod_short_value(Short v1, Short v2) { hasValue(Integer.valueOf(v1 % v2).shortValue()))); assertEquals(String.format("mod(%s, %s)", v1, v2), mod.toString()); - mod = dsl.mod(DSL.literal(v1), DSL.literal(new ExprShortValue(0))); + mod = DSL.mod(DSL.literal(v1), DSL.literal(new ExprShortValue(0))); assertEquals(SHORT, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); } @@ -1097,13 +1097,13 @@ public void mod_short_value(Short v1, Short v2) { @ParameterizedTest(name = "mod({0}, {1})") @MethodSource("testLogIntegerArguments") public void mod_int_value(Integer v1, Integer v2) { - FunctionExpression mod = dsl.mod(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression mod = DSL.mod(DSL.literal(v1), DSL.literal(v2)); assertThat( mod.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue(v1 % v2))); assertEquals(String.format("mod(%s, %s)", v1, v2), mod.toString()); - mod = dsl.mod(DSL.literal(v1), DSL.literal(0)); + mod = DSL.mod(DSL.literal(v1), DSL.literal(0)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); } @@ -1114,13 +1114,13 @@ public void mod_int_value(Integer v1, Integer v2) { @ParameterizedTest(name = "mod({0}, {1})") @MethodSource("testLogLongArguments") public void mod_long_value(Long v1, Long v2) { - FunctionExpression mod = dsl.mod(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression mod = DSL.mod(DSL.literal(v1), DSL.literal(v2)); assertThat( mod.valueOf(valueEnv()), allOf(hasType(LONG), hasValue(v1 % v2))); assertEquals(String.format("mod(%s, %s)", v1, v2), mod.toString()); - mod = dsl.mod(DSL.literal(v1), DSL.literal(0)); + mod = DSL.mod(DSL.literal(v1), DSL.literal(0)); assertEquals(LONG, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); } @@ -1131,13 +1131,13 @@ public void mod_long_value(Long v1, Long v2) { @ParameterizedTest(name = "mod({0}, {1})") @MethodSource("testLogFloatArguments") public void mod_float_value(Float v1, Float v2) { - FunctionExpression mod = dsl.mod(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression mod = DSL.mod(DSL.literal(v1), DSL.literal(v2)); assertThat( mod.valueOf(valueEnv()), allOf(hasType(FLOAT), hasValue(v1 % v2))); assertEquals(String.format("mod(%s, %s)", v1, v2), mod.toString()); - mod = dsl.mod(DSL.literal(v1), DSL.literal(0)); + mod = DSL.mod(DSL.literal(v1), DSL.literal(0)); assertEquals(FLOAT, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); } @@ -1148,13 +1148,13 @@ public void mod_float_value(Float v1, Float v2) { @ParameterizedTest(name = "mod({0}, {1})") @MethodSource("testLogDoubleArguments") public void mod_double_value(Double v1, Double v2) { - FunctionExpression mod = dsl.mod(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression mod = DSL.mod(DSL.literal(v1), DSL.literal(v2)); assertThat( mod.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(v1 % v2))); assertEquals(String.format("mod(%s, %s)", v1, v2), mod.toString()); - mod = dsl.mod(DSL.literal(v1), DSL.literal(0)); + mod = DSL.mod(DSL.literal(v1), DSL.literal(0)); assertEquals(DOUBLE, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); } @@ -1164,15 +1164,15 @@ public void mod_double_value(Double v1, Double v2) { */ @Test public void mod_null_value() { - FunctionExpression mod = dsl.mod(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + FunctionExpression mod = DSL.mod(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); - mod = dsl.mod(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + mod = DSL.mod(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); - mod = dsl.mod( + mod = DSL.mod( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); @@ -1184,15 +1184,15 @@ public void mod_null_value() { @Test public void mod_missing_value() { FunctionExpression mod = - dsl.mod(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + DSL.mod(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); - mod = dsl.mod(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); + mod = DSL.mod(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); - mod = dsl.mod( + mod = DSL.mod( DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); @@ -1204,12 +1204,12 @@ public void mod_missing_value() { */ @Test public void mod_null_missing() { - FunctionExpression mod = dsl.mod(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + FunctionExpression mod = DSL.mod(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); - mod = dsl.mod(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + mod = DSL.mod(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); @@ -1221,14 +1221,14 @@ public void mod_null_missing() { @ParameterizedTest(name = "pow({0}, {1}") @MethodSource("testLogShortArguments") public void pow_short_value(Short v1, Short v2) { - FunctionExpression pow = dsl.pow(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression pow = DSL.pow(DSL.literal(v1), DSL.literal(v2)); assertThat( pow.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); assertEquals(String.format("pow(%s, %s)", v1, v2), pow.toString()); FunctionExpression power = - dsl.power(DSL.literal(v1), DSL.literal(v2)); + DSL.power(DSL.literal(v1), DSL.literal(v2)); assertThat( power.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); @@ -1241,13 +1241,13 @@ public void pow_short_value(Short v1, Short v2) { @ParameterizedTest(name = "pow({0}, {1}") @MethodSource("testLogIntegerArguments") public void pow_int_value(Integer v1, Integer v2) { - FunctionExpression pow = dsl.pow(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression pow = DSL.pow(DSL.literal(v1), DSL.literal(v2)); assertThat( pow.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); assertEquals(String.format("pow(%s, %s)", v1, v2), pow.toString()); - FunctionExpression power = dsl.power(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression power = DSL.power(DSL.literal(v1), DSL.literal(v2)); assertThat( power.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); @@ -1260,13 +1260,13 @@ public void pow_int_value(Integer v1, Integer v2) { @ParameterizedTest(name = "pow({0}, {1}") @MethodSource("testLogLongArguments") public void pow_long_value(Long v1, Long v2) { - FunctionExpression pow = dsl.pow(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression pow = DSL.pow(DSL.literal(v1), DSL.literal(v2)); assertThat( pow.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); assertEquals(String.format("pow(%s, %s)", v1, v2), pow.toString()); - FunctionExpression power = dsl.power(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression power = DSL.power(DSL.literal(v1), DSL.literal(v2)); assertThat( power.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); @@ -1279,13 +1279,13 @@ public void pow_long_value(Long v1, Long v2) { @ParameterizedTest(name = "pow({0}, {1}") @MethodSource("testLogFloatArguments") public void pow_float_value(Float v1, Float v2) { - FunctionExpression pow = dsl.pow(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression pow = DSL.pow(DSL.literal(v1), DSL.literal(v2)); assertThat( pow.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); assertEquals(String.format("pow(%s, %s)", v1, v2), pow.toString()); - FunctionExpression power = dsl.power(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression power = DSL.power(DSL.literal(v1), DSL.literal(v2)); assertThat( power.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); @@ -1298,13 +1298,13 @@ public void pow_float_value(Float v1, Float v2) { @ParameterizedTest(name = "pow({0}, {1}") @MethodSource("testLogDoubleArguments") public void pow_double_value(Double v1, Double v2) { - FunctionExpression pow = dsl.pow(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression pow = DSL.pow(DSL.literal(v1), DSL.literal(v2)); assertThat( pow.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); assertEquals(String.format("pow(%s, %s)", v1, v2), pow.toString()); - FunctionExpression power = dsl.power(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression power = DSL.power(DSL.literal(v1), DSL.literal(v2)); assertThat( power.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.pow(v1, v2)))); @@ -1316,29 +1316,29 @@ public void pow_double_value(Double v1, Double v2) { */ @Test public void pow_null_value() { - FunctionExpression pow = dsl.pow(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + FunctionExpression pow = DSL.pow(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(DOUBLE, pow.type()); assertTrue(pow.valueOf(valueEnv()).isNull()); - dsl.pow(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + DSL.pow(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, pow.type()); assertTrue(pow.valueOf(valueEnv()).isNull()); - dsl.pow( + DSL.pow( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, pow.type()); assertTrue(pow.valueOf(valueEnv()).isNull()); FunctionExpression power = - dsl.power(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + DSL.power(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(DOUBLE, power.type()); assertTrue(power.valueOf(valueEnv()).isNull()); - power = dsl.power(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + power = DSL.power(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, power.type()); assertTrue(power.valueOf(valueEnv()).isNull()); - power = dsl.power( + power = DSL.power( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, power.type()); assertTrue(power.valueOf(valueEnv()).isNull()); @@ -1350,29 +1350,29 @@ public void pow_null_value() { @Test public void pow_missing_value() { FunctionExpression pow = - dsl.pow(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + DSL.pow(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(DOUBLE, pow.type()); assertTrue(pow.valueOf(valueEnv()).isMissing()); - dsl.pow(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); + DSL.pow(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, pow.type()); assertTrue(pow.valueOf(valueEnv()).isMissing()); - dsl.pow(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + DSL.pow(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, pow.type()); assertTrue(pow.valueOf(valueEnv()).isMissing()); FunctionExpression power = - dsl.power(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + DSL.power(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(DOUBLE, power.type()); assertTrue(power.valueOf(valueEnv()).isMissing()); - power = dsl.power(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); + power = DSL.power(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, power.type()); assertTrue(power.valueOf(valueEnv()).isMissing()); - power = dsl.power(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + power = DSL.power(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, power.type()); assertTrue(power.valueOf(valueEnv()).isMissing()); @@ -1383,25 +1383,25 @@ public void pow_missing_value() { */ @Test public void pow_null_missing() { - FunctionExpression pow = dsl.pow( + FunctionExpression pow = DSL.pow( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, pow.type()); assertTrue(pow.valueOf(valueEnv()).isMissing()); - pow = dsl.pow( + pow = DSL.pow( DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, pow.type()); assertTrue(pow.valueOf(valueEnv()).isMissing()); - FunctionExpression power = dsl.power( + FunctionExpression power = DSL.power( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, power.type()); assertTrue(power.valueOf(valueEnv()).isMissing()); - power = dsl.power( + power = DSL.power( DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, power.type()); @@ -1414,20 +1414,20 @@ public void pow_null_missing() { @ParameterizedTest(name = "round({0}") @ValueSource(ints = {21, -21}) public void round_int_value(Integer value) { - FunctionExpression round = dsl.round(DSL.literal(value)); + FunctionExpression round = DSL.round(DSL.literal(value)); assertThat( round.valueOf(valueEnv()), allOf(hasType(LONG), hasValue((long) Math.round(value)))); assertEquals(String.format("round(%s)", value), round.toString()); - round = dsl.round(DSL.literal(value), DSL.literal(1)); + round = DSL.round(DSL.literal(value), DSL.literal(1)); assertThat( round.valueOf(valueEnv()), allOf(hasType(LONG), hasValue( new BigDecimal(value).setScale(1, RoundingMode.HALF_UP).longValue()))); assertEquals(String.format("round(%s, 1)", value), round.toString()); - round = dsl.round(DSL.literal(value), DSL.literal(-1)); + round = DSL.round(DSL.literal(value), DSL.literal(-1)); assertThat( round.valueOf(valueEnv()), allOf(hasType(LONG), hasValue( @@ -1441,20 +1441,20 @@ public void round_int_value(Integer value) { @ParameterizedTest(name = "round({0}") @ValueSource(longs = {21L, -21L}) public void round_long_value(Long value) { - FunctionExpression round = dsl.round(DSL.literal(value)); + FunctionExpression round = DSL.round(DSL.literal(value)); assertThat( round.valueOf(valueEnv()), allOf(hasType(LONG), hasValue((long) Math.round(value)))); assertEquals(String.format("round(%s)", value), round.toString()); - round = dsl.round(DSL.literal(value), DSL.literal(1)); + round = DSL.round(DSL.literal(value), DSL.literal(1)); assertThat( round.valueOf(valueEnv()), allOf(hasType(LONG), hasValue( new BigDecimal(value).setScale(1, RoundingMode.HALF_UP).longValue()))); assertEquals(String.format("round(%s, 1)", value), round.toString()); - round = dsl.round(DSL.literal(value), DSL.literal(-1)); + round = DSL.round(DSL.literal(value), DSL.literal(-1)); assertThat( round.valueOf(valueEnv()), allOf(hasType(LONG), hasValue( @@ -1468,20 +1468,20 @@ public void round_long_value(Long value) { @ParameterizedTest(name = "round({0}") @ValueSource(floats = {21F, -21F}) public void round_float_value(Float value) { - FunctionExpression round = dsl.round(DSL.literal(value)); + FunctionExpression round = DSL.round(DSL.literal(value)); assertThat( round.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue((double) Math.round(value)))); assertEquals(String.format("round(%s)", value), round.toString()); - round = dsl.round(DSL.literal(value), DSL.literal(1)); + round = DSL.round(DSL.literal(value), DSL.literal(1)); assertThat( round.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue( new BigDecimal(value).setScale(1, RoundingMode.HALF_UP).doubleValue()))); assertEquals(String.format("round(%s, 1)", value), round.toString()); - round = dsl.round(DSL.literal(value), DSL.literal(-1)); + round = DSL.round(DSL.literal(value), DSL.literal(-1)); assertThat( round.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue( @@ -1495,20 +1495,20 @@ public void round_float_value(Float value) { @ParameterizedTest(name = "round({0}") @ValueSource(doubles = {21D, -21D}) public void round_double_value(Double value) { - FunctionExpression round = dsl.round(DSL.literal(value)); + FunctionExpression round = DSL.round(DSL.literal(value)); assertThat( round.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue((double) Math.round(value)))); assertEquals(String.format("round(%s)", value), round.toString()); - round = dsl.round(DSL.literal(value), DSL.literal(1)); + round = DSL.round(DSL.literal(value), DSL.literal(1)); assertThat( round.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue( new BigDecimal(value).setScale(1, RoundingMode.HALF_UP).doubleValue()))); assertEquals(String.format("round(%s, 1)", value), round.toString()); - round = dsl.round(DSL.literal(value), DSL.literal(-1)); + round = DSL.round(DSL.literal(value), DSL.literal(-1)); assertThat( round.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue( @@ -1521,15 +1521,15 @@ public void round_double_value(Double value) { */ @Test public void round_null_value() { - FunctionExpression round = dsl.round(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + FunctionExpression round = DSL.round(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isNull()); - round = dsl.round(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + round = DSL.round(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isNull()); - round = dsl.round(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + round = DSL.round(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isNull()); } @@ -1539,15 +1539,15 @@ public void round_null_value() { */ @Test public void round_missing_value() { - FunctionExpression round = dsl.round(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); + FunctionExpression round = DSL.round(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); - round = dsl.round(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + round = DSL.round(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); - round = dsl.round(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); + round = DSL.round(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); } @@ -1557,13 +1557,13 @@ public void round_missing_value() { */ @Test public void round_null_missing() { - FunctionExpression round = dsl.round( + FunctionExpression round = DSL.round( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); - round = dsl.round( + round = DSL.round( DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); @@ -1576,7 +1576,7 @@ public void round_null_missing() { @ParameterizedTest(name = "sign({0})") @ValueSource(ints = {2, -2}) public void sign_int_value(Integer value) { - FunctionExpression sign = dsl.sign(DSL.literal(value)); + FunctionExpression sign = DSL.sign(DSL.literal(value)); assertThat( sign.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.signum(value)))); @@ -1589,7 +1589,7 @@ public void sign_int_value(Integer value) { @ParameterizedTest(name = "sign({0})") @ValueSource(longs = {2L, -2L}) public void sign_long_value(Long value) { - FunctionExpression sign = dsl.sign(DSL.literal(value)); + FunctionExpression sign = DSL.sign(DSL.literal(value)); assertThat( sign.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.signum(value)))); @@ -1602,7 +1602,7 @@ public void sign_long_value(Long value) { @ParameterizedTest(name = "sign({0})") @ValueSource(floats = {2F, -2F}) public void sign_float_value(Float value) { - FunctionExpression sign = dsl.sign(DSL.literal(value)); + FunctionExpression sign = DSL.sign(DSL.literal(value)); assertThat( sign.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.signum(value)))); @@ -1615,7 +1615,7 @@ public void sign_float_value(Float value) { @ParameterizedTest(name = "sign({0})") @ValueSource(doubles = {2, -2}) public void sign_double_value(Double value) { - FunctionExpression sign = dsl.sign(DSL.literal(value)); + FunctionExpression sign = DSL.sign(DSL.literal(value)); assertThat( sign.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.signum(value)))); @@ -1627,7 +1627,7 @@ public void sign_double_value(Double value) { */ @Test public void sign_null_value() { - FunctionExpression sign = dsl.sign(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + FunctionExpression sign = DSL.sign(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, sign.type()); assertTrue(sign.valueOf(valueEnv()).isNull()); } @@ -1637,7 +1637,7 @@ public void sign_null_value() { */ @Test public void sign_missing_value() { - FunctionExpression sign = dsl.sign(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); + FunctionExpression sign = DSL.sign(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, sign.type()); assertTrue(sign.valueOf(valueEnv()).isMissing()); } @@ -1648,7 +1648,7 @@ public void sign_missing_value() { @ParameterizedTest(name = "sqrt({0})") @ValueSource(ints = {1, 2}) public void sqrt_int_value(Integer value) { - FunctionExpression sqrt = dsl.sqrt(DSL.literal(value)); + FunctionExpression sqrt = DSL.sqrt(DSL.literal(value)); assertThat(sqrt.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.sqrt(value)))); assertEquals(String.format("sqrt(%s)", value), sqrt.toString()); } @@ -1659,7 +1659,7 @@ public void sqrt_int_value(Integer value) { @ParameterizedTest(name = "sqrt({0})") @ValueSource(longs = {1L, 2L}) public void sqrt_long_value(Long value) { - FunctionExpression sqrt = dsl.sqrt(DSL.literal(value)); + FunctionExpression sqrt = DSL.sqrt(DSL.literal(value)); assertThat(sqrt.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.sqrt(value)))); assertEquals(String.format("sqrt(%s)", value), sqrt.toString()); } @@ -1670,7 +1670,7 @@ public void sqrt_long_value(Long value) { @ParameterizedTest(name = "sqrt({0})") @ValueSource(floats = {1F, 2F}) public void sqrt_float_value(Float value) { - FunctionExpression sqrt = dsl.sqrt(DSL.literal(value)); + FunctionExpression sqrt = DSL.sqrt(DSL.literal(value)); assertThat(sqrt.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.sqrt(value)))); assertEquals(String.format("sqrt(%s)", value), sqrt.toString()); } @@ -1681,7 +1681,7 @@ public void sqrt_float_value(Float value) { @ParameterizedTest(name = "sqrt({0})") @ValueSource(doubles = {1D, 2D}) public void sqrt_double_value(Double value) { - FunctionExpression sqrt = dsl.sqrt(DSL.literal(value)); + FunctionExpression sqrt = DSL.sqrt(DSL.literal(value)); assertThat(sqrt.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.sqrt(value)))); assertEquals(String.format("sqrt(%s)", value), sqrt.toString()); } @@ -1692,7 +1692,7 @@ public void sqrt_double_value(Double value) { @ParameterizedTest(name = "sqrt({0})") @ValueSource(doubles = {-1D, -2D}) public void sqrt_negative_value(Double value) { - FunctionExpression sqrt = dsl.sqrt(DSL.literal(value)); + FunctionExpression sqrt = DSL.sqrt(DSL.literal(value)); assertEquals(DOUBLE, sqrt.type()); assertTrue(sqrt.valueOf(valueEnv()).isNull()); } @@ -1702,7 +1702,7 @@ public void sqrt_negative_value(Double value) { */ @Test public void sqrt_null_value() { - FunctionExpression sqrt = dsl.sqrt(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + FunctionExpression sqrt = DSL.sqrt(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, sqrt.type()); assertTrue(sqrt.valueOf(valueEnv()).isNull()); } @@ -1712,7 +1712,7 @@ public void sqrt_null_value() { */ @Test public void sqrt_missing_value() { - FunctionExpression sqrt = dsl.sqrt(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); + FunctionExpression sqrt = DSL.sqrt(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, sqrt.type()); assertTrue(sqrt.valueOf(valueEnv()).isMissing()); } @@ -1723,7 +1723,7 @@ public void sqrt_missing_value() { @ParameterizedTest(name = "truncate({0}, {1})") @ValueSource(ints = {2, -2}) public void truncate_int_value(Integer value) { - FunctionExpression truncate = dsl.truncate(DSL.literal(value), DSL.literal(1)); + FunctionExpression truncate = DSL.truncate(DSL.literal(value), DSL.literal(1)); assertThat( truncate.valueOf(valueEnv()), allOf(hasType(LONG), hasValue(new BigDecimal(value).setScale(1, RoundingMode.DOWN).longValue()))); @@ -1736,7 +1736,7 @@ public void truncate_int_value(Integer value) { @ParameterizedTest(name = "truncate({0}, {1})") @ValueSource(longs = {2L, -2L}) public void truncate_long_value(Long value) { - FunctionExpression truncate = dsl.truncate(DSL.literal(value), DSL.literal(1)); + FunctionExpression truncate = DSL.truncate(DSL.literal(value), DSL.literal(1)); assertThat( truncate.valueOf(valueEnv()), allOf(hasType(LONG), hasValue(new BigDecimal(value).setScale(1, RoundingMode.DOWN).longValue()))); @@ -1749,7 +1749,7 @@ public void truncate_long_value(Long value) { @ParameterizedTest(name = "truncate({0}, {1})") @ValueSource(floats = {2F, -2F}) public void truncate_float_value(Float value) { - FunctionExpression truncate = dsl.truncate(DSL.literal(value), DSL.literal(1)); + FunctionExpression truncate = DSL.truncate(DSL.literal(value), DSL.literal(1)); assertThat( truncate.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(new BigDecimal(value).setScale(1, RoundingMode.DOWN).doubleValue()))); @@ -1762,7 +1762,7 @@ public void truncate_float_value(Float value) { @ParameterizedTest(name = "truncate({0}, {1})") @ValueSource(doubles = {2D, -2D}) public void truncate_double_value(Double value) { - FunctionExpression truncate = dsl.truncate(DSL.literal(value), DSL.literal(1)); + FunctionExpression truncate = DSL.truncate(DSL.literal(value), DSL.literal(1)); assertThat( truncate.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(new BigDecimal(value).setScale(1, RoundingMode.DOWN).doubleValue()))); @@ -1775,15 +1775,15 @@ public void truncate_double_value(Double value) { @Test public void truncate_null_value() { FunctionExpression truncate = - dsl.truncate(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + DSL.truncate(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(LONG, truncate.type()); assertTrue(truncate.valueOf(valueEnv()).isNull()); - truncate = dsl.truncate(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + truncate = DSL.truncate(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, truncate.type()); assertTrue(truncate.valueOf(valueEnv()).isNull()); - truncate = dsl.truncate( + truncate = DSL.truncate( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, truncate.type()); assertTrue(truncate.valueOf(valueEnv()).isNull()); @@ -1795,15 +1795,15 @@ public void truncate_null_value() { @Test public void truncate_missing_value() { FunctionExpression truncate = - dsl.truncate(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + DSL.truncate(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(LONG, truncate.type()); assertTrue(truncate.valueOf(valueEnv()).isMissing()); - truncate = dsl.truncate(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); + truncate = DSL.truncate(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, truncate.type()); assertTrue(truncate.valueOf(valueEnv()).isMissing()); - truncate = dsl.truncate( + truncate = DSL.truncate( DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, truncate.type()); @@ -1815,12 +1815,12 @@ public void truncate_missing_value() { */ @Test public void truncate_null_missing() { - FunctionExpression truncate = dsl.truncate(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + FunctionExpression truncate = DSL.truncate(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, truncate.type()); assertTrue(truncate.valueOf(valueEnv()).isMissing()); - truncate = dsl.truncate(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + truncate = DSL.truncate(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, truncate.type()); assertTrue(truncate.valueOf(valueEnv()).isMissing()); @@ -1831,7 +1831,7 @@ public void truncate_null_missing() { */ @Test public void test_pi() { - FunctionExpression pi = dsl.pi(); + FunctionExpression pi = DSL.pi(); assertThat(pi.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.PI))); } @@ -1840,7 +1840,7 @@ public void test_pi() { */ @Test public void rand_no_arg() { - FunctionExpression rand = dsl.rand(); + FunctionExpression rand = DSL.rand(); assertEquals(FLOAT, rand.type()); assertTrue( getFloatValue(rand.valueOf(valueEnv())) >= 0 @@ -1854,7 +1854,7 @@ public void rand_no_arg() { @ParameterizedTest(name = "rand({0})") @ValueSource(ints = {2, 3}) public void rand_int_value(Integer n) { - FunctionExpression rand = dsl.rand(DSL.literal(n)); + FunctionExpression rand = DSL.rand(DSL.literal(n)); assertEquals(FLOAT, rand.type()); assertTrue( getFloatValue(rand.valueOf(valueEnv())) >= 0 @@ -1865,7 +1865,7 @@ public void rand_int_value(Integer n) { @Test public void rand_null_value() { - FunctionExpression rand = dsl.rand(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); + FunctionExpression rand = DSL.rand(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(FLOAT, rand.type()); assertTrue(rand.valueOf(valueEnv()).isNull()); } @@ -1876,7 +1876,7 @@ public void rand_null_value() { @ParameterizedTest(name = "acos({0})") @MethodSource("trigonometricArguments") public void test_acos(Number value) { - FunctionExpression acos = dsl.acos(DSL.literal(value)); + FunctionExpression acos = DSL.acos(DSL.literal(value)); assertThat( acos.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.acos(value.doubleValue())))); @@ -1889,7 +1889,7 @@ public void test_acos(Number value) { @ParameterizedTest(name = "acos({0})") @ValueSource(doubles = {2D, -2D}) public void acos_with_illegal_value(Number value) { - FunctionExpression acos = dsl.acos(DSL.literal(value)); + FunctionExpression acos = DSL.acos(DSL.literal(value)); assertEquals(DOUBLE, acos.type()); assertTrue(acos.valueOf(valueEnv()).isNull()); } @@ -1899,7 +1899,7 @@ public void acos_with_illegal_value(Number value) { */ @Test public void acos_null_value() { - FunctionExpression acos = dsl.acos(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression acos = DSL.acos(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, acos.type()); assertTrue(acos.valueOf(valueEnv()).isNull()); } @@ -1909,7 +1909,7 @@ public void acos_null_value() { */ @Test public void acos_missing_value() { - FunctionExpression acos = dsl.acos(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression acos = DSL.acos(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, acos.type()); assertTrue(acos.valueOf(valueEnv()).isMissing()); } @@ -1920,7 +1920,7 @@ public void acos_missing_value() { @ParameterizedTest(name = "asin({0})") @MethodSource("trigonometricArguments") public void test_asin(Number value) { - FunctionExpression asin = dsl.asin(DSL.literal(value)); + FunctionExpression asin = DSL.asin(DSL.literal(value)); assertThat( asin.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.asin(value.doubleValue())))); @@ -1933,7 +1933,7 @@ public void test_asin(Number value) { @ParameterizedTest(name = "asin({0})") @ValueSource(doubles = {2D, -2D}) public void asin_with_illegal_value(Number value) { - FunctionExpression asin = dsl.asin(DSL.literal(value)); + FunctionExpression asin = DSL.asin(DSL.literal(value)); assertEquals(DOUBLE, asin.type()); assertTrue(asin.valueOf(valueEnv()).isNull()); } @@ -1943,7 +1943,7 @@ public void asin_with_illegal_value(Number value) { */ @Test public void asin_null_value() { - FunctionExpression asin = dsl.asin(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression asin = DSL.asin(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, asin.type()); assertTrue(asin.valueOf(valueEnv()).isNull()); } @@ -1953,7 +1953,7 @@ public void asin_null_value() { */ @Test public void asin_missing_value() { - FunctionExpression asin = dsl.asin(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression asin = DSL.asin(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, asin.type()); assertTrue(asin.valueOf(valueEnv()).isMissing()); } @@ -1964,7 +1964,7 @@ public void asin_missing_value() { @ParameterizedTest(name = "atan({0})") @MethodSource("trigonometricArguments") public void atan_one_arg(Number value) { - FunctionExpression atan = dsl.atan(DSL.literal(value)); + FunctionExpression atan = DSL.atan(DSL.literal(value)); assertThat( atan.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.atan(value.doubleValue())))); @@ -1978,7 +1978,7 @@ public void atan_one_arg(Number value) { @MethodSource("trigonometricDoubleArguments") public void atan_two_args(Number v1, Number v2) { FunctionExpression atan = - dsl.atan(DSL.literal(v1), DSL.literal(v2)); + DSL.atan(DSL.literal(v1), DSL.literal(v2)); assertThat( atan.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.atan2(v1.doubleValue(), v2.doubleValue())))); @@ -1990,19 +1990,19 @@ public void atan_two_args(Number v1, Number v2) { */ @Test public void atan_null_value() { - FunctionExpression atan = dsl.atan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression atan = DSL.atan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isNull()); - atan = dsl.atan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.literal(1)); + atan = DSL.atan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.literal(1)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isNull()); - atan = dsl.atan(DSL.literal(1), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + atan = DSL.atan(DSL.literal(1), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isNull()); - atan = dsl.atan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), + atan = DSL.atan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isNull()); @@ -2013,19 +2013,19 @@ public void atan_null_value() { */ @Test public void atan_missing_value() { - FunctionExpression atan = dsl.atan(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression atan = DSL.atan(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isMissing()); - atan = dsl.atan(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.literal(1)); + atan = DSL.atan(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.literal(1)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isMissing()); - atan = dsl.atan(DSL.literal(1), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + atan = DSL.atan(DSL.literal(1), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isMissing()); - atan = dsl.atan(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), + atan = DSL.atan(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isMissing()); @@ -2036,13 +2036,13 @@ public void atan_missing_value() { */ @Test public void atan_null_missing() { - FunctionExpression atan = dsl.atan( + FunctionExpression atan = DSL.atan( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isMissing()); - atan = dsl.atan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), + atan = DSL.atan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan.type()); assertTrue(atan.valueOf(valueEnv()).isMissing()); @@ -2054,7 +2054,7 @@ public void atan_null_missing() { @ParameterizedTest(name = "atan2({0}, {1})") @MethodSource("trigonometricDoubleArguments") public void test_atan2(Number v1, Number v2) { - FunctionExpression atan2 = dsl.atan2(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression atan2 = DSL.atan2(DSL.literal(v1), DSL.literal(v2)); assertThat( atan2.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.atan2(v1.doubleValue(), v2.doubleValue())))); @@ -2066,16 +2066,16 @@ public void test_atan2(Number v1, Number v2) { */ @Test public void atan2_null_value() { - FunctionExpression atan2 = dsl.atan2( + FunctionExpression atan2 = DSL.atan2( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.literal(1)); assertEquals(DOUBLE, atan2.type()); assertTrue(atan2.valueOf(valueEnv()).isNull()); - atan2 = dsl.atan2(DSL.literal(1), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + atan2 = DSL.atan2(DSL.literal(1), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan2.type()); assertTrue(atan2.valueOf(valueEnv()).isNull()); - atan2 = dsl.atan2(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), + atan2 = DSL.atan2(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan2.type()); assertTrue(atan2.valueOf(valueEnv()).isNull()); @@ -2086,16 +2086,16 @@ public void atan2_null_value() { */ @Test public void atan2_missing_value() { - FunctionExpression atan2 = dsl.atan2( + FunctionExpression atan2 = DSL.atan2( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.literal(1)); assertEquals(DOUBLE, atan2.type()); assertTrue(atan2.valueOf(valueEnv()).isMissing()); - atan2 = dsl.atan2(DSL.literal(1), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + atan2 = DSL.atan2(DSL.literal(1), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan2.type()); assertTrue(atan2.valueOf(valueEnv()).isMissing()); - atan2 = dsl.atan2(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), + atan2 = DSL.atan2(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan2.type()); assertTrue(atan2.valueOf(valueEnv()).isMissing()); @@ -2106,13 +2106,13 @@ public void atan2_missing_value() { */ @Test public void atan2_null_missing() { - FunctionExpression atan2 = dsl.atan2( + FunctionExpression atan2 = DSL.atan2( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan2.type()); assertTrue(atan2.valueOf(valueEnv()).isMissing()); - atan2 = dsl.atan2(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), + atan2 = DSL.atan2(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, atan2.type()); assertTrue(atan2.valueOf(valueEnv()).isMissing()); @@ -2124,7 +2124,7 @@ public void atan2_null_missing() { @ParameterizedTest(name = "cos({0})") @MethodSource("trigonometricArguments") public void test_cos(Number value) { - FunctionExpression cos = dsl.cos(DSL.literal(value)); + FunctionExpression cos = DSL.cos(DSL.literal(value)); assertThat( cos.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.cos(value.doubleValue())))); @@ -2136,7 +2136,7 @@ public void test_cos(Number value) { */ @Test public void cos_null_value() { - FunctionExpression cos = dsl.cos(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression cos = DSL.cos(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, cos.type()); assertTrue(cos.valueOf(valueEnv()).isNull()); } @@ -2146,7 +2146,7 @@ public void cos_null_value() { */ @Test public void cos_missing_value() { - FunctionExpression cos = dsl.cos(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression cos = DSL.cos(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, cos.type()); assertTrue(cos.valueOf(valueEnv()).isMissing()); } @@ -2157,7 +2157,7 @@ public void cos_missing_value() { @ParameterizedTest(name = "cot({0})") @MethodSource("trigonometricArguments") public void test_cot(Number value) { - FunctionExpression cot = dsl.cot(DSL.literal(value)); + FunctionExpression cot = DSL.cot(DSL.literal(value)); assertThat( cot.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(1 / Math.tan(value.doubleValue())))); @@ -2170,7 +2170,7 @@ public void test_cot(Number value) { @ParameterizedTest(name = "cot({0})") @ValueSource(doubles = {0}) public void cot_with_zero(Number value) { - FunctionExpression cot = dsl.cot(DSL.literal(value)); + FunctionExpression cot = DSL.cot(DSL.literal(value)); assertThrows( ArithmeticException.class, () -> cot.valueOf(valueEnv()), String.format("Out of range value for cot(%s)", value)); @@ -2181,7 +2181,7 @@ public void cot_with_zero(Number value) { */ @Test public void cot_null_value() { - FunctionExpression cot = dsl.cot(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression cot = DSL.cot(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, cot.type()); assertTrue(cot.valueOf(valueEnv()).isNull()); } @@ -2191,7 +2191,7 @@ public void cot_null_value() { */ @Test public void cot_missing_value() { - FunctionExpression cot = dsl.cot(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression cot = DSL.cot(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, cot.type()); assertTrue(cot.valueOf(valueEnv()).isMissing()); } @@ -2202,7 +2202,7 @@ public void cot_missing_value() { @ParameterizedTest(name = "degrees({0})") @MethodSource("trigonometricArguments") public void test_degrees(Number value) { - FunctionExpression degrees = dsl.degrees(DSL.literal(value)); + FunctionExpression degrees = DSL.degrees(DSL.literal(value)); assertThat( degrees.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.toDegrees(value.doubleValue())))); @@ -2214,7 +2214,7 @@ public void test_degrees(Number value) { */ @Test public void degrees_null_value() { - FunctionExpression degrees = dsl.degrees(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression degrees = DSL.degrees(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, degrees.type()); assertTrue(degrees.valueOf(valueEnv()).isNull()); } @@ -2224,7 +2224,7 @@ public void degrees_null_value() { */ @Test public void degrees_missing_value() { - FunctionExpression degrees = dsl.degrees(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression degrees = DSL.degrees(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, degrees.type()); assertTrue(degrees.valueOf(valueEnv()).isMissing()); } @@ -2235,7 +2235,7 @@ public void degrees_missing_value() { @ParameterizedTest(name = "radians({0})") @MethodSource("trigonometricArguments") public void test_radians(Number value) { - FunctionExpression radians = dsl.radians(DSL.literal(value)); + FunctionExpression radians = DSL.radians(DSL.literal(value)); assertThat( radians.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.toRadians(value.doubleValue())))); @@ -2247,7 +2247,7 @@ public void test_radians(Number value) { */ @Test public void radians_null_value() { - FunctionExpression radians = dsl.radians(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression radians = DSL.radians(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, radians.type()); assertTrue(radians.valueOf(valueEnv()).isNull()); } @@ -2257,7 +2257,7 @@ public void radians_null_value() { */ @Test public void radians_missing_value() { - FunctionExpression radians = dsl.radians(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression radians = DSL.radians(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, radians.type()); assertTrue(radians.valueOf(valueEnv()).isMissing()); } @@ -2268,7 +2268,7 @@ public void radians_missing_value() { @ParameterizedTest(name = "sin({0})") @MethodSource("trigonometricArguments") public void test_sin(Number value) { - FunctionExpression sin = dsl.sin(DSL.literal(value)); + FunctionExpression sin = DSL.sin(DSL.literal(value)); assertThat( sin.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.sin(value.doubleValue())))); @@ -2280,7 +2280,7 @@ public void test_sin(Number value) { */ @Test public void sin_null_value() { - FunctionExpression sin = dsl.sin(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression sin = DSL.sin(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, sin.type()); assertTrue(sin.valueOf(valueEnv()).isNull()); } @@ -2290,7 +2290,7 @@ public void sin_null_value() { */ @Test public void sin_missing_value() { - FunctionExpression sin = dsl.sin(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression sin = DSL.sin(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, sin.type()); assertTrue(sin.valueOf(valueEnv()).isMissing()); } @@ -2301,7 +2301,7 @@ public void sin_missing_value() { @ParameterizedTest(name = "tan({0})") @MethodSource("trigonometricArguments") public void test_tan(Number value) { - FunctionExpression tan = dsl.tan(DSL.literal(value)); + FunctionExpression tan = DSL.tan(DSL.literal(value)); assertThat( tan.valueOf(valueEnv()), allOf(hasType(DOUBLE), hasValue(Math.tan(value.doubleValue())))); @@ -2313,7 +2313,7 @@ public void test_tan(Number value) { */ @Test public void tan_null_value() { - FunctionExpression tan = dsl.tan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); + FunctionExpression tan = DSL.tan(DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, tan.type()); assertTrue(tan.valueOf(valueEnv()).isNull()); } @@ -2323,7 +2323,7 @@ public void tan_null_value() { */ @Test public void tan_missing_value() { - FunctionExpression tan = dsl.tan(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); + FunctionExpression tan = DSL.tan(DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, tan.type()); assertTrue(tan.valueOf(valueEnv()).isMissing()); } diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java index 1f3748709e..742313922a 100644 --- a/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java @@ -40,12 +40,9 @@ import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.FunctionExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; class TypeCastOperatorTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - private static Stream numberData() { return Stream.of(new ExprByteValue(3), new ExprShortValue(3), new ExprIntegerValue(3), new ExprLongValue(3L), new ExprFloatValue(3.14f), @@ -79,7 +76,7 @@ private static Stream datetime() { @ParameterizedTest(name = "castString({0})") @MethodSource({"numberData", "stringData", "boolData", "date", "time", "timestamp", "datetime"}) void castToString(ExprValue value) { - FunctionExpression expression = dsl.castString(DSL.literal(value)); + FunctionExpression expression = DSL.castString(DSL.literal(value)); assertEquals(STRING, expression.type()); assertEquals(new ExprStringValue(value.value().toString()), expression.valueOf()); } @@ -87,7 +84,7 @@ void castToString(ExprValue value) { @ParameterizedTest(name = "castToByte({0})") @MethodSource({"numberData"}) void castToByte(ExprValue value) { - FunctionExpression expression = dsl.castByte(DSL.literal(value)); + FunctionExpression expression = DSL.castByte(DSL.literal(value)); assertEquals(BYTE, expression.type()); assertEquals(new ExprByteValue(value.byteValue()), expression.valueOf()); } @@ -95,7 +92,7 @@ void castToByte(ExprValue value) { @ParameterizedTest(name = "castToShort({0})") @MethodSource({"numberData"}) void castToShort(ExprValue value) { - FunctionExpression expression = dsl.castShort(DSL.literal(value)); + FunctionExpression expression = DSL.castShort(DSL.literal(value)); assertEquals(SHORT, expression.type()); assertEquals(new ExprShortValue(value.shortValue()), expression.valueOf()); } @@ -103,67 +100,67 @@ void castToShort(ExprValue value) { @ParameterizedTest(name = "castToInt({0})") @MethodSource({"numberData"}) void castToInt(ExprValue value) { - FunctionExpression expression = dsl.castInt(DSL.literal(value)); + FunctionExpression expression = DSL.castInt(DSL.literal(value)); assertEquals(INTEGER, expression.type()); assertEquals(new ExprIntegerValue(value.integerValue()), expression.valueOf()); } @Test void castStringToByte() { - FunctionExpression expression = dsl.castByte(DSL.literal("100")); + FunctionExpression expression = DSL.castByte(DSL.literal("100")); assertEquals(BYTE, expression.type()); assertEquals(new ExprByteValue(100), expression.valueOf()); } @Test void castStringToShort() { - FunctionExpression expression = dsl.castShort(DSL.literal("100")); + FunctionExpression expression = DSL.castShort(DSL.literal("100")); assertEquals(SHORT, expression.type()); assertEquals(new ExprShortValue(100), expression.valueOf()); } @Test void castStringToInt() { - FunctionExpression expression = dsl.castInt(DSL.literal("100")); + FunctionExpression expression = DSL.castInt(DSL.literal("100")); assertEquals(INTEGER, expression.type()); assertEquals(new ExprIntegerValue(100), expression.valueOf()); } @Test void castStringToIntException() { - FunctionExpression expression = dsl.castInt(DSL.literal("invalid")); + FunctionExpression expression = DSL.castInt(DSL.literal("invalid")); assertThrows(RuntimeException.class, () -> expression.valueOf()); } @Test void castBooleanToByte() { - FunctionExpression expression = dsl.castByte(DSL.literal(true)); + FunctionExpression expression = DSL.castByte(DSL.literal(true)); assertEquals(BYTE, expression.type()); assertEquals(new ExprByteValue(1), expression.valueOf()); - expression = dsl.castByte(DSL.literal(false)); + expression = DSL.castByte(DSL.literal(false)); assertEquals(BYTE, expression.type()); assertEquals(new ExprByteValue(0), expression.valueOf()); } @Test void castBooleanToShort() { - FunctionExpression expression = dsl.castShort(DSL.literal(true)); + FunctionExpression expression = DSL.castShort(DSL.literal(true)); assertEquals(SHORT, expression.type()); assertEquals(new ExprShortValue(1), expression.valueOf()); - expression = dsl.castShort(DSL.literal(false)); + expression = DSL.castShort(DSL.literal(false)); assertEquals(SHORT, expression.type()); assertEquals(new ExprShortValue(0), expression.valueOf()); } @Test void castBooleanToInt() { - FunctionExpression expression = dsl.castInt(DSL.literal(true)); + FunctionExpression expression = DSL.castInt(DSL.literal(true)); assertEquals(INTEGER, expression.type()); assertEquals(new ExprIntegerValue(1), expression.valueOf()); - expression = dsl.castInt(DSL.literal(false)); + expression = DSL.castInt(DSL.literal(false)); assertEquals(INTEGER, expression.type()); assertEquals(new ExprIntegerValue(0), expression.valueOf()); } @@ -171,31 +168,31 @@ void castBooleanToInt() { @ParameterizedTest(name = "castToLong({0})") @MethodSource({"numberData"}) void castToLong(ExprValue value) { - FunctionExpression expression = dsl.castLong(DSL.literal(value)); + FunctionExpression expression = DSL.castLong(DSL.literal(value)); assertEquals(LONG, expression.type()); assertEquals(new ExprLongValue(value.longValue()), expression.valueOf()); } @Test void castStringToLong() { - FunctionExpression expression = dsl.castLong(DSL.literal("100")); + FunctionExpression expression = DSL.castLong(DSL.literal("100")); assertEquals(LONG, expression.type()); assertEquals(new ExprLongValue(100), expression.valueOf()); } @Test void castStringToLongException() { - FunctionExpression expression = dsl.castLong(DSL.literal("invalid")); + FunctionExpression expression = DSL.castLong(DSL.literal("invalid")); assertThrows(RuntimeException.class, () -> expression.valueOf()); } @Test void castBooleanToLong() { - FunctionExpression expression = dsl.castLong(DSL.literal(true)); + FunctionExpression expression = DSL.castLong(DSL.literal(true)); assertEquals(LONG, expression.type()); assertEquals(new ExprLongValue(1), expression.valueOf()); - expression = dsl.castLong(DSL.literal(false)); + expression = DSL.castLong(DSL.literal(false)); assertEquals(LONG, expression.type()); assertEquals(new ExprLongValue(0), expression.valueOf()); } @@ -203,31 +200,31 @@ void castBooleanToLong() { @ParameterizedTest(name = "castToFloat({0})") @MethodSource({"numberData"}) void castToFloat(ExprValue value) { - FunctionExpression expression = dsl.castFloat(DSL.literal(value)); + FunctionExpression expression = DSL.castFloat(DSL.literal(value)); assertEquals(FLOAT, expression.type()); assertEquals(new ExprFloatValue(value.floatValue()), expression.valueOf()); } @Test void castStringToFloat() { - FunctionExpression expression = dsl.castFloat(DSL.literal("100.0")); + FunctionExpression expression = DSL.castFloat(DSL.literal("100.0")); assertEquals(FLOAT, expression.type()); assertEquals(new ExprFloatValue(100.0), expression.valueOf()); } @Test void castStringToFloatException() { - FunctionExpression expression = dsl.castFloat(DSL.literal("invalid")); + FunctionExpression expression = DSL.castFloat(DSL.literal("invalid")); assertThrows(RuntimeException.class, () -> expression.valueOf()); } @Test void castBooleanToFloat() { - FunctionExpression expression = dsl.castFloat(DSL.literal(true)); + FunctionExpression expression = DSL.castFloat(DSL.literal(true)); assertEquals(FLOAT, expression.type()); assertEquals(new ExprFloatValue(1), expression.valueOf()); - expression = dsl.castFloat(DSL.literal(false)); + expression = DSL.castFloat(DSL.literal(false)); assertEquals(FLOAT, expression.type()); assertEquals(new ExprFloatValue(0), expression.valueOf()); } @@ -235,31 +232,31 @@ void castBooleanToFloat() { @ParameterizedTest(name = "castToDouble({0})") @MethodSource({"numberData"}) void castToDouble(ExprValue value) { - FunctionExpression expression = dsl.castDouble(DSL.literal(value)); + FunctionExpression expression = DSL.castDouble(DSL.literal(value)); assertEquals(DOUBLE, expression.type()); assertEquals(new ExprDoubleValue(value.doubleValue()), expression.valueOf()); } @Test void castStringToDouble() { - FunctionExpression expression = dsl.castDouble(DSL.literal("100.0")); + FunctionExpression expression = DSL.castDouble(DSL.literal("100.0")); assertEquals(DOUBLE, expression.type()); assertEquals(new ExprDoubleValue(100), expression.valueOf()); } @Test void castStringToDoubleException() { - FunctionExpression expression = dsl.castDouble(DSL.literal("invalid")); + FunctionExpression expression = DSL.castDouble(DSL.literal("invalid")); assertThrows(RuntimeException.class, () -> expression.valueOf()); } @Test void castBooleanToDouble() { - FunctionExpression expression = dsl.castDouble(DSL.literal(true)); + FunctionExpression expression = DSL.castDouble(DSL.literal(true)); assertEquals(DOUBLE, expression.type()); assertEquals(new ExprDoubleValue(1), expression.valueOf()); - expression = dsl.castDouble(DSL.literal(false)); + expression = DSL.castDouble(DSL.literal(false)); assertEquals(DOUBLE, expression.type()); assertEquals(new ExprDoubleValue(0), expression.valueOf()); } @@ -267,96 +264,96 @@ void castBooleanToDouble() { @ParameterizedTest(name = "castToBoolean({0})") @MethodSource({"numberData"}) void castToBoolean(ExprValue value) { - FunctionExpression expression = dsl.castBoolean(DSL.literal(value)); + FunctionExpression expression = DSL.castBoolean(DSL.literal(value)); assertEquals(BOOLEAN, expression.type()); assertEquals(ExprBooleanValue.of(true), expression.valueOf()); } @Test void castZeroToBoolean() { - FunctionExpression expression = dsl.castBoolean(DSL.literal(0)); + FunctionExpression expression = DSL.castBoolean(DSL.literal(0)); assertEquals(BOOLEAN, expression.type()); assertEquals(ExprBooleanValue.of(false), expression.valueOf()); } @Test void castStringToBoolean() { - FunctionExpression expression = dsl.castBoolean(DSL.literal("True")); + FunctionExpression expression = DSL.castBoolean(DSL.literal("True")); assertEquals(BOOLEAN, expression.type()); assertEquals(ExprBooleanValue.of(true), expression.valueOf()); } @Test void castBooleanToBoolean() { - FunctionExpression expression = dsl.castBoolean(DSL.literal(true)); + FunctionExpression expression = DSL.castBoolean(DSL.literal(true)); assertEquals(BOOLEAN, expression.type()); assertEquals(ExprBooleanValue.of(true), expression.valueOf()); } @Test void castToDate() { - FunctionExpression expression = dsl.castDate(DSL.literal("2012-08-07")); + FunctionExpression expression = DSL.castDate(DSL.literal("2012-08-07")); assertEquals(DATE, expression.type()); assertEquals(new ExprDateValue("2012-08-07"), expression.valueOf()); - expression = dsl.castDate(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); + expression = DSL.castDate(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); assertEquals(DATE, expression.type()); assertEquals(new ExprDateValue("2012-08-07"), expression.valueOf()); - expression = dsl.castDate(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); + expression = DSL.castDate(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); assertEquals(DATE, expression.type()); assertEquals(new ExprDateValue("2012-08-07"), expression.valueOf()); - expression = dsl.castDate(DSL.literal(new ExprDateValue("2012-08-07"))); + expression = DSL.castDate(DSL.literal(new ExprDateValue("2012-08-07"))); assertEquals(DATE, expression.type()); assertEquals(new ExprDateValue("2012-08-07"), expression.valueOf()); } @Test void castToTime() { - FunctionExpression expression = dsl.castTime(DSL.literal("01:01:01")); + FunctionExpression expression = DSL.castTime(DSL.literal("01:01:01")); assertEquals(TIME, expression.type()); assertEquals(new ExprTimeValue("01:01:01"), expression.valueOf()); - expression = dsl.castTime(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); + expression = DSL.castTime(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); assertEquals(TIME, expression.type()); assertEquals(new ExprTimeValue("01:01:01"), expression.valueOf()); - expression = dsl.castTime(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); + expression = DSL.castTime(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); assertEquals(TIME, expression.type()); assertEquals(new ExprTimeValue("01:01:01"), expression.valueOf()); - expression = dsl.castTime(DSL.literal(new ExprTimeValue("01:01:01"))); + expression = DSL.castTime(DSL.literal(new ExprTimeValue("01:01:01"))); assertEquals(TIME, expression.type()); assertEquals(new ExprTimeValue("01:01:01"), expression.valueOf()); } @Test void castToTimestamp() { - FunctionExpression expression = dsl.castTimestamp(DSL.literal("2012-08-07 01:01:01")); + FunctionExpression expression = DSL.castTimestamp(DSL.literal("2012-08-07 01:01:01")); assertEquals(TIMESTAMP, expression.type()); assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf()); - expression = dsl.castTimestamp(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); + expression = DSL.castTimestamp(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); assertEquals(TIMESTAMP, expression.type()); assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf()); - expression = dsl.castTimestamp(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); + expression = DSL.castTimestamp(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); assertEquals(TIMESTAMP, expression.type()); assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf()); } @Test void castToDatetime() { - FunctionExpression expression = dsl.castDatetime(DSL.literal("2012-08-07 01:01:01")); + FunctionExpression expression = DSL.castDatetime(DSL.literal("2012-08-07 01:01:01")); assertEquals(DATETIME, expression.type()); assertEquals(new ExprDatetimeValue("2012-08-07 01:01:01"), expression.valueOf()); - expression = dsl.castDatetime(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); + expression = DSL.castDatetime(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); assertEquals(DATETIME, expression.type()); assertEquals(new ExprDatetimeValue("2012-08-07 01:01:01"), expression.valueOf()); - expression = dsl.castDatetime(DSL.literal(new ExprDateValue("2012-08-07"))); + expression = DSL.castDatetime(DSL.literal(new ExprDateValue("2012-08-07"))); assertEquals(DATETIME, expression.type()); assertEquals(new ExprDatetimeValue("2012-08-07 00:00:00"), expression.valueOf()); } diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java index aae76af8de..7354b52e24 100644 --- a/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java @@ -157,7 +157,7 @@ private static Stream testLikeArguments() { @MethodSource("binaryPredicateArguments") public void test_and(Boolean v1, Boolean v2) { FunctionExpression and = - dsl.and(DSL.literal(booleanValue(v1)), DSL.literal(booleanValue(v2))); + DSL.and(DSL.literal(booleanValue(v1)), DSL.literal(booleanValue(v2))); assertEquals(BOOLEAN, and.type()); assertEquals(v1 && v2, ExprValueUtils.getBooleanValue(and.valueOf(valueEnv()))); assertEquals(String.format("and(%s, %s)", v1.toString(), v2.toString()), and.toString()); @@ -166,19 +166,19 @@ public void test_and(Boolean v1, Boolean v2) { @Test public void test_boolean_and_null() { FunctionExpression and = - dsl.and(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); + DSL.and(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_NULL, and.valueOf(valueEnv())); - and = dsl.and(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); + and = DSL.and(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_NULL, and.valueOf(valueEnv())); - and = dsl.and(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); + and = DSL.and(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_FALSE, and.valueOf(valueEnv())); - and = dsl.and(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); + and = DSL.and(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_FALSE, and.valueOf(valueEnv())); } @@ -186,41 +186,41 @@ public void test_boolean_and_null() { @Test public void test_boolean_and_missing() { FunctionExpression and = - dsl.and(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); + DSL.and(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_MISSING, and.valueOf(valueEnv())); - and = dsl.and(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); + and = DSL.and(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_MISSING, and.valueOf(valueEnv())); - and = dsl.and(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); + and = DSL.and(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_FALSE, and.valueOf(valueEnv())); - and = dsl.and(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); + and = DSL.and(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_FALSE, and.valueOf(valueEnv())); } @Test public void test_null_and_missing() { - FunctionExpression and = dsl.and(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + FunctionExpression and = DSL.and(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_MISSING, and.valueOf(valueEnv())); - and = dsl.and(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + and = DSL.and(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_NULL, and.valueOf(valueEnv())); - and = dsl.and(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + and = DSL.and(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_MISSING, and.valueOf(valueEnv())); - and = dsl.and(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + and = DSL.and(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, and.type()); assertEquals(LITERAL_MISSING, and.valueOf(valueEnv())); @@ -230,7 +230,7 @@ public void test_null_and_missing() { @MethodSource("binaryPredicateArguments") public void test_or(Boolean v1, Boolean v2) { FunctionExpression or = - dsl.or(DSL.literal(booleanValue(v1)), DSL.literal(booleanValue(v2))); + DSL.or(DSL.literal(booleanValue(v1)), DSL.literal(booleanValue(v2))); assertEquals(BOOLEAN, or.type()); assertEquals(v1 || v2, ExprValueUtils.getBooleanValue(or.valueOf(valueEnv()))); assertEquals(String.format("or(%s, %s)", v1.toString(), v2.toString()), or.toString()); @@ -239,19 +239,19 @@ public void test_or(Boolean v1, Boolean v2) { @Test public void test_boolean_or_null() { FunctionExpression or = - dsl.or(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); + DSL.or(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_TRUE, or.valueOf(valueEnv())); - or = dsl.or(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); + or = DSL.or(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_TRUE, or.valueOf(valueEnv())); - or = dsl.or(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); + or = DSL.or(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_NULL, or.valueOf(valueEnv())); - or = dsl.or(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); + or = DSL.or(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_NULL, or.valueOf(valueEnv())); } @@ -259,42 +259,42 @@ public void test_boolean_or_null() { @Test public void test_boolean_or_missing() { FunctionExpression or = - dsl.or(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); + DSL.or(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_TRUE, or.valueOf(valueEnv())); - or = dsl.or(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); + or = DSL.or(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_TRUE, or.valueOf(valueEnv())); - or = dsl.or(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); + or = DSL.or(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_MISSING, or.valueOf(valueEnv())); - or = dsl.or(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); + or = DSL.or(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_MISSING, or.valueOf(valueEnv())); } @Test public void test_null_or_missing() { - FunctionExpression or = dsl.or(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + FunctionExpression or = DSL.or(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_MISSING, or.valueOf(valueEnv())); or = - dsl.or(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + DSL.or(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_NULL, or.valueOf(valueEnv())); - or = dsl.or(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + or = DSL.or(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_NULL, or.valueOf(valueEnv())); - or = dsl.or(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + or = DSL.or(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, or.type()); assertEquals(LITERAL_NULL, or.valueOf(valueEnv())); @@ -305,7 +305,7 @@ public void test_null_or_missing() { @MethodSource("binaryPredicateArguments") public void test_xor(Boolean v1, Boolean v2) { FunctionExpression xor = - dsl.xor(DSL.literal(booleanValue(v1)), DSL.literal(booleanValue(v2))); + DSL.xor(DSL.literal(booleanValue(v1)), DSL.literal(booleanValue(v2))); assertEquals(BOOLEAN, xor.type()); assertEquals(v1 ^ v2, ExprValueUtils.getBooleanValue(xor.valueOf(valueEnv()))); assertEquals(String.format("xor(%s, %s)", v1.toString(), v2.toString()), xor.toString()); @@ -314,19 +314,19 @@ public void test_xor(Boolean v1, Boolean v2) { @Test public void test_boolean_xor_null() { FunctionExpression xor = - dsl.xor(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); + DSL.xor(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_TRUE, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); + xor = DSL.xor(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_TRUE, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); + xor = DSL.xor(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_NULL, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); + xor = DSL.xor(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_NULL, xor.valueOf(valueEnv())); } @@ -334,41 +334,41 @@ public void test_boolean_xor_null() { @Test public void test_boolean_xor_missing() { FunctionExpression xor = - dsl.xor(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); + DSL.xor(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_TRUE, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); + xor = DSL.xor(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_TRUE, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); + xor = DSL.xor(DSL.literal(LITERAL_FALSE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_MISSING, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); + xor = DSL.xor(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_FALSE)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_MISSING, xor.valueOf(valueEnv())); } @Test public void test_null_xor_missing() { - FunctionExpression xor = dsl.xor(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + FunctionExpression xor = DSL.xor(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_MISSING, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + xor = DSL.xor(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_NULL, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + xor = DSL.xor(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_NULL, xor.valueOf(valueEnv())); - xor = dsl.xor(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + xor = DSL.xor(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, xor.type()); assertEquals(LITERAL_NULL, xor.valueOf(valueEnv())); @@ -377,7 +377,7 @@ public void test_null_xor_missing() { @ParameterizedTest(name = "equal({0}, {1})") @MethodSource("testEqualArguments") public void test_equal(ExprValue v1, ExprValue v2) { - FunctionExpression equal = dsl.equal(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression equal = DSL.equal(DSL.literal(v1), DSL.literal(v2)); assertEquals(BOOLEAN, equal.type()); assertEquals(v1.value().equals(v2.value()), ExprValueUtils.getBooleanValue(equal.valueOf(valueEnv()))); @@ -386,39 +386,39 @@ public void test_equal(ExprValue v1, ExprValue v2) { @Test public void test_null_equal_missing() { - FunctionExpression equal = dsl.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + FunctionExpression equal = DSL.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); - equal = dsl.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + equal = DSL.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_NULL, equal.valueOf(valueEnv())); - equal = dsl.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + equal = DSL.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); - equal = dsl.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + equal = DSL.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); - equal = dsl.equal(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); + equal = DSL.equal(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); - equal = dsl.equal(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); + equal = DSL.equal(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_NULL, equal.valueOf(valueEnv())); - equal = dsl.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); + equal = DSL.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); - equal = dsl.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); + equal = DSL.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_NULL, equal.valueOf(valueEnv())); } @@ -426,7 +426,7 @@ public void test_null_equal_missing() { @ParameterizedTest(name = "equal({0}, {1})") @MethodSource({"testEqualArguments", "testNotEqualArguments"}) public void test_notequal(ExprValue v1, ExprValue v2) { - FunctionExpression notequal = dsl.notequal(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression notequal = DSL.notequal(DSL.literal(v1), DSL.literal(v2)); assertEquals(BOOLEAN, notequal.type()); assertEquals(!v1.value().equals(v2.value()), ExprValueUtils.getBooleanValue(notequal.valueOf(valueEnv()))); @@ -435,42 +435,42 @@ public void test_notequal(ExprValue v1, ExprValue v2) { @Test public void test_null_notequal_missing() { - FunctionExpression notequal = dsl.notequal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + FunctionExpression notequal = DSL.notequal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, notequal.type()); assertEquals(LITERAL_MISSING, notequal.valueOf(valueEnv())); - notequal = dsl.notequal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + notequal = DSL.notequal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, notequal.type()); assertEquals(LITERAL_NULL, notequal.valueOf(valueEnv())); - notequal = dsl.notequal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + notequal = DSL.notequal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, notequal.type()); assertEquals(LITERAL_MISSING, notequal.valueOf(valueEnv())); - notequal = dsl.notequal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + notequal = DSL.notequal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, notequal.type()); assertEquals(LITERAL_MISSING, notequal.valueOf(valueEnv())); - notequal = dsl.notequal(DSL.literal(LITERAL_TRUE), + notequal = DSL.notequal(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, notequal.type()); assertEquals(LITERAL_MISSING, notequal.valueOf(valueEnv())); - notequal = dsl.notequal(DSL.literal(LITERAL_TRUE), + notequal = DSL.notequal(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, notequal.type()); assertEquals(LITERAL_NULL, notequal.valueOf(valueEnv())); - notequal = dsl.notequal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), + notequal = DSL.notequal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, notequal.type()); assertEquals(LITERAL_MISSING, notequal.valueOf(valueEnv())); - notequal = dsl.notequal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), + notequal = DSL.notequal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, notequal.type()); assertEquals(LITERAL_NULL, notequal.valueOf(valueEnv())); @@ -479,7 +479,7 @@ public void test_null_notequal_missing() { @ParameterizedTest(name = "less({0}, {1})") @MethodSource("testCompareValueArguments") public void test_less(ExprValue v1, ExprValue v2) { - FunctionExpression less = dsl.less(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression less = DSL.less(DSL.literal(v1), DSL.literal(v2)); assertEquals(BOOLEAN, less.type()); assertEquals(compare(v1, v2) < 0, ExprValueUtils.getBooleanValue(less.valueOf(valueEnv()))); @@ -488,16 +488,16 @@ public void test_less(ExprValue v1, ExprValue v2) { @Test public void test_less_null() { - FunctionExpression less = dsl.less(DSL.literal(1), + FunctionExpression less = DSL.less(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, less.type()); assertEquals(LITERAL_NULL, less.valueOf(valueEnv())); - less = dsl.less(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + less = DSL.less(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(BOOLEAN, less.type()); assertEquals(LITERAL_NULL, less.valueOf(valueEnv())); - less = dsl.less(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + less = DSL.less(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, less.type()); assertEquals(LITERAL_NULL, less.valueOf(valueEnv())); @@ -505,16 +505,16 @@ public void test_less_null() { @Test public void test_less_missing() { - FunctionExpression less = dsl.less(DSL.literal(1), + FunctionExpression less = DSL.less(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, less.type()); assertEquals(LITERAL_MISSING, less.valueOf(valueEnv())); - less = dsl.less(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + less = DSL.less(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(BOOLEAN, less.type()); assertEquals(LITERAL_MISSING, less.valueOf(valueEnv())); - less = dsl.less(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + less = DSL.less(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, less.type()); assertEquals(LITERAL_MISSING, less.valueOf(valueEnv())); @@ -522,12 +522,12 @@ public void test_less_missing() { @Test public void test_null_less_missing() { - FunctionExpression less = dsl.less(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + FunctionExpression less = DSL.less(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, less.type()); assertEquals(LITERAL_MISSING, less.valueOf(valueEnv())); - less = dsl.less(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + less = DSL.less(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, less.type()); assertEquals(LITERAL_MISSING, less.valueOf(valueEnv())); @@ -536,7 +536,7 @@ public void test_null_less_missing() { @ParameterizedTest(name = "lte({0}, {1})") @MethodSource("testCompareValueArguments") public void test_lte(ExprValue v1, ExprValue v2) { - FunctionExpression lte = dsl.lte(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression lte = DSL.lte(DSL.literal(v1), DSL.literal(v2)); assertEquals(BOOLEAN, lte.type()); assertEquals(compare(v1, v2) <= 0, ExprValueUtils.getBooleanValue(lte.valueOf(valueEnv()))); @@ -545,16 +545,16 @@ public void test_lte(ExprValue v1, ExprValue v2) { @Test public void test_lte_null() { - FunctionExpression lte = dsl.lte(DSL.literal(1), + FunctionExpression lte = DSL.lte(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, lte.type()); assertEquals(LITERAL_NULL, lte.valueOf(valueEnv())); - lte = dsl.lte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + lte = DSL.lte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(BOOLEAN, lte.type()); assertEquals(LITERAL_NULL, lte.valueOf(valueEnv())); - lte = dsl.lte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + lte = DSL.lte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, lte.type()); assertEquals(LITERAL_NULL, lte.valueOf(valueEnv())); @@ -562,16 +562,16 @@ public void test_lte_null() { @Test public void test_lte_missing() { - FunctionExpression lte = dsl.lte(DSL.literal(1), + FunctionExpression lte = DSL.lte(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, lte.type()); assertEquals(LITERAL_MISSING, lte.valueOf(valueEnv())); - lte = dsl.lte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + lte = DSL.lte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(BOOLEAN, lte.type()); assertEquals(LITERAL_MISSING, lte.valueOf(valueEnv())); - lte = dsl.lte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + lte = DSL.lte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, lte.type()); assertEquals(LITERAL_MISSING, lte.valueOf(valueEnv())); @@ -579,12 +579,12 @@ public void test_lte_missing() { @Test public void test_null_lte_missing() { - FunctionExpression lte = dsl.lte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + FunctionExpression lte = DSL.lte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, lte.type()); assertEquals(LITERAL_MISSING, lte.valueOf(valueEnv())); - lte = dsl.lte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + lte = DSL.lte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, lte.type()); assertEquals(LITERAL_MISSING, lte.valueOf(valueEnv())); @@ -593,7 +593,7 @@ public void test_null_lte_missing() { @ParameterizedTest(name = "greater({0}, {1})") @MethodSource("testCompareValueArguments") public void test_greater(ExprValue v1, ExprValue v2) { - FunctionExpression greater = dsl.greater(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression greater = DSL.greater(DSL.literal(v1), DSL.literal(v2)); assertEquals(BOOLEAN, greater.type()); assertEquals(compare(v1, v2) > 0, ExprValueUtils.getBooleanValue(greater.valueOf(valueEnv()))); @@ -602,16 +602,16 @@ public void test_greater(ExprValue v1, ExprValue v2) { @Test public void test_greater_null() { - FunctionExpression greater = dsl.greater(DSL.literal(1), + FunctionExpression greater = DSL.greater(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, greater.type()); assertEquals(LITERAL_NULL, greater.valueOf(valueEnv())); - greater = dsl.greater(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + greater = DSL.greater(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(BOOLEAN, greater.type()); assertEquals(LITERAL_NULL, greater.valueOf(valueEnv())); - greater = dsl.greater(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + greater = DSL.greater(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, greater.type()); assertEquals(LITERAL_NULL, greater.valueOf(valueEnv())); @@ -619,16 +619,16 @@ public void test_greater_null() { @Test public void test_greater_missing() { - FunctionExpression greater = dsl.greater(DSL.literal(1), + FunctionExpression greater = DSL.greater(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, greater.type()); assertEquals(LITERAL_MISSING, greater.valueOf(valueEnv())); - greater = dsl.greater(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + greater = DSL.greater(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(BOOLEAN, greater.type()); assertEquals(LITERAL_MISSING, greater.valueOf(valueEnv())); - greater = dsl.greater(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + greater = DSL.greater(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, greater.type()); assertEquals(LITERAL_MISSING, greater.valueOf(valueEnv())); @@ -636,12 +636,12 @@ public void test_greater_missing() { @Test public void test_null_greater_missing() { - FunctionExpression greater = dsl.greater(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + FunctionExpression greater = DSL.greater(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, greater.type()); assertEquals(LITERAL_MISSING, greater.valueOf(valueEnv())); - greater = dsl.greater(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + greater = DSL.greater(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, greater.type()); assertEquals(LITERAL_MISSING, greater.valueOf(valueEnv())); @@ -650,7 +650,7 @@ public void test_null_greater_missing() { @ParameterizedTest(name = "gte({0}, {1})") @MethodSource("testCompareValueArguments") public void test_gte(ExprValue v1, ExprValue v2) { - FunctionExpression gte = dsl.gte(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression gte = DSL.gte(DSL.literal(v1), DSL.literal(v2)); assertEquals(BOOLEAN, gte.type()); assertEquals(compare(v1, v2) >= 0, ExprValueUtils.getBooleanValue(gte.valueOf(valueEnv()))); @@ -659,16 +659,16 @@ public void test_gte(ExprValue v1, ExprValue v2) { @Test public void test_gte_null() { - FunctionExpression gte = dsl.gte(DSL.literal(1), + FunctionExpression gte = DSL.gte(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, gte.type()); assertEquals(LITERAL_NULL, gte.valueOf(valueEnv())); - gte = dsl.gte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); + gte = DSL.gte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(BOOLEAN, gte.type()); assertEquals(LITERAL_NULL, gte.valueOf(valueEnv())); - gte = dsl.gte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + gte = DSL.gte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, gte.type()); assertEquals(LITERAL_NULL, gte.valueOf(valueEnv())); @@ -676,16 +676,16 @@ public void test_gte_null() { @Test public void test_gte_missing() { - FunctionExpression gte = dsl.gte(DSL.literal(1), + FunctionExpression gte = DSL.gte(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, gte.type()); assertEquals(LITERAL_MISSING, gte.valueOf(valueEnv())); - gte = dsl.gte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); + gte = DSL.gte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(BOOLEAN, gte.type()); assertEquals(LITERAL_MISSING, gte.valueOf(valueEnv())); - gte = dsl.gte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + gte = DSL.gte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, gte.type()); assertEquals(LITERAL_MISSING, gte.valueOf(valueEnv())); @@ -693,12 +693,12 @@ public void test_gte_missing() { @Test public void test_null_gte_missing() { - FunctionExpression gte = dsl.gte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), + FunctionExpression gte = DSL.gte(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, gte.type()); assertEquals(LITERAL_MISSING, gte.valueOf(valueEnv())); - gte = dsl.gte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), + gte = DSL.gte(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(BOOLEAN, gte.type()); assertEquals(LITERAL_MISSING, gte.valueOf(valueEnv())); @@ -707,7 +707,7 @@ public void test_null_gte_missing() { @ParameterizedTest(name = "like({0}, {1})") @MethodSource("testLikeArguments") public void test_like(ExprValue v1, ExprValue v2) { - FunctionExpression like = dsl.like(DSL.literal(v1), DSL.literal(v2)); + FunctionExpression like = DSL.like(DSL.literal(v1), DSL.literal(v2)); assertEquals(BOOLEAN, like.type()); assertEquals(matches(v1, v2), like.valueOf(valueEnv())); assertEquals(String.format("like(%s, %s)", v1.toString(), v2.toString()), like.toString()); @@ -716,15 +716,15 @@ public void test_like(ExprValue v1, ExprValue v2) { @Test public void test_like_null() { FunctionExpression like = - dsl.like(DSL.literal("str"), DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING)); + DSL.like(DSL.literal("str"), DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING)); assertEquals(BOOLEAN, like.type()); assertEquals(LITERAL_NULL, like.valueOf(valueEnv())); - like = dsl.like(DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING), DSL.literal("str")); + like = DSL.like(DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING), DSL.literal("str")); assertEquals(BOOLEAN, like.type()); assertEquals(LITERAL_NULL, like.valueOf(valueEnv())); - like = dsl.like(DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING), + like = DSL.like(DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING), DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING)); assertEquals(BOOLEAN, like.type()); assertEquals(LITERAL_NULL, like.valueOf(valueEnv())); @@ -733,15 +733,15 @@ public void test_like_null() { @Test public void test_like_missing() { FunctionExpression like = - dsl.like(DSL.literal("str"), DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING)); + DSL.like(DSL.literal("str"), DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING)); assertEquals(BOOLEAN, like.type()); assertEquals(LITERAL_MISSING, like.valueOf(valueEnv())); - like = dsl.like(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), DSL.literal("str")); + like = DSL.like(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), DSL.literal("str")); assertEquals(BOOLEAN, like.type()); assertEquals(LITERAL_MISSING, like.valueOf(valueEnv())); - like = dsl.like(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), + like = DSL.like(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING)); assertEquals(BOOLEAN, like.type()); assertEquals(LITERAL_MISSING, like.valueOf(valueEnv())); @@ -749,12 +749,12 @@ public void test_like_missing() { @Test public void test_null_like_missing() { - FunctionExpression like = dsl.like(DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING), + FunctionExpression like = DSL.like(DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING), DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING)); assertEquals(BOOLEAN, like.type()); assertEquals(LITERAL_MISSING, like.valueOf(valueEnv())); - like = dsl.like(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), + like = DSL.like(DSL.ref(STRING_TYPE_MISSING_VALUE_FIELD, STRING), DSL.ref(STRING_TYPE_NULL_VALUE_FIELD, STRING)); assertEquals(BOOLEAN, like.type()); assertEquals(LITERAL_MISSING, like.valueOf(valueEnv())); @@ -762,12 +762,12 @@ public void test_null_like_missing() { @Test public void test_not_like() { - FunctionExpression notLike = dsl.notLike(DSL.literal("bob"), DSL.literal("tom")); + FunctionExpression notLike = DSL.notLike(DSL.literal("bob"), DSL.literal("tom")); assertEquals(BOOLEAN, notLike.type()); assertTrue(notLike.valueOf(valueEnv()).booleanValue()); assertEquals(String.format("not like(\"%s\", \"%s\")", "bob", "tom"), notLike.toString()); - notLike = dsl.notLike(DSL.literal("bob"), DSL.literal("bo%")); + notLike = DSL.notLike(DSL.literal("bob"), DSL.literal("bo%")); assertFalse(notLike.valueOf(valueEnv()).booleanValue()); assertEquals(String.format("not like(\"%s\", \"%s\")", "bob", "bo%"), notLike.toString()); } @@ -778,7 +778,7 @@ void test_regexp() { } void testRegexpString(StringPatternPair stringPatternPair) { - FunctionExpression expression = dsl.regexp( + FunctionExpression expression = DSL.regexp( DSL.literal(new ExprStringValue(stringPatternPair.getStr())), DSL.literal(new ExprStringValue(stringPatternPair.getPatt()))); assertEquals(INTEGER, expression.type()); @@ -791,7 +791,7 @@ void testRegexpString(StringPatternPair stringPatternPair) { */ @Test public void serializationTest() throws Exception { - Expression expression = dsl.equal(DSL.literal("v1"), DSL.literal("v2")); + Expression expression = DSL.equal(DSL.literal("v1"), DSL.literal("v2")); // serialization ByteArrayOutputStream output = new ByteArrayOutputStream(); ObjectOutputStream objectOutput = new ObjectOutputStream(output); @@ -810,13 +810,13 @@ public void serializationTest() throws Exception { @Test public void compareNumberValueWithDifferentType() { - FunctionExpression equal = dsl.equal(DSL.literal(1), DSL.literal(1L)); + FunctionExpression equal = DSL.equal(DSL.literal(1), DSL.literal(1L)); assertTrue(equal.valueOf(valueEnv()).booleanValue()); } @Test public void compare_int_long() { - FunctionExpression equal = dsl.equal(DSL.literal(1), DSL.literal(1L)); + FunctionExpression equal = DSL.equal(DSL.literal(1), DSL.literal(1L)); assertTrue(equal.valueOf(valueEnv()).booleanValue()); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperatorTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperatorTest.java index 22b94c4b6d..de3f5a3e7e 100644 --- a/core/src/test/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperatorTest.java @@ -36,7 +36,7 @@ class UnaryPredicateOperatorTest extends ExpressionTestBase { @ParameterizedTest(name = "not({0})") @ValueSource(booleans = {true, false}) public void test_not(Boolean v) { - FunctionExpression not = dsl.not(DSL.literal(booleanValue(v))); + FunctionExpression not = DSL.not(DSL.literal(booleanValue(v))); assertEquals(BOOLEAN, not.type()); assertEquals(!v, ExprValueUtils.getBooleanValue(not.valueOf(valueEnv()))); assertEquals(String.format("not(%s)", v.toString()), not.toString()); @@ -156,36 +156,36 @@ private static Stream exprNullIfArguments() { @Test public void test_not_null() { - FunctionExpression expression = dsl.not(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); + FunctionExpression expression = DSL.not(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, expression.type()); assertEquals(LITERAL_NULL, expression.valueOf(valueEnv())); } @Test public void test_not_missing() { - FunctionExpression expression = dsl.not(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); + FunctionExpression expression = DSL.not(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, expression.type()); assertEquals(LITERAL_MISSING, expression.valueOf(valueEnv())); } @Test public void test_is_null_predicate() { - FunctionExpression expression = dsl.is_null(DSL.literal(1)); + FunctionExpression expression = DSL.is_null(DSL.literal(1)); assertEquals(BOOLEAN, expression.type()); assertEquals(LITERAL_FALSE, expression.valueOf(valueEnv())); - expression = dsl.is_null(DSL.literal(ExprNullValue.of())); + expression = DSL.is_null(DSL.literal(ExprNullValue.of())); assertEquals(BOOLEAN, expression.type()); assertEquals(LITERAL_TRUE, expression.valueOf(valueEnv())); } @Test public void test_is_not_null_predicate() { - FunctionExpression expression = dsl.isnotnull(DSL.literal(1)); + FunctionExpression expression = DSL.isnotnull(DSL.literal(1)); assertEquals(BOOLEAN, expression.type()); assertEquals(LITERAL_TRUE, expression.valueOf(valueEnv())); - expression = dsl.isnotnull(DSL.literal(ExprNullValue.of())); + expression = DSL.isnotnull(DSL.literal(ExprNullValue.of())); assertEquals(BOOLEAN, expression.type()); assertEquals(LITERAL_FALSE, expression.valueOf(valueEnv())); } @@ -193,25 +193,25 @@ public void test_is_not_null_predicate() { @ParameterizedTest @MethodSource("isNullArguments") public void test_isnull_predicate(Expression v1, Expression expected) { - assertEquals(expected.valueOf(valueEnv()), dsl.isnull(v1).valueOf(valueEnv())); + assertEquals(expected.valueOf(valueEnv()), DSL.isnull(v1).valueOf(valueEnv())); } @ParameterizedTest @MethodSource("ifNullArguments") public void test_ifnull_predicate(Expression v1, Expression v2, Expression expected) { - assertEquals(expected.valueOf(valueEnv()), dsl.ifnull(v1, v2).valueOf(valueEnv())); + assertEquals(expected.valueOf(valueEnv()), DSL.ifnull(v1, v2).valueOf(valueEnv())); } @ParameterizedTest @MethodSource("nullIfArguments") public void test_nullif_predicate(Expression v1, Expression v2, Expression expected) { - assertEquals(expected.valueOf(valueEnv()), dsl.nullif(v1, v2).valueOf(valueEnv())); + assertEquals(expected.valueOf(valueEnv()), DSL.nullif(v1, v2).valueOf(valueEnv())); } @ParameterizedTest @MethodSource("ifArguments") public void test_if_predicate(Expression v1, Expression v2, Expression v3, Expression expected) { - assertEquals(expected.valueOf(valueEnv()), dsl.iffunction(v1, v2, v3).valueOf(valueEnv())); + assertEquals(expected.valueOf(valueEnv()), DSL.iffunction(v1, v2, v3).valueOf(valueEnv())); } @ParameterizedTest diff --git a/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java b/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java index e6cf4ce585..cdf8e6ec31 100644 --- a/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java @@ -38,14 +38,12 @@ import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; public class SystemFunctionsTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); @Test void typeof() { - assertEquals(STRING, dsl.typeof(DSL.literal(1)).type()); + assertEquals(STRING, DSL.typeof(DSL.literal(1)).type()); assertEquals("ARRAY", typeofGetValue(new ExprCollectionValue(List.of()))); assertEquals("BOOLEAN", typeofGetValue(ExprBooleanValue.of(false))); @@ -88,6 +86,6 @@ public ExprType type() { } private String typeofGetValue(ExprValue input) { - return dsl.typeof(DSL.literal(input)).valueOf().stringValue(); + return DSL.typeof(DSL.literal(input)).valueOf().stringValue(); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/text/TextFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/text/TextFunctionTest.java index f7f7a7749b..502fe70ec8 100644 --- a/core/src/test/java/org/opensearch/sql/expression/text/TextFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/text/TextFunctionTest.java @@ -81,9 +81,9 @@ class Substr implements SubstrSubstring { public FunctionExpression getFunction(SubstringInfo strInfo) { FunctionExpression expr; if (strInfo.getLen() == null) { - expr = dsl.substr(DSL.literal(strInfo.getExpr()), DSL.literal(strInfo.getStart())); + expr = DSL.substr(DSL.literal(strInfo.getExpr()), DSL.literal(strInfo.getStart())); } else { - expr = dsl.substr(DSL.literal(strInfo.getExpr()), + expr = DSL.substr(DSL.literal(strInfo.getExpr()), DSL.literal(strInfo.getStart()), DSL.literal(strInfo.getLen())); } @@ -95,9 +95,9 @@ class Substring implements SubstrSubstring { public FunctionExpression getFunction(SubstringInfo strInfo) { FunctionExpression expr; if (strInfo.getLen() == null) { - expr = dsl.substring(DSL.literal(strInfo.getExpr()), DSL.literal(strInfo.getStart())); + expr = DSL.substring(DSL.literal(strInfo.getExpr()), DSL.literal(strInfo.getStart())); } else { - expr = dsl.substring(DSL.literal(strInfo.getExpr()), + expr = DSL.substring(DSL.literal(strInfo.getExpr()), DSL.literal(strInfo.getStart()), DSL.literal(strInfo.getLen())); } @@ -138,17 +138,17 @@ public void substrSubstring() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.substr(missingRef, DSL.literal(1)))); - assertEquals(nullValue(), eval(dsl.substr(nullRef, DSL.literal(1)))); - assertEquals(missingValue(), eval(dsl.substring(missingRef, DSL.literal(1)))); - assertEquals(nullValue(), eval(dsl.substring(nullRef, DSL.literal(1)))); + assertEquals(missingValue(), eval(DSL.substr(missingRef, DSL.literal(1)))); + assertEquals(nullValue(), eval(DSL.substr(nullRef, DSL.literal(1)))); + assertEquals(missingValue(), eval(DSL.substring(missingRef, DSL.literal(1)))); + assertEquals(nullValue(), eval(DSL.substring(nullRef, DSL.literal(1)))); when(nullRef.type()).thenReturn(INTEGER); when(missingRef.type()).thenReturn(INTEGER); - assertEquals(missingValue(), eval(dsl.substr(DSL.literal("hello"), missingRef))); - assertEquals(nullValue(), eval(dsl.substr(DSL.literal("hello"), nullRef))); - assertEquals(missingValue(), eval(dsl.substring(DSL.literal("hello"), missingRef))); - assertEquals(nullValue(), eval(dsl.substring(DSL.literal("hello"), nullRef))); + assertEquals(missingValue(), eval(DSL.substr(DSL.literal("hello"), missingRef))); + assertEquals(nullValue(), eval(DSL.substr(DSL.literal("hello"), nullRef))); + assertEquals(missingValue(), eval(DSL.substring(DSL.literal("hello"), missingRef))); + assertEquals(nullValue(), eval(DSL.substring(DSL.literal("hello"), nullRef))); } void substrSubstringTest(SubstringInfo strInfo, SubstrSubstring substrSubstring) { @@ -163,8 +163,8 @@ public void ltrim() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.ltrim(missingRef))); - assertEquals(nullValue(), eval(dsl.ltrim(nullRef))); + assertEquals(missingValue(), eval(DSL.ltrim(missingRef))); + assertEquals(nullValue(), eval(DSL.ltrim(nullRef))); } @Test @@ -173,8 +173,8 @@ public void rtrim() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.ltrim(missingRef))); - assertEquals(nullValue(), eval(dsl.ltrim(nullRef))); + assertEquals(missingValue(), eval(DSL.ltrim(missingRef))); + assertEquals(nullValue(), eval(DSL.ltrim(nullRef))); } @Test @@ -183,24 +183,24 @@ public void trim() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.ltrim(missingRef))); - assertEquals(nullValue(), eval(dsl.ltrim(nullRef))); + assertEquals(missingValue(), eval(DSL.ltrim(missingRef))); + assertEquals(nullValue(), eval(DSL.ltrim(nullRef))); } void ltrimString(String str) { - FunctionExpression expression = dsl.ltrim(DSL.literal(str)); + FunctionExpression expression = DSL.ltrim(DSL.literal(str)); assertEquals(STRING, expression.type()); assertEquals(str.stripLeading(), eval(expression).stringValue()); } void rtrimString(String str) { - FunctionExpression expression = dsl.rtrim(DSL.literal(str)); + FunctionExpression expression = DSL.rtrim(DSL.literal(str)); assertEquals(STRING, expression.type()); assertEquals(str.stripTrailing(), eval(expression).stringValue()); } void trimString(String str) { - FunctionExpression expression = dsl.trim(DSL.literal(str)); + FunctionExpression expression = DSL.trim(DSL.literal(str)); assertEquals(STRING, expression.type()); assertEquals(str.trim(), eval(expression).stringValue()); } @@ -211,8 +211,8 @@ public void lower() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.lower(missingRef))); - assertEquals(nullValue(), eval(dsl.lower(nullRef))); + assertEquals(missingValue(), eval(DSL.lower(missingRef))); + assertEquals(nullValue(), eval(DSL.lower(nullRef))); } @Test @@ -221,8 +221,8 @@ public void upper() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.upper(missingRef))); - assertEquals(nullValue(), eval(dsl.upper(nullRef))); + assertEquals(missingValue(), eval(DSL.upper(missingRef))); + assertEquals(nullValue(), eval(DSL.upper(nullRef))); } @Test @@ -232,13 +232,13 @@ void concat() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); assertEquals(missingValue(), eval( - dsl.concat(missingRef, DSL.literal("1")))); + DSL.concat(missingRef, DSL.literal("1")))); assertEquals(nullValue(), eval( - dsl.concat(nullRef, DSL.literal("1")))); + DSL.concat(nullRef, DSL.literal("1")))); assertEquals(missingValue(), eval( - dsl.concat(DSL.literal("1"), missingRef))); + DSL.concat(DSL.literal("1"), missingRef))); assertEquals(nullValue(), eval( - dsl.concat(DSL.literal("1"), nullRef))); + DSL.concat(DSL.literal("1"), nullRef))); } @Test @@ -248,17 +248,17 @@ void concat_ws() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); assertEquals(missingValue(), eval( - dsl.concat_ws(missingRef, DSL.literal("1"), DSL.literal("1")))); + DSL.concat_ws(missingRef, DSL.literal("1"), DSL.literal("1")))); assertEquals(nullValue(), eval( - dsl.concat_ws(nullRef, DSL.literal("1"), DSL.literal("1")))); + DSL.concat_ws(nullRef, DSL.literal("1"), DSL.literal("1")))); assertEquals(missingValue(), eval( - dsl.concat_ws(DSL.literal("1"), missingRef, DSL.literal("1")))); + DSL.concat_ws(DSL.literal("1"), missingRef, DSL.literal("1")))); assertEquals(nullValue(), eval( - dsl.concat_ws(DSL.literal("1"), nullRef, DSL.literal("1")))); + DSL.concat_ws(DSL.literal("1"), nullRef, DSL.literal("1")))); assertEquals(missingValue(), eval( - dsl.concat_ws(DSL.literal("1"), DSL.literal("1"), missingRef))); + DSL.concat_ws(DSL.literal("1"), DSL.literal("1"), missingRef))); assertEquals(nullValue(), eval( - dsl.concat_ws(DSL.literal("1"), DSL.literal("1"), nullRef))); + DSL.concat_ws(DSL.literal("1"), DSL.literal("1"), nullRef))); } @Test @@ -267,8 +267,8 @@ void length() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.length(missingRef))); - assertEquals(nullValue(), eval(dsl.length(nullRef))); + assertEquals(missingValue(), eval(DSL.length(missingRef))); + assertEquals(nullValue(), eval(DSL.length(nullRef))); } @Test @@ -277,91 +277,91 @@ void strcmp() { when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.strcmp(missingRef, missingRef))); - assertEquals(nullValue(), eval(dsl.strcmp(nullRef, nullRef))); - assertEquals(missingValue(), eval(dsl.strcmp(nullRef, missingRef))); - assertEquals(missingValue(), eval(dsl.strcmp(missingRef, nullRef))); + assertEquals(missingValue(), eval(DSL.strcmp(missingRef, missingRef))); + assertEquals(nullValue(), eval(DSL.strcmp(nullRef, nullRef))); + assertEquals(missingValue(), eval(DSL.strcmp(nullRef, missingRef))); + assertEquals(missingValue(), eval(DSL.strcmp(missingRef, nullRef))); } @Test void right() { - FunctionExpression expression = dsl.right( + FunctionExpression expression = DSL.right( DSL.literal(new ExprStringValue("foobarbar")), DSL.literal(new ExprIntegerValue(4))); assertEquals(STRING, expression.type()); assertEquals("rbar", eval(expression).stringValue()); - expression = dsl.right(DSL.literal("foo"), DSL.literal(10)); + expression = DSL.right(DSL.literal("foo"), DSL.literal(10)); assertEquals(STRING, expression.type()); assertEquals("foo", eval(expression).value()); - expression = dsl.right(DSL.literal("foo"), DSL.literal(0)); + expression = DSL.right(DSL.literal("foo"), DSL.literal(0)); assertEquals(STRING, expression.type()); assertEquals("", eval(expression).value()); - expression = dsl.right(DSL.literal(""), DSL.literal(10)); + expression = DSL.right(DSL.literal(""), DSL.literal(10)); assertEquals(STRING, expression.type()); assertEquals("", eval(expression).value()); when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(INTEGER); - assertEquals(missingValue(), eval(dsl.right(nullRef, missingRef))); - assertEquals(nullValue(), eval(dsl.right(nullRef, DSL.literal(new ExprIntegerValue(1))))); + assertEquals(missingValue(), eval(DSL.right(nullRef, missingRef))); + assertEquals(nullValue(), eval(DSL.right(nullRef, DSL.literal(new ExprIntegerValue(1))))); when(nullRef.type()).thenReturn(INTEGER); - assertEquals(nullValue(), eval(dsl.right(DSL.literal(new ExprStringValue("value")), nullRef))); + assertEquals(nullValue(), eval(DSL.right(DSL.literal(new ExprStringValue("value")), nullRef))); } @Test void left() { - FunctionExpression expression = dsl.left( + FunctionExpression expression = DSL.left( DSL.literal(new ExprStringValue("helloworld")), DSL.literal(new ExprIntegerValue(5))); assertEquals(STRING, expression.type()); assertEquals("hello", eval(expression).stringValue()); - expression = dsl.left(DSL.literal("hello"), DSL.literal(10)); + expression = DSL.left(DSL.literal("hello"), DSL.literal(10)); assertEquals(STRING, expression.type()); assertEquals("hello", eval(expression).value()); - expression = dsl.left(DSL.literal("hello"), DSL.literal(0)); + expression = DSL.left(DSL.literal("hello"), DSL.literal(0)); assertEquals(STRING, expression.type()); assertEquals("", eval(expression).value()); - expression = dsl.left(DSL.literal(""), DSL.literal(10)); + expression = DSL.left(DSL.literal(""), DSL.literal(10)); assertEquals(STRING, expression.type()); assertEquals("", eval(expression).value()); when(nullRef.type()).thenReturn(STRING); when(missingRef.type()).thenReturn(INTEGER); - assertEquals(missingValue(), eval(dsl.left(nullRef, missingRef))); - assertEquals(nullValue(), eval(dsl.left(nullRef, DSL.literal(new ExprIntegerValue(1))))); + assertEquals(missingValue(), eval(DSL.left(nullRef, missingRef))); + assertEquals(nullValue(), eval(DSL.left(nullRef, DSL.literal(new ExprIntegerValue(1))))); when(nullRef.type()).thenReturn(INTEGER); - assertEquals(nullValue(), eval(dsl.left(DSL.literal(new ExprStringValue("value")), nullRef))); + assertEquals(nullValue(), eval(DSL.left(DSL.literal(new ExprStringValue("value")), nullRef))); } @Test void ascii() { - FunctionExpression expression = dsl.ascii(DSL.literal(new ExprStringValue("hello"))); + FunctionExpression expression = DSL.ascii(DSL.literal(new ExprStringValue("hello"))); assertEquals(INTEGER, expression.type()); assertEquals(104, eval(expression).integerValue()); when(nullRef.type()).thenReturn(STRING); - assertEquals(nullValue(), eval(dsl.ascii(nullRef))); + assertEquals(nullValue(), eval(DSL.ascii(nullRef))); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.ascii(missingRef))); + assertEquals(missingValue(), eval(DSL.ascii(missingRef))); } @Test void locate() { - FunctionExpression expression = dsl.locate( + FunctionExpression expression = DSL.locate( DSL.literal("world"), DSL.literal("helloworld")); assertEquals(INTEGER, expression.type()); assertEquals(6, eval(expression).integerValue()); - expression = dsl.locate( + expression = DSL.locate( DSL.literal("world"), DSL.literal("helloworldworld"), DSL.literal(7)); @@ -369,17 +369,17 @@ void locate() { assertEquals(11, eval(expression).integerValue()); when(nullRef.type()).thenReturn(STRING); - assertEquals(nullValue(), eval(dsl.locate(nullRef, DSL.literal("hello")))); - assertEquals(nullValue(), eval(dsl.locate(nullRef, DSL.literal("hello"), DSL.literal(1)))); + assertEquals(nullValue(), eval(DSL.locate(nullRef, DSL.literal("hello")))); + assertEquals(nullValue(), eval(DSL.locate(nullRef, DSL.literal("hello"), DSL.literal(1)))); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.locate(missingRef, DSL.literal("hello")))); + assertEquals(missingValue(), eval(DSL.locate(missingRef, DSL.literal("hello")))); assertEquals(missingValue(), eval( - dsl.locate(missingRef, DSL.literal("hello"), DSL.literal(1)))); + DSL.locate(missingRef, DSL.literal("hello"), DSL.literal(1)))); } @Test void replace() { - FunctionExpression expression = dsl.replace( + FunctionExpression expression = DSL.replace( DSL.literal("helloworld"), DSL.literal("world"), DSL.literal("opensearch")); @@ -387,9 +387,9 @@ void replace() { assertEquals("helloopensearch", eval(expression).stringValue()); when(nullRef.type()).thenReturn(STRING); - assertEquals(nullValue(), eval(dsl.replace(nullRef, DSL.literal("a"), DSL.literal("b")))); + assertEquals(nullValue(), eval(DSL.replace(nullRef, DSL.literal("a"), DSL.literal("b")))); when(missingRef.type()).thenReturn(STRING); - assertEquals(missingValue(), eval(dsl.replace(missingRef, DSL.literal("a"), DSL.literal("b")))); + assertEquals(missingValue(), eval(DSL.replace(missingRef, DSL.literal("a"), DSL.literal("b")))); } void testConcatString(List strings) { @@ -398,7 +398,7 @@ void testConcatString(List strings) { expected = String.join("", strings); } - FunctionExpression expression = dsl.concat( + FunctionExpression expression = DSL.concat( DSL.literal(strings.get(0)), DSL.literal(strings.get(1))); assertEquals(STRING, expression.type()); assertEquals(expected, eval(expression).stringValue()); @@ -408,20 +408,20 @@ void testConcatString(List strings, String delim) { String expected = strings.stream() .filter(Objects::nonNull).collect(Collectors.joining(",")); - FunctionExpression expression = dsl.concat_ws( + FunctionExpression expression = DSL.concat_ws( DSL.literal(delim), DSL.literal(strings.get(0)), DSL.literal(strings.get(1))); assertEquals(STRING, expression.type()); assertEquals(expected, eval(expression).stringValue()); } void testLengthString(String str) { - FunctionExpression expression = dsl.length(DSL.literal(new ExprStringValue(str))); + FunctionExpression expression = DSL.length(DSL.literal(new ExprStringValue(str))); assertEquals(INTEGER, expression.type()); assertEquals(str.getBytes().length, eval(expression).integerValue()); } void testStcmpString(StringPatternPair stringPatternPair) { - FunctionExpression expression = dsl.strcmp( + FunctionExpression expression = DSL.strcmp( DSL.literal(new ExprStringValue(stringPatternPair.getStr())), DSL.literal(new ExprStringValue(stringPatternPair.getPatt()))); assertEquals(INTEGER, expression.type()); @@ -429,13 +429,13 @@ void testStcmpString(StringPatternPair stringPatternPair) { } void testLowerString(String str) { - FunctionExpression expression = dsl.lower(DSL.literal(new ExprStringValue(str))); + FunctionExpression expression = DSL.lower(DSL.literal(new ExprStringValue(str))); assertEquals(STRING, expression.type()); assertEquals(stringValue(str.toLowerCase()), eval(expression)); } void testUpperString(String str) { - FunctionExpression expression = dsl.upper(DSL.literal(new ExprStringValue(str))); + FunctionExpression expression = DSL.upper(DSL.literal(new ExprStringValue(str))); assertEquals(STRING, expression.type()); assertEquals(stringValue(str.toUpperCase()), eval(expression)); } diff --git a/core/src/test/java/org/opensearch/sql/expression/window/aggregation/AggregateWindowFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/window/aggregation/AggregateWindowFunctionTest.java index 9a9648a79b..d7062d4e47 100644 --- a/core/src/test/java/org/opensearch/sql/expression/window/aggregation/AggregateWindowFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/window/aggregation/AggregateWindowFunctionTest.java @@ -53,7 +53,7 @@ void test_delegated_methods() { void should_accumulate_all_peer_values_and_not_reset_state_if_same_partition() { PeerRowsWindowFrame windowFrame = mock(PeerRowsWindowFrame.class); AggregateWindowFunction windowFunction = - new AggregateWindowFunction(dsl.sum(DSL.ref("age", INTEGER))); + new AggregateWindowFunction(DSL.sum(DSL.ref("age", INTEGER))); when(windowFrame.isNewPartition()).thenReturn(true); when(windowFrame.next()).thenReturn(ImmutableList.of( diff --git a/core/src/test/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunctionTest.java index 87084bf48f..7b2b5a42f2 100644 --- a/core/src/test/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunctionTest.java @@ -83,7 +83,7 @@ void test_value_of() { fromExprValueMap(ImmutableMap.of( "state", new ExprStringValue("WA"), "age", new ExprIntegerValue(30))))); - RankingWindowFunction rowNumber = dsl.rowNumber(); + RankingWindowFunction rowNumber = DSL.rowNumber(); windowFrame1.load(iterator); assertEquals(new ExprIntegerValue(1), rowNumber.valueOf(windowFrame1)); @@ -91,7 +91,7 @@ void test_value_of() { @Test void test_row_number() { - RankingWindowFunction rowNumber = dsl.rowNumber(); + RankingWindowFunction rowNumber = DSL.rowNumber(); windowFrame1.load(iterator1); assertEquals(1, rowNumber.rank(windowFrame1)); @@ -108,7 +108,7 @@ void test_row_number() { @Test void test_rank() { - RankingWindowFunction rank = dsl.rank(); + RankingWindowFunction rank = DSL.rank(); windowFrame1.load(iterator2); assertEquals(1, rank.rank(windowFrame1)); @@ -128,7 +128,7 @@ void test_rank() { @Test void test_dense_rank() { - RankingWindowFunction denseRank = dsl.denseRank(); + RankingWindowFunction denseRank = DSL.denseRank(); windowFrame1.load(iterator2); assertEquals(1, denseRank.rank(windowFrame1)); @@ -148,7 +148,7 @@ void test_dense_rank() { @Test void row_number_should_work_if_no_sort_items_defined() { - RankingWindowFunction rowNumber = dsl.rowNumber(); + RankingWindowFunction rowNumber = DSL.rowNumber(); windowFrame2.load(iterator1); assertEquals(1, rowNumber.rank(windowFrame2)); @@ -178,7 +178,7 @@ void rank_should_always_return_1_if_no_sort_items_defined() { fromExprValueMap(ImmutableMap.of( "state", new ExprStringValue("CA"), "age", new ExprIntegerValue(15))))); - RankingWindowFunction rank = dsl.rank(); + RankingWindowFunction rank = DSL.rank(); windowFrame2.load(iterator); assertEquals(1, rank.rank(windowFrame2)); @@ -198,7 +198,7 @@ void rank_should_always_return_1_if_no_sort_items_defined() { @Test void dense_rank_should_always_return_1_if_no_sort_items_defined() { - RankingWindowFunction denseRank = dsl.denseRank(); + RankingWindowFunction denseRank = DSL.denseRank(); windowFrame2.load(iterator2); assertEquals(1, denseRank.rank(windowFrame2)); diff --git a/core/src/test/java/org/opensearch/sql/planner/PlannerTest.java b/core/src/test/java/org/opensearch/sql/planner/PlannerTest.java index 4207c7d31b..64498f76cd 100644 --- a/core/src/test/java/org/opensearch/sql/planner/PlannerTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/PlannerTest.java @@ -12,7 +12,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.when; -import static org.opensearch.sql.analysis.CatalogSchemaIdentifierNameResolver.DEFAULT_CATALOG_NAME; +import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -25,7 +25,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.planner.logical.LogicalAggregation; @@ -69,9 +69,9 @@ public void planner_test() { PhysicalPlanDSL.agg( PhysicalPlanDSL.filter( scan, - dsl.equal(DSL.ref("response", INTEGER), DSL.literal(10)) + DSL.equal(DSL.ref("response", INTEGER), DSL.literal(10)) ), - ImmutableList.of(DSL.named("avg(response)", dsl.avg(DSL.ref("response", INTEGER)))), + ImmutableList.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), ImmutableList.of() ), ImmutableMap.of(DSL.ref("ivalue", INTEGER), DSL.ref("avg(response)", DOUBLE)) @@ -81,11 +81,11 @@ public void planner_test() { LogicalPlanDSL.filter( LogicalPlanDSL.relation("schema", storageEngine.getTable( - new CatalogSchemaName(DEFAULT_CATALOG_NAME, "default"), + new DataSourceSchemaName(DEFAULT_DATASOURCE_NAME, "default"), "schema")), - dsl.equal(DSL.ref("response", INTEGER), DSL.literal(10)) + DSL.equal(DSL.ref("response", INTEGER), DSL.literal(10)) ), - ImmutableList.of(DSL.named("avg(response)", dsl.avg(DSL.ref("response", INTEGER)))), + ImmutableList.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), ImmutableList.of() ), ImmutableMap.of(DSL.ref("ivalue", INTEGER), DSL.ref("avg(response)", DOUBLE)) diff --git a/core/src/test/java/org/opensearch/sql/planner/logical/LogicalDedupeTest.java b/core/src/test/java/org/opensearch/sql/planner/logical/LogicalDedupeTest.java index be6d1fa48c..84cef2cbf3 100644 --- a/core/src/test/java/org/opensearch/sql/planner/logical/LogicalDedupeTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/logical/LogicalDedupeTest.java @@ -21,14 +21,13 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.opensearch.sql.analysis.AnalyzerTestBase; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {AnalyzerTestBase.class}) class LogicalDedupeTest extends AnalyzerTestBase { @Test public void analyze_dedup_with_two_field_with_default_option() { diff --git a/core/src/test/java/org/opensearch/sql/planner/logical/LogicalEvalTest.java b/core/src/test/java/org/opensearch/sql/planner/logical/LogicalEvalTest.java index d08e7c7ee8..63429453f9 100644 --- a/core/src/test/java/org/opensearch/sql/planner/logical/LogicalEvalTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/logical/LogicalEvalTest.java @@ -16,14 +16,13 @@ import org.opensearch.sql.analysis.AnalyzerTestBase; import org.opensearch.sql.ast.dsl.AstDSL; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {AnalyzerTestBase.class}) @ExtendWith(MockitoExtension.class) public class LogicalEvalTest extends AnalyzerTestBase { @@ -33,7 +32,7 @@ public void analyze_eval_with_one_field() { LogicalPlanDSL.eval( LogicalPlanDSL.relation("schema", table), ImmutablePair - .of(DSL.ref("absValue", INTEGER), dsl.abs(DSL.ref("integer_value", INTEGER)))), + .of(DSL.ref("absValue", INTEGER), DSL.abs(DSL.ref("integer_value", INTEGER)))), AstDSL.eval( AstDSL.relation("schema"), AstDSL.let(AstDSL.field("absValue"), AstDSL.function("abs", field("integer_value"))))); @@ -45,8 +44,8 @@ public void analyze_eval_with_two_field() { LogicalPlanDSL.eval( LogicalPlanDSL.relation("schema", table), ImmutablePair - .of(DSL.ref("absValue", INTEGER), dsl.abs(DSL.ref("integer_value", INTEGER))), - ImmutablePair.of(DSL.ref("iValue", INTEGER), dsl.abs(DSL.ref("absValue", INTEGER)))), + .of(DSL.ref("absValue", INTEGER), DSL.abs(DSL.ref("integer_value", INTEGER))), + ImmutablePair.of(DSL.ref("iValue", INTEGER), DSL.abs(DSL.ref("absValue", INTEGER)))), AstDSL.eval( AstDSL.relation("schema"), AstDSL.let(AstDSL.field("absValue"), AstDSL.function("abs", field("integer_value"))), diff --git a/core/src/test/java/org/opensearch/sql/planner/logical/LogicalRelationTest.java b/core/src/test/java/org/opensearch/sql/planner/logical/LogicalRelationTest.java index 93448185cd..dacd84e12b 100644 --- a/core/src/test/java/org/opensearch/sql/planner/logical/LogicalRelationTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/logical/LogicalRelationTest.java @@ -28,7 +28,7 @@ public void logicalRelationHasNoInput() { } @Test - public void logicalRelationWithCatalogHasNoInput() { + public void logicalRelationWithDataSourceHasNoInput() { LogicalPlan relation = LogicalPlanDSL.relation("prometheus.index", table); assertEquals(0, relation.getChild().size()); } diff --git a/core/src/test/java/org/opensearch/sql/planner/logical/LogicalSortTest.java b/core/src/test/java/org/opensearch/sql/planner/logical/LogicalSortTest.java index dd8e76d694..deeda2b82c 100644 --- a/core/src/test/java/org/opensearch/sql/planner/logical/LogicalSortTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/logical/LogicalSortTest.java @@ -23,14 +23,13 @@ import org.opensearch.sql.analysis.AnalyzerTestBase; import org.opensearch.sql.ast.tree.Sort.SortOption; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {AnalyzerTestBase.class}) class LogicalSortTest extends AnalyzerTestBase { @Test public void analyze_sort_with_two_field_with_default_option() { diff --git a/core/src/test/java/org/opensearch/sql/planner/optimizer/LogicalPlanOptimizerTest.java b/core/src/test/java/org/opensearch/sql/planner/optimizer/LogicalPlanOptimizerTest.java index d81bcf66cd..9f3035888f 100644 --- a/core/src/test/java/org/opensearch/sql/planner/optimizer/LogicalPlanOptimizerTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/optimizer/LogicalPlanOptimizerTest.java @@ -21,7 +21,6 @@ import org.opensearch.sql.analysis.AnalyzerTestBase; import org.opensearch.sql.ast.tree.Sort; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.planner.logical.LogicalPlan; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; @@ -29,7 +28,7 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {AnalyzerTestBase.class}) class LogicalPlanOptimizerTest extends AnalyzerTestBase { /** * Filter - Filter --> Filter. @@ -39,16 +38,16 @@ void filter_merge_filter() { assertEquals( filter( relation("schema", table), - dsl.and(dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(2))), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))) + DSL.and(DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(2))), + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1)))) ), optimize( filter( filter( relation("schema", table), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(1))) ), - dsl.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(2))) + DSL.equal(DSL.ref("integer_value", INTEGER), DSL.literal(integerValue(2))) ) ) ); @@ -63,7 +62,7 @@ void push_filter_under_sort() { sort( filter( relation("schema", table), - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ), Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("longV", LONG)) ), @@ -73,7 +72,7 @@ void push_filter_under_sort() { relation("schema", table), Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("longV", LONG)) ), - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ) ) ); @@ -88,8 +87,8 @@ void multiple_filter_should_eventually_be_merged() { sort( filter( relation("schema", table), - dsl.and(dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), - dsl.less(DSL.ref("longV", INTEGER), DSL.literal(longValue(1L)))) + DSL.and(DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), + DSL.less(DSL.ref("longV", INTEGER), DSL.literal(longValue(1L)))) ), Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("longV", LONG)) ), @@ -98,18 +97,18 @@ void multiple_filter_should_eventually_be_merged() { sort( filter( relation("schema", table), - dsl.less(DSL.ref("longV", INTEGER), DSL.literal(longValue(1L))) + DSL.less(DSL.ref("longV", INTEGER), DSL.literal(longValue(1L))) ), Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("longV", LONG)) ), - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ) ) ); } private LogicalPlan optimize(LogicalPlan plan) { - final LogicalPlanOptimizer optimizer = LogicalPlanOptimizer.create(dsl); + final LogicalPlanOptimizer optimizer = LogicalPlanOptimizer.create(); final LogicalPlan optimize = optimizer.optimize(plan); return optimize; } diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java index 46b9821752..2585a21d7a 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java @@ -10,7 +10,6 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInRelativeOrder; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_MISSING; import static org.opensearch.sql.data.type.ExprCoreType.DATE; import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; @@ -41,7 +40,7 @@ class AggregationOperatorTest extends PhysicalPlanTestBase { public void sum_without_groups() { PhysicalPlan plan = new AggregationOperator(new TestScan(), Collections - .singletonList(DSL.named("sum(response)", dsl.sum(DSL.ref("response", INTEGER)))), + .singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), Collections.emptyList()); List result = execute(plan); assertEquals(1, result.size()); @@ -54,7 +53,7 @@ public void sum_without_groups() { public void avg_with_one_groups() { PhysicalPlan plan = new AggregationOperator(new TestScan(), Collections - .singletonList(DSL.named("avg(response)", dsl.avg(DSL.ref("response", INTEGER)))), + .singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); @@ -68,7 +67,7 @@ public void avg_with_one_groups() { public void avg_with_two_groups() { PhysicalPlan plan = new AggregationOperator(new TestScan(), Collections - .singletonList(DSL.named("avg(response)", dsl.avg(DSL.ref("response", INTEGER)))), + .singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), Arrays.asList(DSL.named("action", DSL.ref("action", STRING)), DSL.named("ip", DSL.ref("ip", STRING)))); List result = execute(plan); @@ -87,7 +86,7 @@ public void avg_with_two_groups() { public void sum_with_one_groups() { PhysicalPlan plan = new AggregationOperator(new TestScan(), Collections - .singletonList(DSL.named("sum(response)", dsl.sum(DSL.ref("response", INTEGER)))), + .singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); @@ -101,7 +100,7 @@ public void sum_with_one_groups() { public void millisecond_span() { PhysicalPlan plan = new AggregationOperator(testScan(datetimeInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("second", TIMESTAMP)))), + .named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); List result = execute(plan); @@ -118,7 +117,7 @@ public void millisecond_span() { public void second_span() { PhysicalPlan plan = new AggregationOperator(testScan(datetimeInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("second", TIMESTAMP)))), + .named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6), "s")))); List result = execute(plan); @@ -135,7 +134,7 @@ public void second_span() { public void minute_span() { PhysicalPlan plan = new AggregationOperator(testScan(datetimeInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("minute", DATETIME)))), + .named("count", DSL.count(DSL.ref("minute", DATETIME)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("minute", DATETIME), DSL.literal(5), "m")))); List result = execute(plan); @@ -151,7 +150,7 @@ public void minute_span() { plan = new AggregationOperator(testScan(datetimeInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("hour", TIME)))), + .named("count", DSL.count(DSL.ref("hour", TIME)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(30), "m")))); result = execute(plan); @@ -172,7 +171,7 @@ public void minute_span() { public void hour_span() { PhysicalPlan plan = new AggregationOperator(testScan(datetimeInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("hour", TIME)))), + .named("count", DSL.count(DSL.ref("hour", TIME)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(1), "h")))); List result = execute(plan); @@ -191,7 +190,7 @@ public void hour_span() { public void day_span() { PhysicalPlan plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count(day)", dsl.count(DSL.ref("day", DATE)))), + .named("count(day)", DSL.count(DSL.ref("day", DATE)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); List result = execute(plan); @@ -209,7 +208,7 @@ public void day_span() { plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("month", DATE)))), + .named("count", DSL.count(DSL.ref("month", DATE)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(30), "d")))); result = execute(plan); @@ -228,7 +227,7 @@ public void day_span() { public void week_span() { PhysicalPlan plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("month", DATE)))), + .named("count", DSL.count(DSL.ref("month", DATE)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(5), "w")))); List result = execute(plan); @@ -247,7 +246,7 @@ public void week_span() { public void month_span() { PhysicalPlan plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("month", DATE)))), + .named("count", DSL.count(DSL.ref("month", DATE)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(1), "M")))); List result = execute(plan); @@ -263,7 +262,7 @@ public void month_span() { plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("quarter", DATETIME)))), + .named("count", DSL.count(DSL.ref("quarter", DATETIME)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("quarter", DATETIME), DSL.literal(2), "M")))); result = execute(plan); @@ -281,7 +280,7 @@ public void month_span() { plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("year", TIMESTAMP)))), + .named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 12), "M")))); result = execute(plan); @@ -301,7 +300,7 @@ public void month_span() { public void quarter_span() { PhysicalPlan plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("quarter", DATETIME)))), + .named("count", DSL.count(DSL.ref("quarter", DATETIME)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("quarter", DATETIME), DSL.literal(2), "q")))); List result = execute(plan); @@ -315,7 +314,7 @@ public void quarter_span() { plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("year", TIMESTAMP)))), + .named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 4), "q")))); result = execute(plan); @@ -334,7 +333,7 @@ public void quarter_span() { public void year_span() { PhysicalPlan plan = new AggregationOperator(testScan(dateInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("year", TIMESTAMP)))), + .named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10), "y")))); List result = execute(plan); @@ -352,7 +351,7 @@ public void year_span() { @Test public void integer_field() { PhysicalPlan plan = new AggregationOperator(testScan(numericInputs), - Collections.singletonList(DSL.named("count", dsl.count(DSL.ref("integer", INTEGER)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), Collections.singletonList(DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL .literal(1), "")))); List result = execute(plan); @@ -363,7 +362,7 @@ public void integer_field() { ExprValueUtils.tupleValue(ImmutableMap.of("span", 5, "count", 1)))); plan = new AggregationOperator(testScan(numericInputs), - Collections.singletonList(DSL.named("count", dsl.count(DSL.ref("integer", INTEGER)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), Collections.singletonList(DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL .literal(1.5), "")))); result = execute(plan); @@ -377,7 +376,7 @@ public void integer_field() { @Test public void long_field() { PhysicalPlan plan = new AggregationOperator(testScan(numericInputs), - Collections.singletonList(DSL.named("count", dsl.count(DSL.ref("long", LONG)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), Collections.singletonList(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL .literal(1), "")))); List result = execute(plan); @@ -388,7 +387,7 @@ public void long_field() { ExprValueUtils.tupleValue(ImmutableMap.of("span", 5L, "count", 1)))); plan = new AggregationOperator(testScan(numericInputs), - Collections.singletonList(DSL.named("count", dsl.count(DSL.ref("long", LONG)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), Collections.singletonList(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL .literal(1.5), "")))); result = execute(plan); @@ -402,7 +401,7 @@ public void long_field() { @Test public void float_field() { PhysicalPlan plan = new AggregationOperator(testScan(numericInputs), - Collections.singletonList(DSL.named("count", dsl.count(DSL.ref("float", FLOAT)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), Collections.singletonList(DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL .literal(1), "")))); List result = execute(plan); @@ -413,7 +412,7 @@ public void float_field() { ExprValueUtils.tupleValue(ImmutableMap.of("span", 5F, "count", 1)))); plan = new AggregationOperator(testScan(numericInputs), - Collections.singletonList(DSL.named("count", dsl.count(DSL.ref("float", FLOAT)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), Collections.singletonList(DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL .literal(1.5), "")))); result = execute(plan); @@ -427,7 +426,7 @@ public void float_field() { @Test public void double_field() { PhysicalPlan plan = new AggregationOperator(testScan(numericInputs), - Collections.singletonList(DSL.named("count", dsl.count(DSL.ref("double", DOUBLE)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), Collections.singletonList(DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL .literal(1), "")))); List result = execute(plan); @@ -438,7 +437,7 @@ public void double_field() { ExprValueUtils.tupleValue(ImmutableMap.of("span", 5D, "count", 1)))); plan = new AggregationOperator(testScan(numericInputs), - Collections.singletonList(DSL.named("count", dsl.count(DSL.ref("double", DOUBLE)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), Collections.singletonList(DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL .literal(1.5), "")))); result = execute(plan); @@ -452,7 +451,7 @@ public void double_field() { @Test public void twoBucketsSpanAndLong() { PhysicalPlan plan = new AggregationOperator(testScan(compoundInputs), - Collections.singletonList(DSL.named("max", dsl.max(DSL.ref("errors", INTEGER)))), + Collections.singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), DSL.named("region", DSL.ref("region", STRING))) @@ -471,7 +470,7 @@ public void twoBucketsSpanAndLong() { )); plan = new AggregationOperator(testScan(compoundInputs), - Collections.singletonList(DSL.named("max", dsl.max(DSL.ref("errors", INTEGER)))), + Collections.singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), DSL.named("region", DSL.ref("region", STRING)), @@ -500,7 +499,7 @@ public void twoBucketsSpanAndLong() { @Test public void aggregate_with_two_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator(testScan(compoundInputs), - Collections.singletonList(DSL.named("sum", dsl.sum(DSL.ref("errors", INTEGER)))), + Collections.singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("host", DSL.ref("host", STRING)), DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); @@ -541,7 +540,7 @@ public void aggregate_with_two_groups_with_windowing() { @Test public void aggregate_with_three_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator(testScan(compoundInputs), - Collections.singletonList(DSL.named("sum", dsl.sum(DSL.ref("errors", INTEGER)))), + Collections.singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("host", DSL.ref("host", STRING)), DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), @@ -591,7 +590,7 @@ public void aggregate_with_three_groups_with_windowing() { public void copyOfAggregationOperatorShouldSame() { AggregationOperator plan = new AggregationOperator(testScan(datetimeInputs), Collections.singletonList(DSL - .named("count", dsl.count(DSL.ref("second", TIMESTAMP)))), + .named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), Collections.singletonList(DSL .named("span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); AggregationOperator copy = new AggregationOperator(plan.getInput(), plan.getAggregatorList(), diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/EvalOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/EvalOperatorTest.java index 8eb7cc5656..d32622834b 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/EvalOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/EvalOperatorTest.java @@ -43,7 +43,7 @@ public void create_new_field_that_contain_the_result_of_a_calculation() { inputPlan, ImmutablePair.of( DSL.ref("velocity", DOUBLE), - dsl.divide(DSL.ref("distance", INTEGER), DSL.ref("time", INTEGER)))); + DSL.divide(DSL.ref("distance", INTEGER), DSL.ref("time", INTEGER)))); assertThat( execute(plan), allOf( @@ -63,11 +63,11 @@ public void create_multiple_field_using_field_defined_in_input_tuple() { eval( inputPlan, ImmutablePair.of( - DSL.ref("velocity", DOUBLE), dsl.divide(DSL.ref("distance", INTEGER), DSL.ref( + DSL.ref("velocity", DOUBLE), DSL.divide(DSL.ref("distance", INTEGER), DSL.ref( "time", INTEGER))), ImmutablePair.of( DSL.ref("doubleDistance", INTEGER), - dsl.multiply(DSL.ref("distance", INTEGER), DSL.literal(2)))); + DSL.multiply(DSL.ref("distance", INTEGER), DSL.literal(2)))); assertThat( execute(plan), allOf( @@ -88,11 +88,11 @@ public void create_multiple_filed_using_field_defined_in_eval_operator() { eval( inputPlan, ImmutablePair.of( - DSL.ref("velocity", INTEGER), dsl.divide(DSL.ref("distance", INTEGER), DSL.ref( + DSL.ref("velocity", INTEGER), DSL.divide(DSL.ref("distance", INTEGER), DSL.ref( "time", INTEGER))), ImmutablePair.of( DSL.ref("doubleVelocity", INTEGER), - dsl.multiply(DSL.ref("velocity", INTEGER), DSL.literal(2)))); + DSL.multiply(DSL.ref("velocity", INTEGER), DSL.literal(2)))); assertThat( execute(plan), allOf( @@ -114,7 +114,7 @@ public void replace_existing_field() { inputPlan, ImmutablePair.of( DSL.ref("distance", INTEGER), - dsl.multiply(DSL.ref("distance", INTEGER), DSL.literal(2)))); + DSL.multiply(DSL.ref("distance", INTEGER), DSL.literal(2)))); assertThat( execute(plan), allOf( diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/FilterOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/FilterOperatorTest.java index fc0b941938..288b4bf661 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/FilterOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/FilterOperatorTest.java @@ -34,7 +34,7 @@ class FilterOperatorTest extends PhysicalPlanTestBase { @Test public void filterTest() { FilterOperator plan = new FilterOperator(new TestScan(), - dsl.equal(DSL.ref("response", INTEGER), DSL.literal(404))); + DSL.equal(DSL.ref("response", INTEGER), DSL.literal(404))); List result = execute(plan); assertEquals(1, result.size()); assertThat(result, containsInAnyOrder(ExprValueUtils @@ -51,7 +51,7 @@ public void nullValueShouldBeenIgnored() { when(inputPlan.next()).thenReturn(new ExprTupleValue(value)); FilterOperator plan = new FilterOperator(inputPlan, - dsl.equal(DSL.ref("response", INTEGER), DSL.literal(404))); + DSL.equal(DSL.ref("response", INTEGER), DSL.literal(404))); List result = execute(plan); assertEquals(0, result.size()); } @@ -64,7 +64,7 @@ public void missingValueShouldBeenIgnored() { when(inputPlan.next()).thenReturn(new ExprTupleValue(value)); FilterOperator plan = new FilterOperator(inputPlan, - dsl.equal(DSL.ref("response", INTEGER), DSL.literal(404))); + DSL.equal(DSL.ref("response", INTEGER), DSL.literal(404))); List result = execute(plan); assertEquals(0, result.size()); } diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java index 8780177c88..735b914d3e 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java @@ -50,12 +50,12 @@ public void print_physical_plan() { new TestScan(), 1, 1 ), - dsl.equal(DSL.ref("response", INTEGER), DSL.literal(10))), + DSL.equal(DSL.ref("response", INTEGER), DSL.literal(10))), CommandType.TOP, ImmutableList.of(), DSL.ref("response", INTEGER)), ImmutableList - .of(DSL.named("avg(response)", dsl.avg(DSL.ref("response", INTEGER)))), + .of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), ImmutableList.of()), ImmutableMap.of(DSL.ref("ivalue", INTEGER), DSL.ref("avg(response)", DOUBLE))), named("ref", ref)), @@ -77,14 +77,14 @@ public void print_physical_plan() { public void test_PhysicalPlanVisitor_should_return_null() { PhysicalPlan filter = PhysicalPlanDSL.filter( - new TestScan(), dsl.equal(DSL.ref("response", INTEGER), DSL.literal(10))); + new TestScan(), DSL.equal(DSL.ref("response", INTEGER), DSL.literal(10))); assertNull(filter.accept(new PhysicalPlanNodeVisitor() { }, null)); PhysicalPlan aggregation = PhysicalPlanDSL.agg( filter, ImmutableList.of(DSL.named("avg(response)", - dsl.avg(DSL.ref("response", INTEGER)))), ImmutableList.of()); + DSL.avg(DSL.ref("response", INTEGER)))), ImmutableList.of()); assertNull(aggregation.accept(new PhysicalPlanNodeVisitor() { }, null)); @@ -99,7 +99,7 @@ public void test_PhysicalPlanVisitor_should_return_null() { assertNull(project.accept(new PhysicalPlanNodeVisitor() { }, null)); - PhysicalPlan window = PhysicalPlanDSL.window(plan, named(dsl.rowNumber()), + PhysicalPlan window = PhysicalPlanDSL.window(plan, named(DSL.rowNumber()), new WindowDefinition(emptyList(), emptyList())); assertNull(window.accept(new PhysicalPlanNodeVisitor() { }, null)); diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java index 73af929fcd..97bf8ebb79 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java @@ -11,7 +11,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.junit.jupiter.api.extension.ExtendWith; import org.opensearch.sql.data.model.ExprDateValue; import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimeValue; @@ -20,23 +19,12 @@ import org.opensearch.sql.data.model.ExprValueUtils; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.exception.ExpressionEvaluationException; -import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.ReferenceExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@Configuration -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class}) public class PhysicalPlanTestBase { - @Autowired - protected DSL dsl; protected static final List countTestInputs = new ImmutableList.Builder() .add(ExprValueUtils.tupleValue(ImmutableMap diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java index 5e7a3b2d48..a0da659a38 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java @@ -35,7 +35,7 @@ public void avg_aggregation_rename() { PhysicalPlan plan = new RenameOperator( new AggregationOperator(new TestScan(), Collections - .singletonList(DSL.named("avg(response)", dsl.avg(DSL.ref("response", INTEGER)))), + .singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))), ImmutableMap.of(DSL.ref("avg(response)", DOUBLE), DSL.ref("avg", DOUBLE)) ); diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/WindowOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/WindowOperatorTest.java index 0fa8fdcbc8..7f727d391b 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/WindowOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/WindowOperatorTest.java @@ -40,7 +40,7 @@ class WindowOperatorTest extends PhysicalPlanTestBase { @Test void test_ranking_window_function() { - window(dsl.rank()) + window(DSL.rank()) .partitionBy(ref("action", STRING)) .sortBy(DEFAULT_ASC, ref("response", INTEGER)) .expectNext(ImmutableMap.of( @@ -64,7 +64,7 @@ void test_ranking_window_function() { @SuppressWarnings("unchecked") @Test void test_aggregate_window_function() { - window(new AggregateWindowFunction(dsl.sum(ref("response", INTEGER)))) + window(new AggregateWindowFunction(DSL.sum(ref("response", INTEGER)))) .partitionBy(ref("action", STRING)) .sortBy(DEFAULT_ASC, ref("response", INTEGER)) .expectNext(ImmutableMap.of( @@ -88,7 +88,7 @@ void test_aggregate_window_function() { @SuppressWarnings("unchecked") @Test void test_aggregate_window_function_without_sort_key() { - window(new AggregateWindowFunction(dsl.sum(ref("response", INTEGER)))) + window(new AggregateWindowFunction(DSL.sum(ref("response", INTEGER)))) .expectNext(ImmutableMap.of( "ip", "209.160.24.63", "action", "GET", "response", 200, "referer", "www.amazon.com", "sum(response)", 1504)) diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/catalog/CatalogTableScanTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/catalog/CatalogTableScanTest.java deleted file mode 100644 index cf9b5fe016..0000000000 --- a/core/src/test/java/org/opensearch/sql/planner/physical/catalog/CatalogTableScanTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * * Copyright OpenSearch Contributors - * * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.opensearch.sql.planner.physical.catalog; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.when; - -import com.google.common.collect.ImmutableMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Set; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.catalog.CatalogService; -import org.opensearch.sql.catalog.model.Catalog; -import org.opensearch.sql.catalog.model.ConnectorType; -import org.opensearch.sql.data.model.ExprTupleValue; -import org.opensearch.sql.data.model.ExprValueUtils; -import org.opensearch.sql.storage.StorageEngine; - -@ExtendWith(MockitoExtension.class) -public class CatalogTableScanTest { - - @Mock - private CatalogService catalogService; - - @Mock - private StorageEngine storageEngine; - - private CatalogTableScan catalogTableScan; - - @BeforeEach - private void setUp() { - catalogTableScan = new CatalogTableScan(catalogService); - } - - @Test - void testExplain() { - assertEquals("GetCatalogRequestRequest{}", catalogTableScan.explain()); - } - - @Test - void testIterator() { - Set catalogSet = new HashSet<>(); - catalogSet.add(new Catalog("prometheus", ConnectorType.PROMETHEUS, storageEngine)); - catalogSet.add(new Catalog("opensearch", ConnectorType.OPENSEARCH, storageEngine)); - when(catalogService.getCatalogs()).thenReturn(catalogSet); - - assertFalse(catalogTableScan.hasNext()); - catalogTableScan.open(); - assertTrue(catalogTableScan.hasNext()); - for (Catalog catalog : catalogSet) { - assertEquals(new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( - "DATASOURCE_NAME", ExprValueUtils.stringValue(catalog.getName()), - "CONNECTOR_TYPE", ExprValueUtils.stringValue(catalog.getConnectorType().name())))), - catalogTableScan.next()); - } - } - -} diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableScanTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableScanTest.java new file mode 100644 index 0000000000..2f7188a248 --- /dev/null +++ b/core/src/test/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableScanTest.java @@ -0,0 +1,70 @@ +/* + * + * * Copyright OpenSearch Contributors + * * SPDX-License-Identifier: Apache-2.0 + * + */ + +package org.opensearch.sql.planner.physical.datasource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; + +import com.google.common.collect.ImmutableMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.opensearch.sql.data.model.ExprTupleValue; +import org.opensearch.sql.data.model.ExprValueUtils; +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.storage.StorageEngine; + +@ExtendWith(MockitoExtension.class) +public class DataSourceTableScanTest { + + @Mock + private DataSourceService dataSourceService; + + @Mock + private StorageEngine storageEngine; + + private DataSourceTableScan dataSourceTableScan; + + @BeforeEach + private void setUp() { + dataSourceTableScan = new DataSourceTableScan(dataSourceService); + } + + @Test + void testExplain() { + assertEquals("GetDataSourcesInfoRequest{}", dataSourceTableScan.explain()); + } + + @Test + void testIterator() { + Set dataSourceSet = new HashSet<>(); + dataSourceSet.add(new DataSource("prometheus", DataSourceType.PROMETHEUS, storageEngine)); + dataSourceSet.add(new DataSource("opensearch", DataSourceType.OPENSEARCH, storageEngine)); + when(dataSourceService.getDataSources()).thenReturn(dataSourceSet); + + assertFalse(dataSourceTableScan.hasNext()); + dataSourceTableScan.open(); + assertTrue(dataSourceTableScan.hasNext()); + for (DataSource dataSource : dataSourceSet) { + assertEquals(new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( + "DATASOURCE_NAME", ExprValueUtils.stringValue(dataSource.getName()), + "CONNECTOR_TYPE", ExprValueUtils.stringValue(dataSource.getConnectorType().name())))), + dataSourceTableScan.next()); + } + } + +} diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/catalog/CatalogTableTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableTest.java similarity index 68% rename from core/src/test/java/org/opensearch/sql/planner/physical/catalog/CatalogTableTest.java rename to core/src/test/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableTest.java index 531fc40ba8..dd5d49d08e 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/catalog/CatalogTableTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/datasource/DataSourceTableTest.java @@ -5,11 +5,12 @@ * */ -package org.opensearch.sql.planner.physical.catalog; +package org.opensearch.sql.planner.physical.datasource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opensearch.sql.utils.SystemIndexUtils.DATASOURCES_TABLE_NAME; import java.util.HashMap; import java.util.Map; @@ -17,22 +18,22 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.catalog.CatalogService; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; +import org.opensearch.sql.datasource.DataSourceService; import org.opensearch.sql.planner.logical.LogicalPlanDSL; import org.opensearch.sql.planner.physical.PhysicalPlan; @ExtendWith(MockitoExtension.class) -public class CatalogTableTest { +public class DataSourceTableTest { @Mock - private CatalogService catalogService; + private DataSourceService dataSourceService; @Test void testGetFieldTypes() { - CatalogTable catalogTable = new CatalogTable(catalogService); - Map fieldTypes = catalogTable.getFieldTypes(); + DataSourceTable dataSourceTable = new DataSourceTable(dataSourceService); + Map fieldTypes = dataSourceTable.getFieldTypes(); Map expectedTypes = new HashMap<>(); expectedTypes.put("DATASOURCE_NAME", ExprCoreType.STRING); expectedTypes.put("CONNECTOR_TYPE", ExprCoreType.STRING); @@ -41,10 +42,11 @@ void testGetFieldTypes() { @Test void testImplement() { - CatalogTable catalogTable = new CatalogTable(catalogService); + DataSourceTable dataSourceTable = new DataSourceTable(dataSourceService); PhysicalPlan physicalPlan - = catalogTable.implement(LogicalPlanDSL.relation(".CATALOGS", catalogTable)); - assertTrue(physicalPlan instanceof CatalogTableScan); + = dataSourceTable.implement( + LogicalPlanDSL.relation(DATASOURCES_TABLE_NAME, dataSourceTable)); + assertTrue(physicalPlan instanceof DataSourceTableScan); } // todo. temporary added for code coverage. remove if required. @@ -52,7 +54,7 @@ void testImplement() { void testExist() { UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class, - () -> new CatalogTable(catalogService).exists()); + () -> new DataSourceTable(dataSourceService).exists()); assertEquals("Unsupported Operation", exception.getMessage()); } @@ -61,7 +63,7 @@ void testExist() { void testCreateTable() { UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class, - () -> new CatalogTable(catalogService).create(new HashMap<>())); + () -> new DataSourceTable(dataSourceService).create(new HashMap<>())); assertEquals("Unsupported Operation", exception.getMessage()); } diff --git a/core/src/test/java/org/opensearch/sql/storage/StorageEngineTest.java b/core/src/test/java/org/opensearch/sql/storage/StorageEngineTest.java index b0da30212d..0e969c6dac 100644 --- a/core/src/test/java/org/opensearch/sql/storage/StorageEngineTest.java +++ b/core/src/test/java/org/opensearch/sql/storage/StorageEngineTest.java @@ -16,7 +16,7 @@ public class StorageEngineTest { @Test void testFunctionsMethod() { - StorageEngine k = (catalogSchemaName, tableName) -> null; + StorageEngine k = (dataSourceSchemaName, tableName) -> null; Assertions.assertEquals(Collections.emptyList(), k.getFunctions()); } diff --git a/docs/user/general/identifiers.rst b/docs/user/general/identifiers.rst index 8bb42bb7e7..fad2fa4b23 100644 --- a/docs/user/general/identifiers.rst +++ b/docs/user/general/identifiers.rst @@ -231,7 +231,7 @@ tableName = ``http_requests_total``. 2. ``logs.12.13.1`` -datasourceName = ``@opensearch`` [Resolves to default @opensearch connector since [my_prometheus] is the only catalog configured name.] +datasourceName = ``@opensearch`` [Resolves to default @opensearch connector since [my_prometheus] is the only dataSource configured.] schemaName = ``default`` [No supported schema found, so default to `default`]. @@ -249,7 +249,7 @@ tableName = ``http_requests_total``. 4. ``prometheus.http_requests_total`` -datasourceName = ``@opensearch`` [Resolves to default @opensearch connector since [my_prometheus] is the only datasource configured name.] +datasourceName = ``@opensearch`` [Resolves to default @opensearch connector since [my_prometheus] is the only datasource configured.] schemaName = ``default`` [No supported schema found, so default to `default`]. @@ -257,7 +257,7 @@ tableName = ``prometheus.http_requests_total``. 5. ``prometheus.default.http_requests_total.1.2.3`` -datasourceName = ``@opensearch`` [Resolves to default @opensearch connector since [my_prometheus] is the only catalog configured name.] +datasourceName = ``@opensearch`` [Resolves to default @opensearch connector since [my_prometheus] is the only dataSource configured.] schemaName = ``default`` [No supported schema found, so default to `default`]. diff --git a/docs/user/limitations/limitations.rst b/docs/user/limitations/limitations.rst index c2163af23d..d6e763a73d 100644 --- a/docs/user/limitations/limitations.rst +++ b/docs/user/limitations/limitations.rst @@ -18,7 +18,7 @@ In this doc, the restrictions and limitations of SQL plugin is covered as follow Limitations on Identifiers ========================== -Using OpenSearch cluster name as catalog name to qualify an index name, such as ``my_cluster.my_index``, is not supported for now. +Using OpenSearch cluster name as dataSource name to qualify an index name, such as ``my_cluster.my_index``, is not supported for now. Limitations on Fields ===================== diff --git a/docs/user/ppl/admin/prometheus_connector.rst b/docs/user/ppl/admin/prometheus_connector.rst index aced79cbdb..fd84f8114c 100644 --- a/docs/user/ppl/admin/prometheus_connector.rst +++ b/docs/user/ppl/admin/prometheus_connector.rst @@ -14,11 +14,11 @@ Prometheus Connector Introduction ============ -This page covers prometheus connector properties for catalog configuration +This page covers prometheus connector properties for dataSource configuration and the nuances associated with prometheus connector. -Prometheus Connector Properties in Catalog Configuration +Prometheus Connector Properties in DataSource Configuration ======================================================== Prometheus Connector Properties. @@ -32,7 +32,7 @@ Prometheus Connector Properties. * If prometheus.auth.type is awssigv4, following are required parameters. * ``prometheus.auth.region``, ``prometheus.auth.access_key`` and ``prometheus.auth.secret_key`` -Example prometheus catalog configuration with different authentications +Example prometheus dataSource configuration with different authentications ======================================================================= No Auth :: diff --git a/docs/user/ppl/cmd/describe.rst b/docs/user/ppl/cmd/describe.rst index 12fcf35ded..a0ecbd3169 100644 --- a/docs/user/ppl/cmd/describe.rst +++ b/docs/user/ppl/cmd/describe.rst @@ -16,9 +16,9 @@ Description Syntax ============ -describe .. +describe .. -* catalog: optional. If catalog is not provided, it resolves to opensearch catalog. +* dataSource: optional. If dataSource is not provided, it resolves to opensearch dataSource. * schema: optional. If schema is not provided, it resolves to default schema. * tablename: mandatory. describe command must specify which tablename to query from. @@ -67,10 +67,10 @@ PPL query:: +----------------+ -Example 3: Fetch metadata for table in prometheus catalog +Example 3: Fetch metadata for table in prometheus dataSource ========================================================= -The example retrieves table info for ``prometheus_http_requests_total`` metric in prometheus catalog. +The example retrieves table info for ``prometheus_http_requests_total`` metric in prometheus dataSource. PPL query:: diff --git a/docs/user/ppl/cmd/stats.rst b/docs/user/ppl/cmd/stats.rst index 3a34e68a7d..d9cca9e314 100644 --- a/docs/user/ppl/cmd/stats.rst +++ b/docs/user/ppl/cmd/stats.rst @@ -13,7 +13,7 @@ Description ============ | Using ``stats`` command to calculate the aggregation from search result. -The following table catalogs the aggregation functions and also indicates how the NULL/MISSING values is handled: +The following table dataSources the aggregation functions and also indicates how the NULL/MISSING values is handled: +----------+-------------+-------------+ | Function | NULL | MISSING | diff --git a/doctest/build.gradle b/doctest/build.gradle index 62efd29b18..a13375d469 100644 --- a/doctest/build.gradle +++ b/doctest/build.gradle @@ -29,19 +29,21 @@ task bootstrap(type: Exec) { task startPrometheus(type: SpawnProcessTask) { doFirst { download.run { - src 'https://github.com/prometheus/prometheus/releases/download/v2.39.1/prometheus-2.39.1.linux-amd64.tar.gz' + src getPrometheusBinaryLocation() dest new File("$projectDir/bin", 'prometheus.tar.gz') } copy { from tarTree("$projectDir/bin/prometheus.tar.gz") into "$projectDir/bin" } - copy { - from "$projectDir/bin/prometheus.yml" - into "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus" + file("$projectDir/bin").eachDir { + if (it.name.startsWith("prometheus-")) { + println "Renaming folder : " + it.name.toString() + println it.renameTo("$projectDir/bin/prometheus") + } } } - command "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus --storage.tsdb.path=$projectDir/bin/prometheus-2.39.1.linux-amd64/data --config.file=$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus.yml" + command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' pidLockFileName '.prom.pid.lock' } @@ -80,6 +82,8 @@ task stopPrometheus() { process.waitFor() } finally { pidFile.delete() + file("$projectDir/bin/prometheus").deleteDir() + file("$projectDir/bin/prometheus.tar.gz").delete() } } } @@ -104,7 +108,7 @@ String mlCommonsPlugin = 'opensearch-ml' testClusters { docTestCluster { - keystore 'plugins.query.federation.datasources.config', new File("$projectDir/catalog", 'catalog.json') + keystore 'plugins.query.federation.datasources.config', new File("$projectDir/datasource", 'datasources.json') // Disable loading of `ML-commons` plugin, because it might be unavailable (not released yet). /* plugin(provider(new Callable(){ diff --git a/doctest/catalog/catalog.json b/doctest/datasource/datasources.json similarity index 100% rename from doctest/catalog/catalog.json rename to doctest/datasource/datasources.json diff --git a/filesystem/src/testFixtures/java/org/opensearch/sql/filesystem/storage/FSDataSourceFactory.java b/filesystem/src/testFixtures/java/org/opensearch/sql/filesystem/storage/FSDataSourceFactory.java new file mode 100644 index 0000000000..6b700aa6d4 --- /dev/null +++ b/filesystem/src/testFixtures/java/org/opensearch/sql/filesystem/storage/FSDataSourceFactory.java @@ -0,0 +1,33 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.filesystem.storage; + +import java.net.URI; +import java.util.concurrent.atomic.AtomicInteger; +import lombok.RequiredArgsConstructor; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.storage.DataSourceFactory; + +@RequiredArgsConstructor +public class FSDataSourceFactory implements DataSourceFactory { + + private final URI basePath; + + private final AtomicInteger result; + + @Override + public DataSourceType getDataSourceType() { + return DataSourceType.FILESYSTEM; + } + + @Override + public DataSource createDataSource(DataSourceMetadata metadata) { + return new DataSource( + metadata.getName(), DataSourceType.FILESYSTEM, new FSStorageEngine(basePath, result)); + } +} diff --git a/filesystem/src/testFixtures/java/org/opensearch/sql/filesystem/storage/FSStorageEngine.java b/filesystem/src/testFixtures/java/org/opensearch/sql/filesystem/storage/FSStorageEngine.java index ba590bcd1e..0826b4c12f 100644 --- a/filesystem/src/testFixtures/java/org/opensearch/sql/filesystem/storage/FSStorageEngine.java +++ b/filesystem/src/testFixtures/java/org/opensearch/sql/filesystem/storage/FSStorageEngine.java @@ -12,7 +12,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.storage.StorageEngine; import org.opensearch.sql.storage.Table; @@ -37,7 +37,7 @@ public FSStorageEngine(URI basePath, AtomicInteger result) { } @Override - public Table getTable(CatalogSchemaName catalogSchemaName, String tableName) { + public Table getTable(DataSourceSchemaName dataSourceSchemaName, String tableName) { return new FSTable(fs, basePath, result); } diff --git a/integ-test/build.gradle b/integ-test/build.gradle index 25197c6b8f..ba6a6b5838 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -38,6 +38,9 @@ apply plugin: 'java' apply plugin: 'io.freefair.lombok' apply plugin: 'com.wiredforcode.spawn' + + + repositories { mavenCentral() maven { url 'https://jitpack.io' } @@ -117,37 +120,46 @@ testClusters.all { testClusters.integTest { plugin ":opensearch-sql-plugin" - keystore 'plugins.query.federation.datasources.config', new File("$projectDir/src/test/resources/catalog/", 'catalog.json') + keystore 'plugins.query.federation.datasources.config', new File("$projectDir/src/test/resources/datasource/", 'datasources.json') } + task startPrometheus(type: SpawnProcessTask) { mustRunAfter ':doctest:doctest' + doFirst { download.run { - src 'https://github.com/prometheus/prometheus/releases/download/v2.39.1/prometheus-2.39.1.linux-amd64.tar.gz' + src getPrometheusBinaryLocation() dest new File("$projectDir/bin", 'prometheus.tar.gz') } copy { from tarTree("$projectDir/bin/prometheus.tar.gz") into "$projectDir/bin" } - copy { - from "$projectDir/bin/prometheus.yml" - into "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus" + file("$projectDir/bin").eachDir { + if (it.name.startsWith("prometheus-")) { + println "Renaming folder : " + it.name.toString() + println it.renameTo("$projectDir/bin/prometheus") + } } } - command "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus --storage.tsdb.path=$projectDir/bin/prometheus-2.39.1.linux-amd64/data --config.file=$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus.yml" + command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' } -task stopPrometheus(type: KillProcessTask) +task stopPrometheus(type: KillProcessTask) { + doLast { + file("$projectDir/bin/prometheus").deleteDir() + file("$projectDir/bin/prometheus.tar.gz").delete() + } +} stopPrometheus.mustRunAfter startPrometheus // Run PPL ITs and new, legacy and comparison SQL ITs with new SQL engine enabled integTest { dependsOn ':opensearch-sql-plugin:bundlePlugin' - dependsOn startPrometheus - finalizedBy stopPrometheus +// dependsOn startPrometheus +// finalizedBy stopPrometheus systemProperty 'tests.security.manager', 'false' systemProperty('project.root', project.projectDir.absolutePath) diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusCatalogCommandsIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java similarity index 98% rename from integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusCatalogCommandsIT.java rename to integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java index 10c1e911ab..292ea26fc1 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusCatalogCommandsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class PrometheusCatalogCommandsIT extends PPLIntegTestCase { +public class PrometheusDataSourceCommandsIT extends PPLIntegTestCase { @Test @SneakyThrows diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/ShowCatalogsCommandIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/ShowDataSourcesCommandIT.java similarity index 83% rename from integ-test/src/test/java/org/opensearch/sql/ppl/ShowCatalogsCommandIT.java rename to integ-test/src/test/java/org/opensearch/sql/ppl/ShowDataSourcesCommandIT.java index e12aa040e3..3614168ab8 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/ShowCatalogsCommandIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/ShowDataSourcesCommandIT.java @@ -16,10 +16,10 @@ import org.json.JSONObject; import org.junit.jupiter.api.Test; -public class ShowCatalogsCommandIT extends PPLIntegTestCase { +public class ShowDataSourcesCommandIT extends PPLIntegTestCase { @Test - public void testShowCatalogsCommands() throws IOException { + public void testShowDataSourcesCommands() throws IOException { JSONObject result = executeQuery("show datasources"); verifyDataRows(result, rows("my_prometheus", "PROMETHEUS"), @@ -32,7 +32,7 @@ public void testShowCatalogsCommands() throws IOException { } @Test - public void testShowCatalogsCommandsWithWhereClause() throws IOException { + public void testShowDataSourcesCommandsWithWhereClause() throws IOException { JSONObject result = executeQuery("show datasources | where CONNECTOR_TYPE='PROMETHEUS'"); verifyDataRows(result, rows("my_prometheus", "PROMETHEUS")); diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java index cf5f930b3b..f0fe041313 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java @@ -6,9 +6,11 @@ package org.opensearch.sql.ppl; +import static org.opensearch.sql.datasource.model.DataSourceMetadata.defaultOpenSearchDataSourceMetadata; import static org.opensearch.sql.protocol.response.format.JsonResponseFormatter.Style.PRETTY; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import java.io.IOException; import java.util.Collections; import java.util.List; @@ -20,37 +22,35 @@ import org.opensearch.client.RestHighLevelClient; import org.opensearch.sql.analysis.Analyzer; import org.opensearch.sql.analysis.ExpressionAnalyzer; -import org.opensearch.sql.catalog.CatalogService; import org.opensearch.sql.common.response.ResponseListener; import org.opensearch.sql.common.setting.Settings; +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.DataSourceServiceImpl; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.ExecutionEngine.QueryResponse; import org.opensearch.sql.executor.QueryManager; import org.opensearch.sql.executor.QueryService; import org.opensearch.sql.executor.execution.QueryPlanFactory; -import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.function.BuiltinFunctionRepository; import org.opensearch.sql.monitor.AlwaysHealthyMonitor; import org.opensearch.sql.opensearch.client.OpenSearchClient; import org.opensearch.sql.opensearch.client.OpenSearchRestClient; import org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine; import org.opensearch.sql.opensearch.executor.protector.OpenSearchExecutionProtector; -import org.opensearch.sql.opensearch.storage.OpenSearchStorageEngine; +import org.opensearch.sql.opensearch.storage.OpenSearchDataSourceFactory; import org.opensearch.sql.planner.Planner; import org.opensearch.sql.planner.optimizer.LogicalPlanOptimizer; -import org.opensearch.sql.plugin.catalog.CatalogServiceImpl; import org.opensearch.sql.ppl.config.PPLServiceConfig; import org.opensearch.sql.ppl.domain.PPLQueryRequest; import org.opensearch.sql.protocol.response.QueryResult; import org.opensearch.sql.protocol.response.format.SimpleJsonResponseFormatter; +import org.opensearch.sql.storage.DataSourceFactory; import org.opensearch.sql.util.ExecuteOnCallerThreadQueryManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Scope; /** @@ -75,9 +75,12 @@ public void init() { new OpenSearchExecutionProtector(new AlwaysHealthyMonitor()))); context.registerBean(OpenSearchClient.class, () -> client); context.registerBean(Settings.class, () -> defaultSettings()); - OpenSearchStorageEngine openSearchStorageEngine = new OpenSearchStorageEngine(client, defaultSettings()); - CatalogServiceImpl.getInstance().registerDefaultOpenSearchCatalog(openSearchStorageEngine); - context.registerBean(CatalogService.class, CatalogServiceImpl::getInstance); + DataSourceService dataSourceService = new DataSourceServiceImpl( + new ImmutableSet.Builder() + .add(new OpenSearchDataSourceFactory(client, defaultSettings())) + .build()); + dataSourceService.addDataSource(defaultOpenSearchDataSourceMetadata()); + context.registerBean(DataSourceService.class, () -> dataSourceService); context.register(StandaloneConfig.class); context.register(PPLServiceConfig.class); context.refresh(); @@ -166,10 +169,9 @@ public InternalRestHighLevelClient(RestClient restClient) { } @Configuration - @Import({ExpressionConfig.class}) static class StandaloneConfig { @Autowired - private CatalogService catalogService; + private DataSourceService dataSourceService; @Autowired private ExecutionEngine executionEngine; @@ -181,21 +183,12 @@ QueryManager queryManager() { @Bean @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) - QueryPlanFactory queryExecutionFactory(BuiltinFunctionRepository functionRepository) { - catalogService - .getCatalogs() - .forEach( - catalog -> - catalog - .getStorageEngine() - .getFunctions() - .forEach( - functionResolver -> - functionRepository.register(catalog.getName(), functionResolver))); + QueryPlanFactory queryExecutionFactory() { + BuiltinFunctionRepository functionRepository = BuiltinFunctionRepository.getInstance(); Analyzer analyzer = new Analyzer(new ExpressionAnalyzer(functionRepository), - catalogService, functionRepository); + dataSourceService, functionRepository); Planner planner = - new Planner(LogicalPlanOptimizer.create(new DSL(functionRepository))); + new Planner(LogicalPlanOptimizer.create()); return new QueryPlanFactory(new QueryService(analyzer, executionEngine, planner)); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/StreamingQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/StreamingQueryIT.java index e1ced8044c..2a00e14d34 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/StreamingQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/StreamingQueryIT.java @@ -7,6 +7,8 @@ import com.carrotsearch.randomizedtesting.ThreadFilter; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -22,21 +24,23 @@ import org.opensearch.sql.analysis.Analyzer; import org.opensearch.sql.analysis.ExpressionAnalyzer; import org.opensearch.sql.ast.dsl.AstDSL; -import org.opensearch.sql.catalog.CatalogService; import org.opensearch.sql.common.response.ResponseListener; +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.DataSourceServiceImpl; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; import org.opensearch.sql.executor.DefaultExecutionEngine; import org.opensearch.sql.executor.DefaultQueryManager; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.QueryId; import org.opensearch.sql.executor.QueryService; import org.opensearch.sql.executor.execution.StreamingQueryPlan; -import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.function.BuiltinFunctionRepository; +import org.opensearch.sql.filesystem.storage.FSDataSourceFactory; import org.opensearch.sql.filesystem.storage.FSStorageEngine; import org.opensearch.sql.planner.Planner; import org.opensearch.sql.planner.optimizer.LogicalPlanOptimizer; -import org.opensearch.sql.plugin.catalog.CatalogServiceImpl; +import org.opensearch.sql.storage.DataSourceFactory; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @ThreadLeakFilters(filters = {StreamingQueryIT.HadoopFSThreadsFilter.class}) @@ -44,6 +48,10 @@ public class StreamingQueryIT extends PPLIntegTestCase { private static final int INTERVAL_IN_SECONDS = 1; + private static final String DATASOURCE_NAME = "fs"; + + private static final String TABLE_NAME = "mock"; + private final AtomicInteger result = new AtomicInteger(0); private Source source; @@ -68,12 +76,12 @@ public void testStreamingQuery() throws IOException, InterruptedException { } @After - void clean() throws InterruptedException, IOException { + public void clean() throws InterruptedException, IOException { query.close(); source.close(); } - StreamingQuery fromFile(java.nio.file.Path path) throws IOException { + StreamingQuery fromFile(java.nio.file.Path path) { return new StreamingQuery(path); } @@ -117,17 +125,21 @@ class StreamingQuery { public StreamingQuery(java.nio.file.Path tempDir) { result.set(0); context = new AnnotationConfigApplicationContext(); - context.register(ExpressionConfig.class); context.refresh(); - BuiltinFunctionRepository functionRepository = - context.getBean(BuiltinFunctionRepository.class); - CatalogService catalogService = CatalogServiceImpl.getInstance(); - storageEngine = new FSStorageEngine(tempDir.toUri(), result); - CatalogServiceImpl.getInstance().registerDefaultOpenSearchCatalog(storageEngine); + DataSourceService dataSourceService = + new DataSourceServiceImpl( + new ImmutableSet.Builder() + .add(new FSDataSourceFactory(tempDir.toUri(), result)) + .build()); + dataSourceService.addDataSource(fsDataSourceMetadata()); + context.registerBean(DataSourceService.class, () -> dataSourceService); + storageEngine = + (FSStorageEngine) dataSourceService.getDataSource(DATASOURCE_NAME).getStorageEngine(); + final BuiltinFunctionRepository functionRepository = BuiltinFunctionRepository.getInstance(); Analyzer analyzer = new Analyzer( - new ExpressionAnalyzer(functionRepository), catalogService, functionRepository); - Planner planner = new Planner(LogicalPlanOptimizer.create(new DSL(functionRepository))); + new ExpressionAnalyzer(functionRepository), dataSourceService, functionRepository); + Planner planner = new Planner(LogicalPlanOptimizer.create()); queryManager = DefaultQueryManager.defaultQueryManager(); queryService = new QueryService(analyzer, new DefaultExecutionEngine(), planner); @@ -137,7 +149,7 @@ public StreamingQuery run() { queryManager.submit( new StreamingQueryPlan( queryId, - AstDSL.relation("mock"), + AstDSL.relation(AstDSL.qualifiedName(DATASOURCE_NAME, "default", TABLE_NAME)), queryService, new ResponseListener<>() { @Override @@ -178,4 +190,12 @@ public boolean reject(Thread t) { return t.getName().contains("StatisticsDataReferenceCleaner"); } } + + private DataSourceMetadata fsDataSourceMetadata() { + DataSourceMetadata dataSourceMetadata = new DataSourceMetadata(); + dataSourceMetadata.setName(DATASOURCE_NAME); + dataSourceMetadata.setConnector(DataSourceType.FILESYSTEM); + dataSourceMetadata.setProperties(ImmutableMap.of()); + return dataSourceMetadata; + } } diff --git a/integ-test/src/test/resources/catalog/catalog.json b/integ-test/src/test/resources/datasource/datasources.json similarity index 100% rename from integ-test/src/test/resources/catalog/catalog.json rename to integ-test/src/test/resources/datasource/datasources.json diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/plugin/RestSQLQueryActionTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/plugin/RestSQLQueryActionTest.java index 4c9afe802e..3eafbd32d9 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/plugin/RestSQLQueryActionTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/plugin/RestSQLQueryActionTest.java @@ -27,7 +27,7 @@ import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestRequest; -import org.opensearch.sql.catalog.CatalogService; +import org.opensearch.sql.datasource.DataSourceService; import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.QueryManager; @@ -66,7 +66,7 @@ public void setup() { context = new AnnotationConfigApplicationContext(); context.registerBean(StorageEngine.class, () -> Mockito.mock(StorageEngine.class)); context.registerBean(ExecutionEngine.class, () -> Mockito.mock(ExecutionEngine.class)); - context.registerBean(CatalogService.class, () -> Mockito.mock(CatalogService.class)); + context.registerBean(DataSourceService.class, () -> Mockito.mock(DataSourceService.class)); context.registerBean(QueryManager.class, () -> queryManager); context.registerBean(QueryPlanFactory.class, () -> factory); context.register(SQLServiceConfig.class); diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/OpenSearchDataSourceFactory.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/OpenSearchDataSourceFactory.java new file mode 100644 index 0000000000..011f6236fb --- /dev/null +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/OpenSearchDataSourceFactory.java @@ -0,0 +1,34 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.opensearch.storage; + +import lombok.RequiredArgsConstructor; +import org.opensearch.sql.common.setting.Settings; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.opensearch.client.OpenSearchClient; +import org.opensearch.sql.storage.DataSourceFactory; + +@RequiredArgsConstructor +public class OpenSearchDataSourceFactory implements DataSourceFactory { + + /** OpenSearch client connection. */ + private final OpenSearchClient client; + + private final Settings settings; + + @Override + public DataSourceType getDataSourceType() { + return DataSourceType.OPENSEARCH; + } + + @Override + public DataSource createDataSource(DataSourceMetadata metadata) { + return new DataSource(metadata.getName(), DataSourceType.OPENSEARCH, + new OpenSearchStorageEngine(client, settings)); + } +} diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/OpenSearchStorageEngine.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/OpenSearchStorageEngine.java index 9a9847dd8c..4a3393abc9 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/OpenSearchStorageEngine.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/OpenSearchStorageEngine.java @@ -9,7 +9,7 @@ import static org.opensearch.sql.utils.SystemIndexUtils.isSystemIndex; import lombok.RequiredArgsConstructor; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.common.setting.Settings; import org.opensearch.sql.opensearch.client.OpenSearchClient; import org.opensearch.sql.opensearch.storage.system.OpenSearchSystemIndex; @@ -26,7 +26,7 @@ public class OpenSearchStorageEngine implements StorageEngine { private final Settings settings; @Override - public Table getTable(CatalogSchemaName catalogSchemaName, String name) { + public Table getTable(DataSourceSchemaName dataSourceSchemaName, String name) { if (isSystemIndex(name)) { return new OpenSearchSystemIndex(client, name); } else { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDataTypeRecognitionTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDataTypeRecognitionTest.java index d7ec5bee5e..22ccff9d25 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDataTypeRecognitionTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDataTypeRecognitionTest.java @@ -13,7 +13,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.opensearch.sql.data.model.ExprValue; 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; @@ -22,8 +21,6 @@ public class OpenSearchDataTypeRecognitionTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - @ParameterizedTest @MethodSource("types") public void typeof(String expected, ExprValue value) { @@ -42,6 +39,6 @@ private static Stream types() { } private String typeofGetValue(ExprValue input) { - return dsl.typeof(DSL.literal(input)).valueOf().stringValue(); + return DSL.typeof(DSL.literal(input)).valueOf().stringValue(); } } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/logical/OpenSearchLogicOptimizerTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/logical/OpenSearchLogicOptimizerTest.java index df42a2b201..31ad2b2ee3 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/logical/OpenSearchLogicOptimizerTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/logical/OpenSearchLogicOptimizerTest.java @@ -33,7 +33,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.sql.ast.tree.Sort; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.opensearch.utils.Utils; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.optimizer.LogicalPlanOptimizer; @@ -42,8 +41,6 @@ @ExtendWith(MockitoExtension.class) class OpenSearchLogicOptimizerTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - @Mock private Table table; @@ -55,7 +52,7 @@ void project_filter_merge_with_relation() { assertEquals( project( indexScan("schema", - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), ImmutableSet.of(DSL.ref("intV", INTEGER))), DSL.named("i", DSL.ref("intV", INTEGER)) ), @@ -63,7 +60,7 @@ void project_filter_merge_with_relation() { project( filter( relation("schema", table), - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ), DSL.named("i", DSL.ref("intV", INTEGER))) ) @@ -79,9 +76,9 @@ void aggregation_merge_relation() { project( indexScanAgg("schema", ImmutableList .of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)))), + DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("longV", - dsl.abs(DSL.ref("longV", LONG))))), + DSL.abs(DSL.ref("longV", LONG))))), DSL.named("AVG(intV)", DSL.ref("AVG(intV)", DOUBLE))), optimize( project( @@ -89,9 +86,9 @@ void aggregation_merge_relation() { relation("schema", table), ImmutableList .of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)))), + DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("longV", - dsl.abs(DSL.ref("longV", LONG))))), + DSL.abs(DSL.ref("longV", LONG))))), DSL.named("AVG(intV)", DSL.ref("AVG(intV)", DOUBLE))) ) ); @@ -105,25 +102,25 @@ void aggregation_merge_filter_relation() { assertEquals( project( indexScanAgg("schema", - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), ImmutableList .of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)))), + DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("longV", - dsl.abs(DSL.ref("longV", LONG))))), + DSL.abs(DSL.ref("longV", LONG))))), DSL.named("AVG(intV)", DSL.ref("AVG(intV)", DOUBLE))), optimize( project( aggregation( filter( relation("schema", table), - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ), ImmutableList .of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)))), + DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("longV", - dsl.abs(DSL.ref("longV", LONG))))), + DSL.abs(DSL.ref("longV", LONG))))), DSL.named("AVG(intV)", DSL.ref("AVG(intV)", DOUBLE))) ) ); @@ -135,26 +132,26 @@ void aggregation_cant_merge_indexScan_with_project() { assertEquals( aggregation( OpenSearchLogicalIndexScan.builder().relationName("schema") - .filter(dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1)))) + .filter(DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1)))) .projectList(ImmutableSet.of(DSL.ref("intV", INTEGER))) .build(), ImmutableList .of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)))), + DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("longV", - dsl.abs(DSL.ref("longV", LONG))))), + DSL.abs(DSL.ref("longV", LONG))))), optimize( aggregation( OpenSearchLogicalIndexScan.builder().relationName("schema") - .filter(dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1)))) + .filter(DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1)))) .projectList( ImmutableSet.of(DSL.ref("intV", INTEGER))) .build(), ImmutableList .of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)))), + DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("longV", - dsl.abs(DSL.ref("longV", LONG)))))) + DSL.abs(DSL.ref("longV", LONG)))))) ); } @@ -199,14 +196,14 @@ void sort_merge_with_indexScan() { void sort_filter_merge_with_relation() { assertEquals( indexScan("schema", - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("longV", LONG)) ), optimize( sort( filter( relation("schema", table), - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ), Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("longV", LONG)) ) @@ -219,12 +216,12 @@ void sort_with_expression_cannot_merge_with_relation() { assertEquals( sort( relation("schema", table), - Pair.of(Sort.SortOption.DEFAULT_ASC, dsl.abs(DSL.ref("intV", INTEGER))) + Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.abs(DSL.ref("intV", INTEGER))) ), optimize( sort( relation("schema", table), - Pair.of(Sort.SortOption.DEFAULT_ASC, dsl.abs(DSL.ref("intV", INTEGER))) + Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.abs(DSL.ref("intV", INTEGER))) ) ) ); @@ -238,7 +235,7 @@ void sort_merge_indexagg() { assertEquals( project( indexScanAgg("schema", - ImmutableList.of(DSL.named("AVG(intV)", dsl.avg(DSL.ref("intV", INTEGER)))), + ImmutableList.of(DSL.named("AVG(intV)", DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING))), ImmutableList .of(Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("stringV", STRING)))), @@ -249,7 +246,7 @@ void sort_merge_indexagg() { aggregation( relation("schema", table), ImmutableList - .of(DSL.named("AVG(intV)", dsl.avg(DSL.ref("intV", INTEGER)))), + .of(DSL.named("AVG(intV)", DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("stringV", STRING)) ), @@ -266,7 +263,7 @@ void sort_merge_indexagg_nulls_last() { assertEquals( project( indexScanAgg("schema", - ImmutableList.of(DSL.named("AVG(intV)", dsl.avg(DSL.ref("intV", INTEGER)))), + ImmutableList.of(DSL.named("AVG(intV)", DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING))), ImmutableList .of(Pair.of(Sort.SortOption.DEFAULT_DESC, DSL.ref("stringV", STRING)))), @@ -277,7 +274,7 @@ void sort_merge_indexagg_nulls_last() { aggregation( relation("schema", table), ImmutableList - .of(DSL.named("AVG(intV)", dsl.avg(DSL.ref("intV", INTEGER)))), + .of(DSL.named("AVG(intV)", DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), Pair.of(Sort.SortOption.DEFAULT_DESC, DSL.ref("stringV", STRING)) ), @@ -296,14 +293,14 @@ void sort_refer_to_aggregator_should_not_merge_with_indexAgg() { assertEquals( sort( indexScanAgg("schema", - ImmutableList.of(DSL.named("AVG(intV)", dsl.avg(DSL.ref("intV", INTEGER)))), + ImmutableList.of(DSL.named("AVG(intV)", DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), Pair.of(Sort.SortOption.DEFAULT_DESC, DSL.ref("AVG(intV)", INTEGER)) ), optimize( sort( indexScanAgg("schema", - ImmutableList.of(DSL.named("AVG(intV)", dsl.avg(DSL.ref("intV", INTEGER)))), + ImmutableList.of(DSL.named("AVG(intV)", DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), Pair.of(Sort.SortOption.DEFAULT_DESC, DSL.ref("AVG(intV)", INTEGER)) ) @@ -319,7 +316,7 @@ void sort_with_customized_option_should_merge_with_indexAgg() { assertEquals( indexScanAgg( "schema", - ImmutableList.of(DSL.named("AVG(intV)", dsl.avg(DSL.ref("intV", INTEGER)))), + ImmutableList.of(DSL.named("AVG(intV)", DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING))), ImmutableList.of( Pair.of( @@ -329,7 +326,7 @@ void sort_with_customized_option_should_merge_with_indexAgg() { sort( indexScanAgg( "schema", - ImmutableList.of(DSL.named("AVG(intV)", dsl.avg(DSL.ref("intV", INTEGER)))), + ImmutableList.of(DSL.named("AVG(intV)", DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), Pair.of( new Sort.SortOption(Sort.SortOrder.ASC, Sort.NullOrder.NULL_LAST), @@ -360,7 +357,7 @@ void limit_merge_with_index_scan() { assertEquals( project( indexScan("schema", - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), 1, 1, projects(DSL.ref("intV", INTEGER)) ), @@ -371,7 +368,7 @@ void limit_merge_with_index_scan() { limit( filter( relation("schema", table), - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ), 1, 1 ), DSL.named("intV", DSL.ref("intV", INTEGER))) @@ -384,7 +381,7 @@ void limit_merge_with_index_scan_sort() { assertEquals( project( indexScan("schema", - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))), 1, 1, Utils.sort(DSL.ref("longV", LONG), Sort.SortOption.DEFAULT_ASC), projects(DSL.ref("intV", INTEGER)) @@ -397,7 +394,7 @@ void limit_merge_with_index_scan_sort() { sort( filter( relation("schema", table), - dsl.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) + DSL.equal(DSL.ref("intV", INTEGER), DSL.literal(integerValue(1))) ), Pair.of(Sort.SortOption.DEFAULT_ASC, DSL.ref("longV", LONG)) ), 1, 1 @@ -416,9 +413,9 @@ void aggregation_cant_merge_index_scan_with_limit() { indexScan("schema", 10, 0, noProjects()), ImmutableList .of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)))), + DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("longV", - dsl.abs(DSL.ref("longV", LONG))))), + DSL.abs(DSL.ref("longV", LONG))))), DSL.named("AVG(intV)", DSL.ref("AVG(intV)", DOUBLE))), optimize( project( @@ -426,9 +423,9 @@ void aggregation_cant_merge_index_scan_with_limit() { indexScan("schema", 10, 0, noProjects()), ImmutableList .of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)))), + DSL.avg(DSL.ref("intV", INTEGER)))), ImmutableList.of(DSL.named("longV", - dsl.abs(DSL.ref("longV", LONG))))), + DSL.abs(DSL.ref("longV", LONG))))), DSL.named("AVG(intV)", DSL.ref("AVG(intV)", DOUBLE))))); } @@ -458,13 +455,13 @@ void push_down_should_handle_duplication() { project( indexScan("schema", projects(DSL.ref("intV", INTEGER))), DSL.named("i", DSL.ref("intV", INTEGER)), - DSL.named("absi", dsl.abs(DSL.ref("intV", INTEGER))) + DSL.named("absi", DSL.abs(DSL.ref("intV", INTEGER))) ), optimize( project( relation("schema", table), DSL.named("i", DSL.ref("intV", INTEGER)), - DSL.named("absi", dsl.abs(DSL.ref("intV", INTEGER)))) + DSL.named("absi", DSL.abs(DSL.ref("intV", INTEGER)))) ) ); } @@ -524,8 +521,8 @@ void filter_aggregation_merge_relation() { assertEquals( project( indexScanAgg("schema", ImmutableList.of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)) - .condition(dsl.greater(DSL.ref("intV", INTEGER), DSL.literal(1))))), + DSL.avg(DSL.ref("intV", INTEGER)) + .condition(DSL.greater(DSL.ref("intV", INTEGER), DSL.literal(1))))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), DSL.named("avg(intV) filter(where intV > 1)", DSL.ref("avg(intV)", DOUBLE))), optimize( @@ -533,8 +530,8 @@ void filter_aggregation_merge_relation() { aggregation( relation("schema", table), ImmutableList.of(DSL.named("AVG(intV)", - dsl.avg(DSL.ref("intV", INTEGER)) - .condition(dsl.greater(DSL.ref("intV", INTEGER), DSL.literal(1))))), + DSL.avg(DSL.ref("intV", INTEGER)) + .condition(DSL.greater(DSL.ref("intV", INTEGER), DSL.literal(1))))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), DSL.named("avg(intV) filter(where intV > 1)", DSL.ref("avg(intV)", DOUBLE))) ) @@ -549,10 +546,10 @@ void filter_aggregation_merge_filter_relation() { assertEquals( project( indexScanAgg("schema", - dsl.less(DSL.ref("longV", LONG), DSL.literal(1)), + DSL.less(DSL.ref("longV", LONG), DSL.literal(1)), ImmutableList.of(DSL.named("avg(intV)", - dsl.avg(DSL.ref("intV", INTEGER)) - .condition(dsl.greater(DSL.ref("intV", INTEGER), DSL.literal(1))))), + DSL.avg(DSL.ref("intV", INTEGER)) + .condition(DSL.greater(DSL.ref("intV", INTEGER), DSL.literal(1))))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), DSL.named("avg(intV) filter(where intV > 1)", DSL.ref("avg(intV)", DOUBLE))), optimize( @@ -560,11 +557,11 @@ void filter_aggregation_merge_filter_relation() { aggregation( filter( relation("schema", table), - dsl.less(DSL.ref("longV", LONG), DSL.literal(1)) + DSL.less(DSL.ref("longV", LONG), DSL.literal(1)) ), ImmutableList.of(DSL.named("avg(intV)", - dsl.avg(DSL.ref("intV", INTEGER)) - .condition(dsl.greater(DSL.ref("intV", INTEGER), DSL.literal(1))))), + DSL.avg(DSL.ref("intV", INTEGER)) + .condition(DSL.greater(DSL.ref("intV", INTEGER), DSL.literal(1))))), ImmutableList.of(DSL.named("stringV", DSL.ref("stringV", STRING)))), DSL.named("avg(intV) filter(where intV > 1)", DSL.ref("avg(intV)", DOUBLE))) ) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchDataSourceFactoryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchDataSourceFactoryTest.java new file mode 100644 index 0000000000..a9e4e153fc --- /dev/null +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchDataSourceFactoryTest.java @@ -0,0 +1,51 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.opensearch.storage; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.opensearch.sql.common.setting.Settings; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.opensearch.client.OpenSearchClient; + +@ExtendWith(MockitoExtension.class) +class OpenSearchDataSourceFactoryTest { + + @Mock private OpenSearchClient client; + + @Mock private Settings settings; + + @Mock private DataSourceMetadata dataSourceMetadata; + + private OpenSearchDataSourceFactory factory; + + @BeforeEach + public void setup() { + factory = new OpenSearchDataSourceFactory(client, settings); + } + + @Test + void getDataSourceType() { + assertEquals(DataSourceType.OPENSEARCH, factory.getDataSourceType()); + } + + @Test + void createDataSource() { + when(dataSourceMetadata.getName()).thenReturn("opensearch"); + + DataSource dataSource = factory.createDataSource(dataSourceMetadata); + assertEquals("opensearch", dataSource.getName()); + assertEquals(DataSourceType.OPENSEARCH, dataSource.getConnectorType()); + } +} diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchIndexTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchIndexTest.java index f7860403c7..9e375aa1b0 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchIndexTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchIndexTest.java @@ -61,7 +61,6 @@ import org.opensearch.sql.expression.ReferenceExpression; import org.opensearch.sql.expression.aggregation.AvgAggregator; import org.opensearch.sql.expression.aggregation.NamedAggregator; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.opensearch.client.OpenSearchClient; import org.opensearch.sql.opensearch.data.type.OpenSearchDataType; import org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory; @@ -79,8 +78,6 @@ @ExtendWith(MockitoExtension.class) class OpenSearchIndexTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - private final String indexName = "test"; @Mock @@ -254,7 +251,7 @@ void shouldImplLogicalIndexScan() { ReferenceExpression field = ref("name", STRING); NamedExpression named = named("n", field); - Expression filterExpr = dsl.equal(field, literal("John")); + Expression filterExpr = DSL.equal(field, literal("John")); PhysicalPlan plan = index.implement( project( @@ -274,7 +271,7 @@ void shouldNotPushDownFilterFarFromRelation() { when(client.getIndexMaxResultWindows("test")).thenReturn(Map.of("test", 10000)); ReferenceExpression field = ref("name", STRING); - Expression filterExpr = dsl.equal(field, literal("John")); + Expression filterExpr = DSL.equal(field, literal("John")); List groupByExprs = Arrays.asList(named("age", ref("age", INTEGER))); List aggregators = Arrays.asList(named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), @@ -298,7 +295,7 @@ void shouldImplLogicalIndexScanAgg() { when(client.getIndexMaxResultWindows("test")).thenReturn(Map.of("test", 10000)); ReferenceExpression field = ref("name", STRING); - Expression filterExpr = dsl.equal(field, literal("John")); + Expression filterExpr = DSL.equal(field, literal("John")); List groupByExprs = Arrays.asList(named("age", ref("age", INTEGER))); List aggregators = Arrays.asList(named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), @@ -332,7 +329,7 @@ void shouldNotPushDownAggregationFarFromRelation() { when(client.getIndexMaxResultWindows("test")).thenReturn(Map.of("test", 10000)); ReferenceExpression field = ref("name", STRING); - Expression filterExpr = dsl.equal(field, literal("John")); + Expression filterExpr = DSL.equal(field, literal("John")); List groupByExprs = Arrays.asList(named("age", ref("age", INTEGER))); List aggregators = Arrays.asList(named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), @@ -423,7 +420,7 @@ void shouldNotPushDownLimitFarFromRelationButUpdateScanSize() { sort( relation("test", table), Pair.of(Sort.SortOption.DEFAULT_ASC, - dsl.abs(named("intV", ref("intV", INTEGER)))) + DSL.abs(named("intV", ref("intV", INTEGER)))) ), 300, 1 ), diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchStorageEngineTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchStorageEngineTest.java index dd660d54a1..ab87f4531c 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchStorageEngineTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/OpenSearchStorageEngineTest.java @@ -8,14 +8,14 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opensearch.sql.analysis.CatalogSchemaIdentifierNameResolver.DEFAULT_CATALOG_NAME; +import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; import static org.opensearch.sql.utils.SystemIndexUtils.TABLE_INFO; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.common.setting.Settings; import org.opensearch.sql.opensearch.client.OpenSearchClient; import org.opensearch.sql.opensearch.storage.system.OpenSearchSystemIndex; @@ -33,14 +33,15 @@ class OpenSearchStorageEngineTest { @Test public void getTable() { OpenSearchStorageEngine engine = new OpenSearchStorageEngine(client, settings); - Table table = engine.getTable(new CatalogSchemaName(DEFAULT_CATALOG_NAME, "default"), "test"); + Table table = engine.getTable(new DataSourceSchemaName(DEFAULT_DATASOURCE_NAME, "default"), + "test"); assertNotNull(table); } @Test public void getSystemTable() { OpenSearchStorageEngine engine = new OpenSearchStorageEngine(client, settings); - Table table = engine.getTable(new CatalogSchemaName(DEFAULT_CATALOG_NAME, "default"), + Table table = engine.getTable(new DataSourceSchemaName(DEFAULT_DATASOURCE_NAME, "default"), TABLE_INFO); assertNotNull(table); assertTrue(table instanceof OpenSearchSystemIndex); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java index 3614d82e59..602571434b 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java @@ -52,15 +52,12 @@ import org.opensearch.sql.expression.aggregation.AvgAggregator; import org.opensearch.sql.expression.aggregation.CountAggregator; import org.opensearch.sql.expression.aggregation.NamedAggregator; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.opensearch.storage.serialization.ExpressionSerializer; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class) class AggregationQueryBuilderTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - @Mock private ExpressionSerializer serializer; @@ -236,8 +233,8 @@ void should_build_composite_aggregation_for_expression() { buildQuery( Arrays.asList( named("avg(balance)", new AvgAggregator( - Arrays.asList(dsl.abs(ref("balance", INTEGER))), INTEGER))), - Arrays.asList(named("age", dsl.asin(ref("age", INTEGER)))))); + Arrays.asList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + Arrays.asList(named("age", DSL.asin(ref("age", INTEGER)))))); } @Test @@ -289,8 +286,8 @@ void should_build_type_mapping_for_expression() { assertThat( buildTypeMapping(Arrays.asList( named("avg(balance)", new AvgAggregator( - Arrays.asList(dsl.abs(ref("balance", INTEGER))), INTEGER))), - Arrays.asList(named("age", dsl.asin(ref("age", INTEGER))))), + Arrays.asList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + Arrays.asList(named("age", DSL.asin(ref("age", INTEGER))))), containsInAnyOrder( map("avg(balance)", INTEGER), map("age", DOUBLE) @@ -342,7 +339,7 @@ void should_build_filter_aggregation() { buildQuery( Arrays.asList(named("avg(age) filter(where age > 34)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER) - .condition(dsl.greater(ref("age", INTEGER), literal(20))))), + .condition(DSL.greater(ref("age", INTEGER), literal(20))))), Collections.emptyList())); } @@ -391,7 +388,7 @@ void should_build_filter_aggregation_group_by() { buildQuery( Arrays.asList(named("avg(age) filter(where age > 34)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER) - .condition(dsl.greater(ref("age", INTEGER), literal(20))))), + .condition(DSL.greater(ref("age", INTEGER), literal(20))))), Arrays.asList(named(ref("gender", STRING))))); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java index e721b7ed27..79b6bba712 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java @@ -34,14 +34,11 @@ import org.opensearch.search.lookup.SearchLookup; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; -import org.opensearch.sql.expression.config.ExpressionConfig; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class) class ExpressionAggregationScriptTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - @Mock private SearchLookup lookup; @@ -56,7 +53,7 @@ void can_execute_expression_with_integer_field() { assertThat() .docValues("age", 30L) // DocValue only supports long .evaluate( - dsl.abs(ref("age", INTEGER))) + DSL.abs(ref("age", INTEGER))) .shouldMatch(30); } @@ -65,7 +62,7 @@ void can_execute_expression_with_integer_field_with_boolean_result() { assertThat() .docValues("age", 30L) // DocValue only supports long .evaluate( - dsl.greater(ref("age", INTEGER), literal(20))) + DSL.greater(ref("age", INTEGER), literal(20))) .shouldMatch(true); } @@ -74,7 +71,7 @@ void can_execute_expression_with_text_keyword_field() { assertThat() .docValues("name.keyword", "John") .evaluate( - dsl.equal(ref("name", OPENSEARCH_TEXT_KEYWORD), literal("John"))) + DSL.equal(ref("name", OPENSEARCH_TEXT_KEYWORD), literal("John"))) .shouldMatch(true); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java index b2ad41d516..94f152f913 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java @@ -42,14 +42,12 @@ import org.opensearch.sql.expression.aggregation.NamedAggregator; import org.opensearch.sql.expression.aggregation.SumAggregator; import org.opensearch.sql.expression.aggregation.TakeAggregator; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.serialization.ExpressionSerializer; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class) class MetricAggregationBuilderTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); @Mock private ExpressionSerializer serializer; @@ -287,7 +285,7 @@ void should_build_filtered_cardinality_aggregation() { buildQuery(Collections.singletonList(named( "count(distinct name) filter(where age > 30)", new CountAggregator(Collections.singletonList(ref("name", STRING)), INTEGER) - .condition(dsl.greater(ref("age", INTEGER), literal(30))) + .condition(DSL.greater(ref("age", INTEGER), literal(30))) .distinct(true))))); } @@ -351,7 +349,7 @@ void should_build_filtered_top_hits_aggregation() { "take(name, 10) filter(where age > 30)", new TakeAggregator( ImmutableList.of(ref("name", STRING), literal(10)), ARRAY) - .condition(dsl.greater(ref("age", INTEGER), literal(30))))))); + .condition(DSL.greater(ref("age", INTEGER), literal(30))))))); } @Test diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java index c3965d8408..ee63c2f0c0 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java @@ -44,14 +44,11 @@ import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.LiteralExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class) class ExpressionFilterScriptTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - @Mock private SearchLookup lookup; @@ -82,7 +79,7 @@ void can_execute_expression_with_integer_field() { assertThat() .docValues("age", 30L) // DocValue only supports long .filterBy( - dsl.greater(ref("age", INTEGER), literal(20))) + DSL.greater(ref("age", INTEGER), literal(20))) .shouldMatch(); } @@ -91,7 +88,7 @@ void can_execute_expression_with_text_keyword_field() { assertThat() .docValues("name.keyword", "John") .filterBy( - dsl.equal(ref("name", OPENSEARCH_TEXT_KEYWORD), literal("John"))) + DSL.equal(ref("name", OPENSEARCH_TEXT_KEYWORD), literal("John"))) .shouldMatch(); } @@ -102,9 +99,9 @@ void can_execute_expression_with_float_field() { "balance", 100.0, // DocValue only supports double "name", "John") .filterBy( - dsl.and( - dsl.less(ref("balance", FLOAT), literal(150.0F)), - dsl.equal(ref("name", STRING), literal("John")))) + DSL.and( + DSL.less(ref("balance", FLOAT), literal(150.0F)), + DSL.equal(ref("name", STRING), literal("John")))) .shouldMatch(); } @@ -113,7 +110,7 @@ void can_execute_expression_with_date_field() { ExprTimestampValue ts = new ExprTimestampValue("2020-08-04 10:00:00"); assertThat() .docValues("birthday", ZonedDateTime.parse("2020-08-04T10:00:00Z")) - .filterBy(dsl.equal(ref("birthday", TIMESTAMP), new LiteralExpression(ts))) + .filterBy(DSL.equal(ref("birthday", TIMESTAMP), new LiteralExpression(ts))) .shouldMatch(); } @@ -137,7 +134,7 @@ void can_execute_expression_with_empty_doc_value() { void can_execute_parse_expression() { assertThat() .docValues("age_string", "age: 30") - .filterBy(dsl.equal( + .filterBy(DSL.equal( DSL.regex(DSL.ref("age_string", STRING), literal("age: (?\\d+)"), literal("age")), literal("30"))) .shouldMatch(); 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 bae4028986..737e61f54b 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 @@ -53,15 +53,12 @@ import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.LiteralExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.opensearch.storage.serialization.ExpressionSerializer; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class) class FilterQueryBuilderTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - private static Stream numericCastSource() { return Stream.of(literal((byte) 1), literal((short) -1), literal( 1), literal(21L), literal(3.14F), literal(3.1415D), literal(true), literal("1")); @@ -99,7 +96,7 @@ void should_build_term_query_for_equality_expression() { + " }\n" + "}", buildQuery( - dsl.equal( + DSL.equal( ref("name", STRING), literal("John")))); } @@ -107,10 +104,10 @@ void should_build_term_query_for_equality_expression() { void should_build_range_query_for_comparison_expression() { Expression[] params = {ref("age", INTEGER), literal(30)}; Map ranges = ImmutableMap.of( - dsl.less(params), new Object[]{null, 30, true, false}, - dsl.greater(params), new Object[]{30, null, false, true}, - dsl.lte(params), new Object[]{null, 30, true, true}, - dsl.gte(params), new Object[]{30, null, true, true}); + DSL.less(params), new Object[]{null, 30, true, false}, + DSL.greater(params), new Object[]{30, null, false, true}, + DSL.lte(params), new Object[]{null, 30, true, true}, + DSL.gte(params), new Object[]{30, null, true, true}); ranges.forEach((expr, range) -> assertJsonEquals( @@ -140,7 +137,7 @@ void should_build_wildcard_query_for_like_expression() { + " }\n" + "}", buildQuery( - dsl.like( + DSL.like( ref("name", STRING), literal("%John_")))); } @@ -158,7 +155,7 @@ void should_build_script_query_for_unsupported_lucene_query() { + " }\n" + "}", buildQuery( - dsl.isnotnull(ref("age", INTEGER)))); + DSL.isnotnull(ref("age", INTEGER)))); } @Test @@ -175,8 +172,8 @@ void should_build_script_query_for_function_expression() { + " }\n" + "}", buildQuery( - dsl.equal( - dsl.abs(ref("age", INTEGER)), literal(30)))); + DSL.equal( + DSL.abs(ref("age", INTEGER)), literal(30)))); } @Test @@ -193,18 +190,18 @@ void should_build_script_query_for_comparison_between_fields() { + " }\n" + "}", buildQuery( - dsl.equal( + DSL.equal( ref("age1", INTEGER), ref("age2", INTEGER)))); } @Test void should_build_bool_query_for_and_or_expression() { String[] names = { "filter", "should" }; - FunctionExpression expr1 = dsl.equal(ref("name", STRING), literal("John")); - FunctionExpression expr2 = dsl.equal(ref("age", INTEGER), literal(30)); + FunctionExpression expr1 = DSL.equal(ref("name", STRING), literal("John")); + FunctionExpression expr2 = DSL.equal(ref("age", INTEGER), literal(30)); Expression[] exprs = { - dsl.and(expr1, expr2), - dsl.or(expr1, expr2) + DSL.and(expr1, expr2), + DSL.or(expr1, expr2) }; for (int i = 0; i < names.length; i++) { @@ -257,8 +254,8 @@ void should_build_bool_query_for_not_expression() { + " }\n" + "}", buildQuery( - dsl.not( - dsl.equal( + DSL.not( + DSL.equal( ref("age", INTEGER), literal(30))))); } @@ -274,7 +271,7 @@ void should_use_keyword_for_multi_field_in_equality_expression() { + " }\n" + "}", buildQuery( - dsl.equal( + DSL.equal( ref("name", OPENSEARCH_TEXT_KEYWORD), literal("John")))); } @@ -290,7 +287,7 @@ void should_use_keyword_for_multi_field_in_like_expression() { + " }\n" + "}", buildQuery( - dsl.like( + DSL.like( ref("name", OPENSEARCH_TEXT_KEYWORD), literal("John%")))); } @@ -313,9 +310,9 @@ void should_build_match_query_with_default_parameters() { + " }\n" + "}", buildQuery( - dsl.match( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query"))))); + DSL.match( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query"))))); } @Test @@ -341,80 +338,80 @@ void should_build_match_query_with_custom_parameters() { + " }\n" + "}", buildQuery( - dsl.match( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("operator", literal("AND")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("auto_generate_synonyms_phrase_query", literal("true")), - dsl.namedArgument("fuzziness", literal("AUTO")), - dsl.namedArgument("max_expansions", literal("50")), - dsl.namedArgument("prefix_length", literal("0")), - dsl.namedArgument("fuzzy_transpositions", literal("false")), - dsl.namedArgument("fuzzy_rewrite", literal("top_terms_1")), - dsl.namedArgument("lenient", literal("false")), - dsl.namedArgument("minimum_should_match", literal("3")), - dsl.namedArgument("zero_terms_query", literal("ALL")), - dsl.namedArgument("boost", literal("2.0"))))); + DSL.match( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("operator", literal("AND")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("auto_generate_synonyms_phrase_query", literal("true")), + DSL.namedArgument("fuzziness", literal("AUTO")), + DSL.namedArgument("max_expansions", literal("50")), + DSL.namedArgument("prefix_length", literal("0")), + DSL.namedArgument("fuzzy_transpositions", literal("false")), + DSL.namedArgument("fuzzy_rewrite", literal("top_terms_1")), + DSL.namedArgument("lenient", literal("false")), + DSL.namedArgument("minimum_should_match", literal("3")), + DSL.namedArgument("zero_terms_query", literal("ALL")), + DSL.namedArgument("boost", literal("2.0"))))); } @Test void match_invalid_parameter() { - FunctionExpression expr = dsl.match( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("invalid_parameter", literal("invalid_value"))); + FunctionExpression expr = DSL.match( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("invalid_parameter", literal("invalid_value"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertTrue(msg.startsWith("Parameter invalid_parameter is invalid for match function.")); } @Test void match_disallow_duplicate_parameter() { - FunctionExpression expr = dsl.match( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("AnalYzer", literal("english"))); + FunctionExpression expr = DSL.match( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("AnalYzer", literal("english"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertEquals("Parameter 'analyzer' can only be specified once.", msg); } @Test void match_disallow_duplicate_query() { - FunctionExpression expr = dsl.match( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("QUERY", literal("something"))); + FunctionExpression expr = DSL.match( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("QUERY", literal("something"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertEquals("Parameter 'query' can only be specified once.", msg); } @Test void match_disallow_duplicate_field() { - FunctionExpression expr = dsl.match( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("Field", literal("something"))); + FunctionExpression expr = DSL.match( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("Field", literal("something"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertEquals("Parameter 'field' can only be specified once.", msg); } @Test void match_missing_field() { - FunctionExpression expr = dsl.match( - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("analyzer", literal("keyword"))); + FunctionExpression expr = DSL.match( + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("analyzer", literal("keyword"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertEquals("'field' parameter is missing.", msg); } @Test void match_missing_query() { - FunctionExpression expr = dsl.match( - dsl.namedArgument("field", literal("field1")), - dsl.namedArgument("analyzer", literal("keyword"))); + FunctionExpression expr = DSL.match( + DSL.namedArgument("field", literal("field1")), + DSL.namedArgument("analyzer", literal("keyword"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertEquals("'query' parameter is missing", msg); } @@ -433,9 +430,9 @@ void should_build_match_phrase_query_with_default_parameters() { + " }\n" + "}", buildQuery( - dsl.match_phrase( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query"))))); + DSL.match_phrase( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query"))))); } @Test @@ -457,11 +454,11 @@ void should_build_multi_match_query_with_default_parameters_single_field() { + " \"boost\" : 1.0,\n" + " }\n" + "}", - buildQuery(dsl.multi_match( - dsl.namedArgument("fields", DSL.literal(new ExprTupleValue( + buildQuery(DSL.multi_match( + DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", literal("search query"))))); + DSL.namedArgument("query", literal("search query"))))); } @Test @@ -483,11 +480,11 @@ void should_build_multi_match_query_with_default_parameters_all_fields() { + " \"boost\" : 1.0,\n" + " }\n" + "}", - buildQuery(dsl.multi_match( - dsl.namedArgument("fields", DSL.literal(new ExprTupleValue( + buildQuery(DSL.multi_match( + DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "*", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", literal("search query"))))); + DSL.namedArgument("query", literal("search query"))))); } @Test @@ -507,10 +504,10 @@ void should_build_multi_match_query_with_default_parameters_no_fields() { + " \"boost\" : 1.0,\n" + " }\n" + "}", - buildQuery(dsl.multi_match( - dsl.namedArgument("fields", DSL.literal(new ExprTupleValue( + buildQuery(DSL.multi_match( + DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of())))), - dsl.namedArgument("query", literal("search query"))))); + DSL.namedArgument("query", literal("search query"))))); } // Note: we can't test `multi_match` and `simple_query_string` without weight(s) @@ -532,12 +529,12 @@ void should_build_multi_match_query_with_default_parameters_multiple_fields() { + " \"boost\" : 1.0,\n" + " }\n" + "}"; - var actual = buildQuery(dsl.multi_match( - dsl.namedArgument("fields", DSL.literal(new ExprTupleValue( + var actual = buildQuery(DSL.multi_match( + DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", literal("search query")))); + DSL.namedArgument("query", literal("search query")))); var ex1 = String.format(expected, "\"field1^1.0\", \"field2^0.3\""); var ex2 = String.format(expected, "\"field2^0.3\", \"field1^1.0\""); @@ -570,25 +567,25 @@ void should_build_multi_match_query_with_custom_parameters() { + " }\n" + "}"; var actual = buildQuery( - dsl.multi_match( - dsl.namedArgument("fields", DSL.literal( + DSL.multi_match( + DSL.namedArgument("fields", DSL.literal( ExprValueUtils.tupleValue(ImmutableMap.of("field1", 1.F, "field2", .3F)))), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("auto_generate_synonyms_phrase_query", literal("false")), - dsl.namedArgument("cutoff_frequency", literal("4.3")), - dsl.namedArgument("fuzziness", literal("AUTO:2,4")), - dsl.namedArgument("fuzzy_transpositions", literal("false")), - dsl.namedArgument("lenient", literal("false")), - dsl.namedArgument("max_expansions", literal("3")), - dsl.namedArgument("minimum_should_match", literal("3")), - dsl.namedArgument("operator", literal("AND")), - dsl.namedArgument("prefix_length", literal("1")), - dsl.namedArgument("slop", literal("1")), - dsl.namedArgument("tie_breaker", literal("1")), - dsl.namedArgument("type", literal("phrase_prefix")), - dsl.namedArgument("zero_terms_query", literal("ALL")), - dsl.namedArgument("boost", literal("2.0")))); + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("auto_generate_synonyms_phrase_query", literal("false")), + DSL.namedArgument("cutoff_frequency", literal("4.3")), + DSL.namedArgument("fuzziness", literal("AUTO:2,4")), + DSL.namedArgument("fuzzy_transpositions", literal("false")), + DSL.namedArgument("lenient", literal("false")), + DSL.namedArgument("max_expansions", literal("3")), + DSL.namedArgument("minimum_should_match", literal("3")), + DSL.namedArgument("operator", literal("AND")), + DSL.namedArgument("prefix_length", literal("1")), + DSL.namedArgument("slop", literal("1")), + DSL.namedArgument("tie_breaker", literal("1")), + DSL.namedArgument("type", literal("phrase_prefix")), + DSL.namedArgument("zero_terms_query", literal("ALL")), + DSL.namedArgument("boost", literal("2.0")))); var ex1 = String.format(expected, "\"field1^1.0\", \"field2^0.3\""); var ex2 = String.format(expected, "\"field2^0.3\", \"field1^1.0\""); @@ -599,13 +596,13 @@ void should_build_multi_match_query_with_custom_parameters() { @Test void multi_match_invalid_parameter() { - FunctionExpression expr = dsl.multi_match( - dsl.namedArgument("fields", DSL.literal( + FunctionExpression expr = DSL.multi_match( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("invalid_parameter", literal("invalid_value"))); + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("invalid_parameter", literal("invalid_value"))); assertThrows(SemanticCheckException.class, () -> buildQuery(expr), "Parameter invalid_parameter is invalid for match function."); } @@ -625,28 +622,28 @@ void should_build_match_phrase_query_with_custom_parameters() { + " }\n" + "}", buildQuery( - dsl.match_phrase( - dsl.namedArgument("boost", literal("1.2")), - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("slop", literal("2")), - dsl.namedArgument("zero_terms_query", literal("ALL"))))); + DSL.match_phrase( + DSL.namedArgument("boost", literal("1.2")), + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("slop", literal("2")), + DSL.namedArgument("zero_terms_query", literal("ALL"))))); } @Test void query_invalid_parameter() { - FunctionExpression expr = dsl.query( - dsl.namedArgument("invalid_parameter", literal("invalid_value"))); + FunctionExpression expr = DSL.query( + DSL.namedArgument("invalid_parameter", literal("invalid_value"))); assertThrows(SemanticCheckException.class, () -> buildQuery(expr), "Parameter invalid_parameter is invalid for query function."); } @Test void query_invalid_fields_parameter_exception_message() { - FunctionExpression expr = dsl.query( - dsl.namedArgument("fields", literal("field1")), - dsl.namedArgument("query", literal("search query"))); + FunctionExpression expr = DSL.query( + DSL.namedArgument("fields", literal("field1")), + DSL.namedArgument("query", literal("search query"))); var exception = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)); assertEquals("Parameter fields is invalid for query function.", exception.getMessage()); @@ -673,8 +670,8 @@ void should_build_query_query_with_default_parameters() { + " }\n" + "}"; - assertJsonEquals(expected, buildQuery(dsl.query( - dsl.namedArgument("query", literal("field1:query_value"))))); + assertJsonEquals(expected, buildQuery(DSL.query( + DSL.namedArgument("query", literal("field1:query_value"))))); } @Test @@ -703,33 +700,33 @@ void should_build_query_query_with_custom_parameters() { + " }\n" + "}"; var actual = buildQuery( - dsl.query( - dsl.namedArgument("query", literal("field1:query_value")), - dsl.namedArgument("analyze_wildcard", literal("true")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("auto_generate_synonyms_phrase_query", literal("false")), - dsl.namedArgument("default_operator", literal("AND")), - dsl.namedArgument("fuzzy_max_expansions", literal("10")), - dsl.namedArgument("fuzzy_prefix_length", literal("2")), - dsl.namedArgument("fuzzy_transpositions", literal("false")), - dsl.namedArgument("lenient", literal("false")), - dsl.namedArgument("minimum_should_match", literal("3")), - dsl.namedArgument("tie_breaker", literal("1.3")), - dsl.namedArgument("type", literal("cross_fields")), - dsl.namedArgument("boost", literal("2.0")))); + DSL.query( + DSL.namedArgument("query", literal("field1:query_value")), + DSL.namedArgument("analyze_wildcard", literal("true")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("auto_generate_synonyms_phrase_query", literal("false")), + DSL.namedArgument("default_operator", literal("AND")), + DSL.namedArgument("fuzzy_max_expansions", literal("10")), + DSL.namedArgument("fuzzy_prefix_length", literal("2")), + DSL.namedArgument("fuzzy_transpositions", literal("false")), + DSL.namedArgument("lenient", literal("false")), + DSL.namedArgument("minimum_should_match", literal("3")), + DSL.namedArgument("tie_breaker", literal("1.3")), + DSL.namedArgument("type", literal("cross_fields")), + DSL.namedArgument("boost", literal("2.0")))); assertJsonEquals(expected, actual); } @Test void query_string_invalid_parameter() { - FunctionExpression expr = dsl.query_string( - dsl.namedArgument("fields", DSL.literal( + FunctionExpression expr = DSL.query_string( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("invalid_parameter", literal("invalid_value"))); + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("invalid_parameter", literal("invalid_value"))); assertThrows(SemanticCheckException.class, () -> buildQuery(expr), "Parameter invalid_parameter is invalid for match function."); } @@ -754,12 +751,12 @@ void should_build_query_string_query_with_default_parameters_multiple_fields() { + " \"boost\" : 1.0\n" + " }\n" + "}"; - var actual = buildQuery(dsl.query_string( - dsl.namedArgument("fields", DSL.literal(new ExprTupleValue( + var actual = buildQuery(DSL.query_string( + DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", literal("query_value")))); + DSL.namedArgument("query", literal("query_value")))); var ex1 = String.format(expected, "\"field1^1.0\", \"field2^0.3\""); var ex2 = String.format(expected, "\"field2^0.3\", \"field1^1.0\""); @@ -794,22 +791,22 @@ void should_build_query_string_query_with_custom_parameters() { + " }\n" + "}"; var actual = buildQuery( - dsl.query_string( - dsl.namedArgument("fields", DSL.literal( + DSL.query_string( + DSL.namedArgument("fields", DSL.literal( ExprValueUtils.tupleValue(ImmutableMap.of("field1", 1.F, "field2", .3F)))), - dsl.namedArgument("query", literal("query_value")), - dsl.namedArgument("analyze_wildcard", literal("true")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("auto_generate_synonyms_phrase_query", literal("false")), - dsl.namedArgument("default_operator", literal("AND")), - dsl.namedArgument("fuzzy_max_expansions", literal("10")), - dsl.namedArgument("fuzzy_prefix_length", literal("2")), - dsl.namedArgument("fuzzy_transpositions", literal("false")), - dsl.namedArgument("lenient", literal("false")), - dsl.namedArgument("minimum_should_match", literal("3")), - dsl.namedArgument("tie_breaker", literal("1.3")), - dsl.namedArgument("type", literal("cross_fields")), - dsl.namedArgument("boost", literal("2.0")))); + DSL.namedArgument("query", literal("query_value")), + DSL.namedArgument("analyze_wildcard", literal("true")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("auto_generate_synonyms_phrase_query", literal("false")), + DSL.namedArgument("default_operator", literal("AND")), + DSL.namedArgument("fuzzy_max_expansions", literal("10")), + DSL.namedArgument("fuzzy_prefix_length", literal("2")), + DSL.namedArgument("fuzzy_transpositions", literal("false")), + DSL.namedArgument("lenient", literal("false")), + DSL.namedArgument("minimum_should_match", literal("3")), + DSL.namedArgument("tie_breaker", literal("1.3")), + DSL.namedArgument("type", literal("cross_fields")), + DSL.namedArgument("boost", literal("2.0")))); var ex1 = String.format(expected, "\"field1^1.0\", \"field2^0.3\""); var ex2 = String.format(expected, "\"field2^0.3\", \"field1^1.0\""); @@ -840,11 +837,11 @@ void should_build_query_string_query_with_default_parameters_single_field() { + " \"boost\" : 1.0,\n" + " }\n" + "}", - buildQuery(dsl.query_string( - dsl.namedArgument("fields", DSL.literal(new ExprTupleValue( + buildQuery(DSL.query_string( + DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", literal("query_value"))))); + DSL.namedArgument("query", literal("query_value"))))); } @Test @@ -869,11 +866,11 @@ void should_build_simple_query_string_query_with_default_parameters_single_field + " \"boost\" : 1.0\n" + " }\n" + "}", - buildQuery(dsl.simple_query_string( - dsl.namedArgument("fields", DSL.literal(new ExprTupleValue( + buildQuery(DSL.simple_query_string( + DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F)))))), - dsl.namedArgument("query", literal("search query"))))); + DSL.namedArgument("query", literal("search query"))))); } @Test @@ -892,12 +889,12 @@ void should_build_simple_query_string_query_with_default_parameters_multiple_fie + " \"boost\" : 1.0\n" + " }\n" + "}"; - var actual = buildQuery(dsl.simple_query_string( - dsl.namedArgument("fields", DSL.literal(new ExprTupleValue( + var actual = buildQuery(DSL.simple_query_string( + DSL.namedArgument("fields", DSL.literal(new ExprTupleValue( new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", literal("search query")))); + DSL.namedArgument("query", literal("search query")))); var ex1 = String.format(expected, "\"field1^1.0\", \"field2^0.3\""); var ex2 = String.format(expected, "\"field2^0.3\", \"field1^1.0\""); @@ -926,21 +923,21 @@ void should_build_simple_query_string_query_with_custom_parameters() { + " }\n" + "}"; var actual = buildQuery( - dsl.simple_query_string( - dsl.namedArgument("fields", DSL.literal( + DSL.simple_query_string( + DSL.namedArgument("fields", DSL.literal( ExprValueUtils.tupleValue(ImmutableMap.of("field1", 1.F, "field2", .3F)))), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("analyze_wildcard", literal("true")), - dsl.namedArgument("analyzer", literal("keyword")), - dsl.namedArgument("auto_generate_synonyms_phrase_query", literal("false")), - dsl.namedArgument("default_operator", literal("AND")), - dsl.namedArgument("flags", literal("AND")), - dsl.namedArgument("fuzzy_max_expansions", literal("10")), - dsl.namedArgument("fuzzy_prefix_length", literal("2")), - dsl.namedArgument("fuzzy_transpositions", literal("false")), - dsl.namedArgument("lenient", literal("false")), - dsl.namedArgument("minimum_should_match", literal("3")), - dsl.namedArgument("boost", literal("2.0")))); + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("analyze_wildcard", literal("true")), + DSL.namedArgument("analyzer", literal("keyword")), + DSL.namedArgument("auto_generate_synonyms_phrase_query", literal("false")), + DSL.namedArgument("default_operator", literal("AND")), + DSL.namedArgument("flags", literal("AND")), + DSL.namedArgument("fuzzy_max_expansions", literal("10")), + DSL.namedArgument("fuzzy_prefix_length", literal("2")), + DSL.namedArgument("fuzzy_transpositions", literal("false")), + DSL.namedArgument("lenient", literal("false")), + DSL.namedArgument("minimum_should_match", literal("3")), + DSL.namedArgument("boost", literal("2.0")))); var ex1 = String.format(expected, "\"field1^1.0\", \"field2^0.3\""); var ex2 = String.format(expected, "\"field2^0.3\", \"field1^1.0\""); @@ -951,86 +948,86 @@ void should_build_simple_query_string_query_with_custom_parameters() { @Test void simple_query_string_invalid_parameter() { - FunctionExpression expr = dsl.simple_query_string( - dsl.namedArgument("fields", DSL.literal( + FunctionExpression expr = DSL.simple_query_string( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("invalid_parameter", literal("invalid_value"))); + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("invalid_parameter", literal("invalid_value"))); assertThrows(SemanticCheckException.class, () -> buildQuery(expr), "Parameter invalid_parameter is invalid for match function."); } @Test void match_phrase_invalid_parameter() { - FunctionExpression expr = dsl.match_phrase( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("invalid_parameter", literal("invalid_value"))); + FunctionExpression expr = DSL.match_phrase( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("invalid_parameter", literal("invalid_value"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertTrue(msg.startsWith("Parameter invalid_parameter is invalid for match_phrase function.")); } @Test void relevancy_func_invalid_arg_values() { - final var field = dsl.namedArgument("field", literal("message")); - final var fields = dsl.namedArgument("fields", DSL.literal( + final var field = DSL.namedArgument("field", literal("message")); + final var fields = DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))); - final var query = dsl.namedArgument("query", literal("search query")); + final var query = DSL.namedArgument("query", literal("search query")); - var slopTest = dsl.match_phrase(field, query, - dsl.namedArgument("slop", literal("1.5"))); + var slopTest = DSL.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, - dsl.namedArgument("zero_terms_query", literal("meow"))); + var ztqTest = DSL.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, - dsl.namedArgument("boost", literal("pewpew"))); + var boostTest = DSL.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, - dsl.namedArgument("escape", literal("42"))); + var boolTest = DSL.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, - dsl.namedArgument("type", literal("42"))); + var typeTest = DSL.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, - dsl.namedArgument("default_operator", literal("42"))); + var operatorTest = DSL.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, - dsl.namedArgument("flags", literal("42"))); + var flagsTest = DSL.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, - dsl.namedArgument("fuzziness", literal("AUTO:"))); + var fuzzinessTest = DSL.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, - dsl.namedArgument("fuzzy_rewrite", literal("42"))); + var rewriteTest = DSL.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, - dsl.namedArgument("time_zone", literal("42"))); + var timezoneTest = DSL.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'.")); } @@ -1051,39 +1048,39 @@ void should_build_match_bool_prefix_query_with_default_parameters() { + " }\n" + "}", buildQuery( - dsl.match_bool_prefix( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query"))))); + DSL.match_bool_prefix( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query"))))); } @Test void multi_match_missing_fields() { var msg = assertThrows(SemanticCheckException.class, () -> - dsl.multi_match( - dsl.namedArgument("query", literal("search query")))).getMessage(); + DSL.multi_match( + DSL.namedArgument("query", literal("search query")))).getMessage(); assertEquals("Expected type STRUCT instead of STRING for parameter #1", msg); } @Test void multi_match_missing_fields_even_with_struct() { - FunctionExpression expr = dsl.multi_match( - dsl.namedArgument("something-but-not-fields", DSL.literal( + FunctionExpression expr = DSL.multi_match( + DSL.namedArgument("something-but-not-fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "pewpew", ExprValueUtils.integerValue(42)))))), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("analyzer", literal("keyword"))); + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("analyzer", literal("keyword"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertEquals("'fields' parameter is missing.", msg); } @Test void multi_match_missing_query_even_with_struct() { - FunctionExpression expr = dsl.multi_match( - dsl.namedArgument("fields", DSL.literal( + FunctionExpression expr = DSL.multi_match( + DSL.namedArgument("fields", DSL.literal( new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( "field1", ExprValueUtils.floatValue(1.F), "field2", ExprValueUtils.floatValue(.3F)))))), - dsl.namedArgument("analyzer", literal("keyword"))); + DSL.namedArgument("analyzer", literal("keyword"))); var msg = assertThrows(SemanticCheckException.class, () -> buildQuery(expr)).getMessage(); assertEquals("'query' parameter is missing", msg); } @@ -1103,9 +1100,9 @@ void should_build_match_phrase_prefix_query_with_default_parameters() { + " }\n" + "}", buildQuery( - dsl.match_phrase_prefix( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query"))))); + DSL.match_phrase_prefix( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query"))))); } @Test @@ -1124,12 +1121,12 @@ void should_build_match_phrase_prefix_query_with_non_default_parameters() { + " }\n" + "}", buildQuery( - dsl.match_phrase_prefix( - dsl.namedArgument("field", literal("message")), - dsl.namedArgument("query", literal("search query")), - dsl.namedArgument("boost", literal("1.2")), - dsl.namedArgument("max_expansions", literal("42")), - dsl.namedArgument("analyzer", literal("english"))))); + DSL.match_phrase_prefix( + DSL.namedArgument("field", literal("message")), + DSL.namedArgument("query", literal("search query")), + DSL.namedArgument("boost", literal("1.2")), + DSL.namedArgument("max_expansions", literal("42")), + DSL.namedArgument("analyzer", literal("english"))))); } @Test @@ -1144,9 +1141,9 @@ void cast_to_string_in_filter() { + "}"; assertJsonEquals(json, buildQuery( - dsl.equal(ref("string_value", STRING), dsl.castString(literal(1))))); + DSL.equal(ref("string_value", STRING), DSL.castString(literal(1))))); assertJsonEquals(json, buildQuery( - dsl.equal(ref("string_value", STRING), dsl.castString(literal("1"))))); + DSL.equal(ref("string_value", STRING), DSL.castString(literal("1"))))); } private Float castToFloat(Object o) { @@ -1189,7 +1186,7 @@ void cast_to_byte_in_filter(LiteralExpression expr) { + " }\n" + " }\n" + "}", castToInteger(expr.valueOf().value())), - buildQuery(dsl.equal(ref("byte_value", BYTE), dsl.castByte(expr)))); + buildQuery(DSL.equal(ref("byte_value", BYTE), DSL.castByte(expr)))); } @ParameterizedTest(name = "castShort({0})") @@ -1204,7 +1201,7 @@ void cast_to_short_in_filter(LiteralExpression expr) { + " }\n" + " }\n" + "}", castToInteger(expr.valueOf().value())), - buildQuery(dsl.equal(ref("short_value", SHORT), dsl.castShort(expr)))); + buildQuery(DSL.equal(ref("short_value", SHORT), DSL.castShort(expr)))); } @ParameterizedTest(name = "castInt({0})") @@ -1219,7 +1216,7 @@ void cast_to_int_in_filter(LiteralExpression expr) { + " }\n" + " }\n" + "}", castToInteger(expr.valueOf().value())), - buildQuery(dsl.equal(ref("integer_value", INTEGER), dsl.castInt(expr)))); + buildQuery(DSL.equal(ref("integer_value", INTEGER), DSL.castInt(expr)))); } @ParameterizedTest(name = "castLong({0})") @@ -1234,7 +1231,7 @@ void cast_to_long_in_filter(LiteralExpression expr) { + " }\n" + " }\n" + "}", castToInteger(expr.valueOf().value())), - buildQuery(dsl.equal(ref("long_value", LONG), dsl.castLong(expr)))); + buildQuery(DSL.equal(ref("long_value", LONG), DSL.castLong(expr)))); } @ParameterizedTest(name = "castFloat({0})") @@ -1249,7 +1246,7 @@ void cast_to_float_in_filter(LiteralExpression expr) { + " }\n" + " }\n" + "}", castToFloat(expr.valueOf().value())), - buildQuery(dsl.equal(ref("float_value", FLOAT), dsl.castFloat(expr)))); + buildQuery(DSL.equal(ref("float_value", FLOAT), DSL.castFloat(expr)))); } @ParameterizedTest(name = "castDouble({0})") @@ -1258,7 +1255,7 @@ void cast_to_double_in_filter(LiteralExpression expr) { // double values affected by floating point imprecision, so we can't compare them in json // (Double)(Float)3.14 -> 3.14000010490417 assertEquals(castToFloat(expr.valueOf().value()), - dsl.castDouble(expr).valueOf().doubleValue(), 0.00001); + DSL.castDouble(expr).valueOf().doubleValue(), 0.00001); assertJsonEquals(String.format( "{\n" @@ -1268,8 +1265,8 @@ void cast_to_double_in_filter(LiteralExpression expr) { + " \"boost\" : 1.0\n" + " }\n" + " }\n" - + "}", dsl.castDouble(expr).valueOf().doubleValue()), - buildQuery(dsl.equal(ref("double_value", DOUBLE), dsl.castDouble(expr)))); + + "}", DSL.castDouble(expr).valueOf().doubleValue()), + buildQuery(DSL.equal(ref("double_value", DOUBLE), DSL.castDouble(expr)))); } @ParameterizedTest(name = "castBooleanTrue({0})") @@ -1285,7 +1282,7 @@ void cast_to_boolean_true_in_filter(LiteralExpression expr) { + "}"; assertJsonEquals( - json, buildQuery(dsl.equal(ref("boolean_value", BOOLEAN), dsl.castBoolean(expr)))); + json, buildQuery(DSL.equal(ref("boolean_value", BOOLEAN), DSL.castBoolean(expr)))); } @ParameterizedTest(name = "castBooleanFalse({0})") @@ -1301,7 +1298,7 @@ void cast_to_boolean_false_in_filter(LiteralExpression expr) { + "}"; assertJsonEquals( - json, buildQuery(dsl.equal(ref("boolean_value", BOOLEAN), dsl.castBoolean(expr)))); + json, buildQuery(DSL.equal(ref("boolean_value", BOOLEAN), DSL.castBoolean(expr)))); } @Test @@ -1316,13 +1313,13 @@ void cast_from_boolean() { + " }\n" + "}"; assertJsonEquals(json, buildQuery( - dsl.equal(ref("my_value", BYTE), dsl.castByte(booleanExpr)))); + DSL.equal(ref("my_value", BYTE), DSL.castByte(booleanExpr)))); assertJsonEquals(json, buildQuery( - dsl.equal(ref("my_value", SHORT), dsl.castShort(booleanExpr)))); + DSL.equal(ref("my_value", SHORT), DSL.castShort(booleanExpr)))); assertJsonEquals(json, buildQuery( - dsl.equal(ref("my_value", INTEGER), dsl.castInt(booleanExpr)))); + DSL.equal(ref("my_value", INTEGER), DSL.castInt(booleanExpr)))); assertJsonEquals(json, buildQuery( - dsl.equal(ref("my_value", LONG), dsl.castLong(booleanExpr)))); + DSL.equal(ref("my_value", LONG), DSL.castLong(booleanExpr)))); json = "{\n" + " \"term\" : {\n" @@ -1333,9 +1330,9 @@ void cast_from_boolean() { + " }\n" + "}"; assertJsonEquals(json, buildQuery( - dsl.equal(ref("my_value", FLOAT), dsl.castFloat(booleanExpr)))); + DSL.equal(ref("my_value", FLOAT), DSL.castFloat(booleanExpr)))); assertJsonEquals(json, buildQuery( - dsl.equal(ref("my_value", DOUBLE), dsl.castDouble(booleanExpr)))); + DSL.equal(ref("my_value", DOUBLE), DSL.castDouble(booleanExpr)))); json = "{\n" + " \"term\" : {\n" @@ -1346,7 +1343,7 @@ void cast_from_boolean() { + " }\n" + "}"; assertJsonEquals(json, buildQuery( - dsl.equal(ref("my_value", STRING), dsl.castString(booleanExpr)))); + DSL.equal(ref("my_value", STRING), DSL.castString(booleanExpr)))); } @Test @@ -1360,12 +1357,12 @@ void cast_to_date_in_filter() { + " }\n" + "}"; - assertJsonEquals(json, buildQuery(dsl.equal( - ref("date_value", DATE), dsl.castDate(literal("2021-11-08"))))); - assertJsonEquals(json, buildQuery(dsl.equal( - ref("date_value", DATE), dsl.castDate(literal(new ExprDateValue("2021-11-08")))))); - assertJsonEquals(json, buildQuery(dsl.equal(ref( - "date_value", DATE), dsl.castDate(literal(new ExprDatetimeValue("2021-11-08 17:00:00")))))); + assertJsonEquals(json, buildQuery(DSL.equal( + ref("date_value", DATE), DSL.castDate(literal("2021-11-08"))))); + assertJsonEquals(json, buildQuery(DSL.equal( + ref("date_value", DATE), DSL.castDate(literal(new ExprDateValue("2021-11-08")))))); + assertJsonEquals(json, buildQuery(DSL.equal(ref( + "date_value", DATE), DSL.castDate(literal(new ExprDatetimeValue("2021-11-08 17:00:00")))))); } @Test @@ -1379,11 +1376,11 @@ void cast_to_time_in_filter() { + " }\n" + "}"; - assertJsonEquals(json, buildQuery(dsl.equal( - ref("time_value", TIME), dsl.castTime(literal("17:00:00"))))); - assertJsonEquals(json, buildQuery(dsl.equal( - ref("time_value", TIME), dsl.castTime(literal(new ExprTimeValue("17:00:00")))))); - assertJsonEquals(json, buildQuery(dsl.equal(ref("time_value", TIME), dsl + assertJsonEquals(json, buildQuery(DSL.equal( + ref("time_value", TIME), DSL.castTime(literal("17:00:00"))))); + assertJsonEquals(json, buildQuery(DSL.equal( + ref("time_value", TIME), DSL.castTime(literal(new ExprTimeValue("17:00:00")))))); + assertJsonEquals(json, buildQuery(DSL.equal(ref("time_value", TIME), DSL .castTime(literal(new ExprTimestampValue("2021-11-08 17:00:00")))))); } @@ -1398,9 +1395,9 @@ void cast_to_datetime_in_filter() { + " }\n" + "}"; - assertJsonEquals(json, buildQuery(dsl.equal(ref("datetime_value", DATETIME), dsl + assertJsonEquals(json, buildQuery(DSL.equal(ref("datetime_value", DATETIME), DSL .castDatetime(literal("2021-11-08 17:00:00"))))); - assertJsonEquals(json, buildQuery(dsl.equal(ref("datetime_value", DATETIME), dsl + assertJsonEquals(json, buildQuery(DSL.equal(ref("datetime_value", DATETIME), DSL .castDatetime(literal(new ExprTimestampValue("2021-11-08 17:00:00")))))); } @@ -1415,9 +1412,9 @@ void cast_to_timestamp_in_filter() { + " }\n" + "}"; - assertJsonEquals(json, buildQuery(dsl.equal(ref("timestamp_value", TIMESTAMP), dsl + assertJsonEquals(json, buildQuery(DSL.equal(ref("timestamp_value", TIMESTAMP), DSL .castTimestamp(literal("2021-11-08 17:00:00"))))); - assertJsonEquals(json, buildQuery(dsl.equal(ref("timestamp_value", TIMESTAMP), dsl + assertJsonEquals(json, buildQuery(DSL.equal(ref("timestamp_value", TIMESTAMP), DSL .castTimestamp(literal(new ExprTimestampValue("2021-11-08 17:00:00")))))); } @@ -1435,7 +1432,7 @@ void cast_in_range_query() { + " }\n" + " }\n" + "}", - buildQuery(dsl.greater(ref("timestamp_value", TIMESTAMP), dsl + buildQuery(DSL.greater(ref("timestamp_value", TIMESTAMP), DSL .castTimestamp(literal("2021-11-08 17:00:00"))))); } @@ -1452,7 +1449,7 @@ void non_literal_in_cast_should_build_script() { + " \"boost\" : 1.0\n" + " }\n" + "}", - buildQuery(dsl.equal(ref("string_value", STRING), dsl.castString(dsl + buildQuery(DSL.equal(ref("string_value", STRING), DSL.castString(DSL .add(literal(1), literal(0))))) ); } @@ -1470,7 +1467,7 @@ void non_cast_nested_function_should_build_script() { + " \"boost\" : 1.0\n" + " }\n" + "}", - buildQuery(dsl.equal(ref("integer_value", INTEGER), dsl.abs(dsl + buildQuery(DSL.equal(ref("integer_value", INTEGER), DSL.abs(DSL .add(literal(1), literal(0))))) ); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQueryTest.java index ace10a019f..37b8326ef4 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQueryTest.java @@ -14,15 +14,13 @@ import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class LuceneQueryTest { @Test void should_not_support_single_argument_by_default() { - DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - assertFalse(new LuceneQuery(){}.canSupport(dsl.abs(DSL.ref("age", INTEGER)))); + assertFalse(new LuceneQuery(){}.canSupport(DSL.abs(DSL.ref("age", INTEGER)))); } @Test diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchBoolPrefixQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchBoolPrefixQueryTest.java index c30e06bc1a..162c55fcaf 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchBoolPrefixQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchBoolPrefixQueryTest.java @@ -23,32 +23,29 @@ import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.NamedArgumentExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.MatchBoolPrefixQuery; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class MatchBoolPrefixQueryTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); private final MatchBoolPrefixQuery matchBoolPrefixQuery = new MatchBoolPrefixQuery(); private final FunctionName matchBoolPrefix = FunctionName.of("match_bool_prefix"); static Stream> generateValidData() { - final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - NamedArgumentExpression field = dsl.namedArgument("field", DSL.literal("field_value")); - NamedArgumentExpression query = dsl.namedArgument("query", DSL.literal("query_value")); + NamedArgumentExpression field = DSL.namedArgument("field", DSL.literal("field_value")); + NamedArgumentExpression query = DSL.namedArgument("query", DSL.literal("query_value")); return List.of( - dsl.namedArgument("fuzziness", DSL.literal("AUTO")), - dsl.namedArgument("max_expansions", DSL.literal("50")), - dsl.namedArgument("prefix_length", DSL.literal("0")), - dsl.namedArgument("fuzzy_transpositions", DSL.literal("true")), - dsl.namedArgument("fuzzy_rewrite", DSL.literal("constant_score")), - dsl.namedArgument("minimum_should_match", DSL.literal("3")), - dsl.namedArgument("boost", DSL.literal("1")), - dsl.namedArgument("analyzer", DSL.literal("simple")), - dsl.namedArgument("operator", DSL.literal("Or")), - dsl.namedArgument("operator", DSL.literal("and")) + DSL.namedArgument("fuzziness", DSL.literal("AUTO")), + DSL.namedArgument("max_expansions", DSL.literal("50")), + DSL.namedArgument("prefix_length", DSL.literal("0")), + DSL.namedArgument("fuzzy_transpositions", DSL.literal("true")), + DSL.namedArgument("fuzzy_rewrite", DSL.literal("constant_score")), + DSL.namedArgument("minimum_should_match", DSL.literal("3")), + DSL.namedArgument("boost", DSL.literal("1")), + DSL.namedArgument("analyzer", DSL.literal("simple")), + DSL.namedArgument("operator", DSL.literal("Or")), + DSL.namedArgument("operator", DSL.literal("and")) ).stream().map(arg -> List.of(field, query, arg)); } @@ -61,8 +58,8 @@ public void test_valid_arguments(List validArgs) { @Test public void test_valid_when_two_arguments() { List arguments = List.of( - dsl.namedArgument("field", "field_value"), - dsl.namedArgument("query", "query_value")); + DSL.namedArgument("field", "field_value"), + DSL.namedArgument("query", "query_value")); Assertions.assertNotNull(matchBoolPrefixQuery.build(new MatchExpression(arguments))); } @@ -75,7 +72,7 @@ public void test_SyntaxCheckException_when_no_arguments() { @Test public void test_SyntaxCheckException_when_one_argument() { - List arguments = List.of(dsl.namedArgument("field", "field_value")); + List arguments = List.of(DSL.namedArgument("field", "field_value")); assertThrows(SyntaxCheckException.class, () -> matchBoolPrefixQuery.build(new MatchExpression(arguments))); } @@ -83,9 +80,9 @@ public void test_SyntaxCheckException_when_one_argument() { @Test public void test_SemanticCheckException_when_invalid_argument() { List arguments = List.of( - dsl.namedArgument("field", "field_value"), - dsl.namedArgument("query", "query_value"), - dsl.namedArgument("unsupported", "unsupported_value")); + DSL.namedArgument("field", "field_value"), + DSL.namedArgument("query", "query_value"), + DSL.namedArgument("unsupported", "unsupported_value")); Assertions.assertThrows(SemanticCheckException.class, () -> matchBoolPrefixQuery.build(new MatchExpression(arguments))); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhrasePrefixQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhrasePrefixQueryTest.java index 8e1a2fcdf0..c6ec2d95c1 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhrasePrefixQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhrasePrefixQueryTest.java @@ -20,7 +20,6 @@ import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.FunctionExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.MatchPhrasePrefixQuery; @@ -28,7 +27,6 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class MatchPhrasePrefixQueryTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); private final MatchPhrasePrefixQuery matchPhrasePrefixQuery = new MatchPhrasePrefixQuery(); private final FunctionName matchPhrasePrefix = FunctionName.of("match_phrase_prefix"); @@ -41,7 +39,7 @@ public void test_SyntaxCheckException_when_no_arguments() { @Test public void test_SyntaxCheckException_when_one_argument() { - List arguments = List.of(dsl.namedArgument("field", "test")); + List arguments = List.of(DSL.namedArgument("field", "test")); assertThrows(SyntaxCheckException.class, () -> matchPhrasePrefixQuery.build(new MatchPhraseExpression(arguments))); } @@ -49,9 +47,9 @@ public void test_SyntaxCheckException_when_one_argument() { @Test public void test_SyntaxCheckException_when_invalid_parameter() { List arguments = List.of( - dsl.namedArgument("field", "test"), - dsl.namedArgument("query", "test2"), - dsl.namedArgument("unsupported", "3")); + DSL.namedArgument("field", "test"), + DSL.namedArgument("query", "test2"), + DSL.namedArgument("unsupported", "3")); Assertions.assertThrows(SemanticCheckException.class, () -> matchPhrasePrefixQuery.build(new MatchPhraseExpression(arguments))); } @@ -59,9 +57,9 @@ public void test_SyntaxCheckException_when_invalid_parameter() { @Test public void test_analyzer_parameter() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("analyzer", "standard") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("analyzer", "standard") ); Assertions.assertNotNull(matchPhrasePrefixQuery.build(new MatchPhraseExpression(arguments))); } @@ -69,17 +67,17 @@ public void test_analyzer_parameter() { @Test public void build_succeeds_with_two_arguments() { List arguments = List.of( - dsl.namedArgument("field", "test"), - dsl.namedArgument("query", "test2")); + DSL.namedArgument("field", "test"), + DSL.namedArgument("query", "test2")); Assertions.assertNotNull(matchPhrasePrefixQuery.build(new MatchPhraseExpression(arguments))); } @Test public void test_slop_parameter() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("slop", "2") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("slop", "2") ); Assertions.assertNotNull(matchPhrasePrefixQuery.build(new MatchPhraseExpression(arguments))); } @@ -87,9 +85,9 @@ public void test_slop_parameter() { @Test public void test_zero_terms_query_parameter() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("zero_terms_query", "ALL") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("zero_terms_query", "ALL") ); Assertions.assertNotNull(matchPhrasePrefixQuery.build(new MatchPhraseExpression(arguments))); } @@ -97,9 +95,9 @@ public void test_zero_terms_query_parameter() { @Test public void test_zero_terms_query_parameter_lower_case() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("zero_terms_query", "all") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("zero_terms_query", "all") ); Assertions.assertNotNull(matchPhrasePrefixQuery.build(new MatchPhraseExpression(arguments))); } @@ -107,9 +105,9 @@ public void test_zero_terms_query_parameter_lower_case() { @Test public void test_boost_parameter() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("boost", "0.1") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("boost", "0.1") ); Assertions.assertNotNull(matchPhrasePrefixQuery.build(new MatchPhraseExpression(arguments))); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java index 09e25fe569..78b000bba3 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java @@ -20,7 +20,6 @@ import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.FunctionExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.MatchPhraseQuery; @@ -28,7 +27,6 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class MatchPhraseQueryTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); private final MatchPhraseQuery matchPhraseQuery = new MatchPhraseQuery(); private final FunctionName matchPhrase = FunctionName.of("match_phrase"); @@ -41,7 +39,7 @@ public void test_SyntaxCheckException_when_no_arguments() { @Test public void test_SyntaxCheckException_when_one_argument() { - List arguments = List.of(dsl.namedArgument("field", "test")); + List arguments = List.of(DSL.namedArgument("field", "test")); assertThrows(SyntaxCheckException.class, () -> matchPhraseQuery.build(new MatchPhraseExpression(arguments))); } @@ -49,9 +47,9 @@ public void test_SyntaxCheckException_when_one_argument() { @Test public void test_SyntaxCheckException_when_invalid_parameter() { List arguments = List.of( - dsl.namedArgument("field", "test"), - dsl.namedArgument("query", "test2"), - dsl.namedArgument("unsupported", "3")); + DSL.namedArgument("field", "test"), + DSL.namedArgument("query", "test2"), + DSL.namedArgument("unsupported", "3")); Assertions.assertThrows(SemanticCheckException.class, () -> matchPhraseQuery.build(new MatchPhraseExpression(arguments))); } @@ -59,9 +57,9 @@ public void test_SyntaxCheckException_when_invalid_parameter() { @Test public void test_analyzer_parameter() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("analyzer", "standard") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("analyzer", "standard") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression(arguments))); } @@ -69,17 +67,17 @@ public void test_analyzer_parameter() { @Test public void build_succeeds_with_two_arguments() { List arguments = List.of( - dsl.namedArgument("field", "test"), - dsl.namedArgument("query", "test2")); + DSL.namedArgument("field", "test"), + DSL.namedArgument("query", "test2")); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression(arguments))); } @Test public void test_slop_parameter() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("slop", "2") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("slop", "2") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression(arguments))); } @@ -87,9 +85,9 @@ public void test_slop_parameter() { @Test public void test_zero_terms_query_parameter() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("zero_terms_query", "ALL") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("zero_terms_query", "ALL") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression(arguments))); } @@ -97,9 +95,9 @@ public void test_zero_terms_query_parameter() { @Test public void test_zero_terms_query_parameter_lower_case() { List arguments = List.of( - dsl.namedArgument("field", "t1"), - dsl.namedArgument("query", "t2"), - dsl.namedArgument("zero_terms_query", "all") + DSL.namedArgument("field", "t1"), + DSL.namedArgument("query", "t2"), + DSL.namedArgument("zero_terms_query", "all") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression(arguments))); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchQueryTest.java index 60dd938f78..1973892403 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchQueryTest.java @@ -23,88 +23,85 @@ import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.NamedArgumentExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.MatchQuery; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class MatchQueryTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); private final MatchQuery matchQuery = new MatchQuery(); private final FunctionName match = FunctionName.of("match"); static Stream> generateValidData() { - final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); return Stream.of( List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("analyzer", DSL.literal("standard")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("analyzer", DSL.literal("standard")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("fuzziness", DSL.literal("AUTO")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("fuzziness", DSL.literal("AUTO")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("max_expansions", DSL.literal("50")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("max_expansions", DSL.literal("50")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("prefix_length", DSL.literal("0")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("prefix_length", DSL.literal("0")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("fuzzy_transpositions", DSL.literal("true")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("fuzzy_transpositions", DSL.literal("true")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("fuzzy_rewrite", DSL.literal("constant_score")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("fuzzy_rewrite", DSL.literal("constant_score")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("lenient", DSL.literal("false")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("lenient", DSL.literal("false")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("operator", DSL.literal("OR")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("operator", DSL.literal("OR")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("minimum_should_match", DSL.literal("3")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("minimum_should_match", DSL.literal("3")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("zero_terms_query", DSL.literal("NONE")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("zero_terms_query", DSL.literal("NONE")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("zero_terms_query", DSL.literal("none")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("zero_terms_query", DSL.literal("none")) ), List.of( - dsl.namedArgument("field", DSL.literal("field_value")), - dsl.namedArgument("query", DSL.literal("query_value")), - dsl.namedArgument("boost", DSL.literal("1")) + DSL.namedArgument("field", DSL.literal("field_value")), + DSL.namedArgument("query", DSL.literal("query_value")), + DSL.namedArgument("boost", DSL.literal("1")) ) ); } @@ -140,7 +137,7 @@ public void test_SemanticCheckException_when_invalid_parameter() { } private NamedArgumentExpression namedArgument(String name, String value) { - return dsl.namedArgument(name, DSL.literal(value)); + return DSL.namedArgument(name, DSL.literal(value)); } private class MatchExpression extends FunctionExpression { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MultiMatchTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MultiMatchTest.java index 748384f4c8..f4ea11241e 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MultiMatchTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MultiMatchTest.java @@ -29,15 +29,12 @@ import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.LiteralExpression; import org.opensearch.sql.expression.NamedArgumentExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.MultiMatchQuery; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class MultiMatchTest { - private static final DSL dsl = new ExpressionConfig() - .dsl(new ExpressionConfig().functionRepository()); private final MultiMatchQuery multiMatchQuery = new MultiMatchQuery(); private final FunctionName multiMatch = FunctionName.of("multi_match"); private static final LiteralExpression fields_value = DSL.literal( @@ -49,83 +46,83 @@ class MultiMatchTest { static Stream> generateValidData() { return Stream.of( List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("analyzer", DSL.literal("simple")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("analyzer", DSL.literal("simple")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("boost", DSL.literal("1.3")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("boost", DSL.literal("1.3")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("cutoff_frequency", DSL.literal("4.2")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("cutoff_frequency", DSL.literal("4.2")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("fuzziness", DSL.literal("AUTO:2,4")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("fuzziness", DSL.literal("AUTO:2,4")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("fuzzy_transpositions", DSL.literal("true")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("fuzzy_transpositions", DSL.literal("true")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("lenient", DSL.literal("true")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("lenient", DSL.literal("true")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("max_expansions", DSL.literal("7")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("max_expansions", DSL.literal("7")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("minimum_should_match", DSL.literal("4")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("minimum_should_match", DSL.literal("4")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("operator", DSL.literal("AND")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("operator", DSL.literal("AND")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("prefix_length", DSL.literal("7")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("prefix_length", DSL.literal("7")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("tie_breaker", DSL.literal("0.3")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("tie_breaker", DSL.literal("0.3")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("type", DSL.literal("cross_fields")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("type", DSL.literal("cross_fields")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("zero_terms_query", DSL.literal("ALL")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("zero_terms_query", DSL.literal("ALL")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("zero_terms_query", DSL.literal("all")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("zero_terms_query", DSL.literal("all")) ) ); } @@ -156,13 +153,13 @@ public void test_SemanticCheckException_when_invalid_parameter() { List arguments = List.of( namedArgument("fields", fields_value), namedArgument("query", query_value), - dsl.namedArgument("unsupported", "unsupported_value")); + DSL.namedArgument("unsupported", "unsupported_value")); Assertions.assertThrows(SemanticCheckException.class, () -> multiMatchQuery.build(new MultiMatchExpression(arguments))); } private NamedArgumentExpression namedArgument(String name, LiteralExpression value) { - return dsl.namedArgument(name, value); + return DSL.namedArgument(name, value); } private class MultiMatchExpression extends FunctionExpression { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryStringTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryStringTest.java index 4692f046db..ab3dc406b8 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryStringTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryStringTest.java @@ -28,15 +28,12 @@ import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.LiteralExpression; import org.opensearch.sql.expression.NamedArgumentExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.QueryStringQuery; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class QueryStringTest { - private static final DSL dsl = new ExpressionConfig() - .dsl(new ExpressionConfig().functionRepository()); private final QueryStringQuery queryStringQuery = new QueryStringQuery(); private final FunctionName queryStringFunc = FunctionName.of("query_string"); private static final LiteralExpression fields_value = DSL.literal( @@ -46,38 +43,38 @@ class QueryStringTest { private static final LiteralExpression query_value = DSL.literal("query_value"); static Stream> generateValidData() { - Expression field = dsl.namedArgument("fields", fields_value); - Expression query = dsl.namedArgument("query", query_value); + Expression field = DSL.namedArgument("fields", fields_value); + Expression query = DSL.namedArgument("query", query_value); return List.of( - dsl.namedArgument("analyzer", DSL.literal("standard")), - dsl.namedArgument("analyze_wildcard", DSL.literal("true")), - dsl.namedArgument("allow_leading_wildcard", DSL.literal("true")), - dsl.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")), - dsl.namedArgument("boost", DSL.literal("1")), - dsl.namedArgument("default_operator", DSL.literal("AND")), - dsl.namedArgument("default_operator", DSL.literal("and")), - dsl.namedArgument("enable_position_increments", DSL.literal("true")), - dsl.namedArgument("escape", DSL.literal("false")), - dsl.namedArgument("fuzziness", DSL.literal("1")), - dsl.namedArgument("fuzzy_rewrite", DSL.literal("constant_score")), - dsl.namedArgument("fuzzy_max_expansions", DSL.literal("42")), - dsl.namedArgument("fuzzy_prefix_length", DSL.literal("42")), - dsl.namedArgument("fuzzy_transpositions", DSL.literal("true")), - dsl.namedArgument("lenient", DSL.literal("true")), - dsl.namedArgument("max_determinized_states", DSL.literal("10000")), - dsl.namedArgument("minimum_should_match", DSL.literal("4")), - dsl.namedArgument("quote_analyzer", DSL.literal("standard")), - dsl.namedArgument("phrase_slop", DSL.literal("0")), - dsl.namedArgument("quote_field_suffix", DSL.literal(".exact")), - dsl.namedArgument("rewrite", DSL.literal("constant_score")), - dsl.namedArgument("type", DSL.literal("best_fields")), - dsl.namedArgument("tie_breaker", DSL.literal("0.3")), - dsl.namedArgument("time_zone", DSL.literal("Canada/Pacific")), - dsl.namedArgument("ANALYZER", DSL.literal("standard")), - dsl.namedArgument("ANALYZE_wildcard", DSL.literal("true")), - dsl.namedArgument("Allow_Leading_wildcard", DSL.literal("true")), - dsl.namedArgument("Auto_Generate_Synonyms_Phrase_Query", DSL.literal("true")), - dsl.namedArgument("Boost", DSL.literal("1")) + DSL.namedArgument("analyzer", DSL.literal("standard")), + DSL.namedArgument("analyze_wildcard", DSL.literal("true")), + DSL.namedArgument("allow_leading_wildcard", DSL.literal("true")), + DSL.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")), + DSL.namedArgument("boost", DSL.literal("1")), + DSL.namedArgument("default_operator", DSL.literal("AND")), + DSL.namedArgument("default_operator", DSL.literal("and")), + DSL.namedArgument("enable_position_increments", DSL.literal("true")), + DSL.namedArgument("escape", DSL.literal("false")), + DSL.namedArgument("fuzziness", DSL.literal("1")), + DSL.namedArgument("fuzzy_rewrite", DSL.literal("constant_score")), + DSL.namedArgument("fuzzy_max_expansions", DSL.literal("42")), + DSL.namedArgument("fuzzy_prefix_length", DSL.literal("42")), + DSL.namedArgument("fuzzy_transpositions", DSL.literal("true")), + DSL.namedArgument("lenient", DSL.literal("true")), + DSL.namedArgument("max_determinized_states", DSL.literal("10000")), + DSL.namedArgument("minimum_should_match", DSL.literal("4")), + DSL.namedArgument("quote_analyzer", DSL.literal("standard")), + DSL.namedArgument("phrase_slop", DSL.literal("0")), + DSL.namedArgument("quote_field_suffix", DSL.literal(".exact")), + DSL.namedArgument("rewrite", DSL.literal("constant_score")), + DSL.namedArgument("type", DSL.literal("best_fields")), + DSL.namedArgument("tie_breaker", DSL.literal("0.3")), + DSL.namedArgument("time_zone", DSL.literal("Canada/Pacific")), + DSL.namedArgument("ANALYZER", DSL.literal("standard")), + DSL.namedArgument("ANALYZE_wildcard", DSL.literal("true")), + DSL.namedArgument("Allow_Leading_wildcard", DSL.literal("true")), + DSL.namedArgument("Auto_Generate_Synonyms_Phrase_Query", DSL.literal("true")), + DSL.namedArgument("Boost", DSL.literal("1")) ).stream().map(arg -> List.of(field, query, arg)); } @@ -113,11 +110,11 @@ public void test_SemanticCheckException_when_invalid_parameter() { } private NamedArgumentExpression namedArgument(String name, String value) { - return dsl.namedArgument(name, DSL.literal(value)); + return DSL.namedArgument(name, DSL.literal(value)); } private NamedArgumentExpression namedArgument(String name, LiteralExpression value) { - return dsl.namedArgument(name, value); + return DSL.namedArgument(name, value); } private class QueryStringExpression extends FunctionExpression { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryTest.java index e0681bceac..a61b47b7b1 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryTest.java @@ -24,51 +24,48 @@ import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.LiteralExpression; import org.opensearch.sql.expression.NamedArgumentExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.QueryQuery; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class QueryTest { - private static final DSL dsl = new ExpressionConfig() - .dsl(new ExpressionConfig().functionRepository()); private final QueryQuery queryQuery = new QueryQuery(); private final FunctionName queryFunc = FunctionName.of("query"); private static final LiteralExpression query_value = DSL.literal("title:query_value"); static Stream> generateValidData() { - Expression query = dsl.namedArgument("query", query_value); + Expression query = DSL.namedArgument("query", query_value); return List.of( - dsl.namedArgument("analyzer", DSL.literal("standard")), - dsl.namedArgument("analyze_wildcard", DSL.literal("true")), - dsl.namedArgument("allow_leading_wildcard", DSL.literal("true")), - dsl.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")), - dsl.namedArgument("boost", DSL.literal("1")), - dsl.namedArgument("default_operator", DSL.literal("AND")), - dsl.namedArgument("default_operator", DSL.literal("and")), - dsl.namedArgument("enable_position_increments", DSL.literal("true")), - dsl.namedArgument("escape", DSL.literal("false")), - dsl.namedArgument("fuzziness", DSL.literal("1")), - dsl.namedArgument("fuzzy_rewrite", DSL.literal("constant_score")), - dsl.namedArgument("fuzzy_max_expansions", DSL.literal("42")), - dsl.namedArgument("fuzzy_prefix_length", DSL.literal("42")), - dsl.namedArgument("fuzzy_transpositions", DSL.literal("true")), - dsl.namedArgument("lenient", DSL.literal("true")), - dsl.namedArgument("max_determinized_states", DSL.literal("10000")), - dsl.namedArgument("minimum_should_match", DSL.literal("4")), - dsl.namedArgument("quote_analyzer", DSL.literal("standard")), - dsl.namedArgument("phrase_slop", DSL.literal("0")), - dsl.namedArgument("quote_field_suffix", DSL.literal(".exact")), - dsl.namedArgument("rewrite", DSL.literal("constant_score")), - dsl.namedArgument("type", DSL.literal("best_fields")), - dsl.namedArgument("tie_breaker", DSL.literal("0.3")), - dsl.namedArgument("time_zone", DSL.literal("Canada/Pacific")), - dsl.namedArgument("ANALYZER", DSL.literal("standard")), - dsl.namedArgument("ANALYZE_wildcard", DSL.literal("true")), - dsl.namedArgument("Allow_Leading_wildcard", DSL.literal("true")), - dsl.namedArgument("Auto_Generate_Synonyms_Phrase_Query", DSL.literal("true")), - dsl.namedArgument("Boost", DSL.literal("1")) + DSL.namedArgument("analyzer", DSL.literal("standard")), + DSL.namedArgument("analyze_wildcard", DSL.literal("true")), + DSL.namedArgument("allow_leading_wildcard", DSL.literal("true")), + DSL.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")), + DSL.namedArgument("boost", DSL.literal("1")), + DSL.namedArgument("default_operator", DSL.literal("AND")), + DSL.namedArgument("default_operator", DSL.literal("and")), + DSL.namedArgument("enable_position_increments", DSL.literal("true")), + DSL.namedArgument("escape", DSL.literal("false")), + DSL.namedArgument("fuzziness", DSL.literal("1")), + DSL.namedArgument("fuzzy_rewrite", DSL.literal("constant_score")), + DSL.namedArgument("fuzzy_max_expansions", DSL.literal("42")), + DSL.namedArgument("fuzzy_prefix_length", DSL.literal("42")), + DSL.namedArgument("fuzzy_transpositions", DSL.literal("true")), + DSL.namedArgument("lenient", DSL.literal("true")), + DSL.namedArgument("max_determinized_states", DSL.literal("10000")), + DSL.namedArgument("minimum_should_match", DSL.literal("4")), + DSL.namedArgument("quote_analyzer", DSL.literal("standard")), + DSL.namedArgument("phrase_slop", DSL.literal("0")), + DSL.namedArgument("quote_field_suffix", DSL.literal(".exact")), + DSL.namedArgument("rewrite", DSL.literal("constant_score")), + DSL.namedArgument("type", DSL.literal("best_fields")), + DSL.namedArgument("tie_breaker", DSL.literal("0.3")), + DSL.namedArgument("time_zone", DSL.literal("Canada/Pacific")), + DSL.namedArgument("ANALYZER", DSL.literal("standard")), + DSL.namedArgument("ANALYZE_wildcard", DSL.literal("true")), + DSL.namedArgument("Allow_Leading_wildcard", DSL.literal("true")), + DSL.namedArgument("Auto_Generate_Synonyms_Phrase_Query", DSL.literal("true")), + DSL.namedArgument("Boost", DSL.literal("1")) ).stream().map(arg -> List.of(query, arg)); } @@ -115,11 +112,11 @@ public void test_SemanticCheckException_when_sending_parameter_multiple_times() } private NamedArgumentExpression namedArgument(String name, String value) { - return dsl.namedArgument(name, DSL.literal(value)); + return DSL.namedArgument(name, DSL.literal(value)); } private NamedArgumentExpression namedArgument(String name, LiteralExpression value) { - return dsl.namedArgument(name, value); + return DSL.namedArgument(name, value); } private class QueryExpression extends FunctionExpression { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/SimpleQueryStringTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/SimpleQueryStringTest.java index de8576e9d4..f7129117a1 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/SimpleQueryStringTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/SimpleQueryStringTest.java @@ -29,15 +29,12 @@ import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.LiteralExpression; import org.opensearch.sql.expression.NamedArgumentExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.SimpleQueryStringQuery; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class SimpleQueryStringTest { - private static final DSL dsl = new ExpressionConfig() - .dsl(new ExpressionConfig().functionRepository()); private final SimpleQueryStringQuery simpleQueryStringQuery = new SimpleQueryStringQuery(); private final FunctionName simpleQueryString = FunctionName.of("simple_query_string"); private static final LiteralExpression fields_value = DSL.literal( @@ -49,107 +46,107 @@ class SimpleQueryStringTest { static Stream> generateValidData() { return Stream.of( List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("analyze_wildcard", DSL.literal("true")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("analyze_wildcard", DSL.literal("true")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("analyzer", DSL.literal("standard")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("analyzer", DSL.literal("standard")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("auto_generate_synonyms_phrase_query", DSL.literal("true")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("flags", DSL.literal("PREFIX")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("flags", DSL.literal("PREFIX")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("flags", DSL.literal("PREFIX|NOT|AND")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("flags", DSL.literal("PREFIX|NOT|AND")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("flags", DSL.literal("NOT|AND")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("flags", DSL.literal("NOT|AND")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("flags", DSL.literal("PREFIX|not|AND")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("flags", DSL.literal("PREFIX|not|AND")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("flags", DSL.literal("not|and")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("flags", DSL.literal("not|and")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("fuzzy_max_expansions", DSL.literal("42")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("fuzzy_max_expansions", DSL.literal("42")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("fuzzy_prefix_length", DSL.literal("42")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("fuzzy_prefix_length", DSL.literal("42")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("fuzzy_transpositions", DSL.literal("true")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("fuzzy_transpositions", DSL.literal("true")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("lenient", DSL.literal("true")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("lenient", DSL.literal("true")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("default_operator", DSL.literal("AND")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("default_operator", DSL.literal("AND")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("default_operator", DSL.literal("and")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("default_operator", DSL.literal("and")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("minimum_should_match", DSL.literal("4")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("minimum_should_match", DSL.literal("4")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("quote_field_suffix", DSL.literal(".exact")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("quote_field_suffix", DSL.literal(".exact")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("boost", DSL.literal("1")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("boost", DSL.literal("1")) ), List.of( - dsl.namedArgument("FIELDS", fields_value), - dsl.namedArgument("QUERY", query_value) + DSL.namedArgument("FIELDS", fields_value), + DSL.namedArgument("QUERY", query_value) ), List.of( - dsl.namedArgument("FIELDS", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("ANALYZE_wildcard", DSL.literal("true")) + DSL.namedArgument("FIELDS", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("ANALYZE_wildcard", DSL.literal("true")) ), List.of( - dsl.namedArgument("fields", fields_value), - dsl.namedArgument("query", query_value), - dsl.namedArgument("analyZER", DSL.literal("standard")) + DSL.namedArgument("fields", fields_value), + DSL.namedArgument("query", query_value), + DSL.namedArgument("analyZER", DSL.literal("standard")) ) ); } @@ -186,11 +183,11 @@ public void test_SemanticCheckException_when_invalid_parameter() { } private NamedArgumentExpression namedArgument(String name, String value) { - return dsl.namedArgument(name, DSL.literal(value)); + return DSL.namedArgument(name, DSL.literal(value)); } private NamedArgumentExpression namedArgument(String name, LiteralExpression value) { - return dsl.namedArgument(name, value); + return DSL.namedArgument(name, value); } private class SimpleQueryStringExpression extends FunctionExpression { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiFieldQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiFieldQueryTest.java index c50f2efb0d..678a77b82f 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiFieldQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiFieldQueryTest.java @@ -23,11 +23,9 @@ import org.opensearch.sql.data.model.ExprValueUtils; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.LiteralExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; class MultiFieldQueryTest { MultiFieldQuery query; - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); private final String testQueryName = "test_query"; private final Map actionMap = ImmutableMap.of("paramA", (o, v) -> o); @@ -49,9 +47,9 @@ void createQueryBuilderTest() { var fieldSpec = ImmutableMap.builder().put(sampleField, ExprValueUtils.floatValue(sampleValue)).build(); - query.createQueryBuilder(List.of(dsl.namedArgument("fields", + query.createQueryBuilder(List.of(DSL.namedArgument("fields", new LiteralExpression(ExprTupleValue.fromExprValueMap(fieldSpec))), - dsl.namedArgument("query", + DSL.namedArgument("query", new LiteralExpression(ExprValueUtils.stringValue(sampleQuery))))); verify(query).createBuilder(argThat( diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQueryTest.java index e06dd7d32a..c4e4f1242a 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQueryTest.java @@ -19,11 +19,9 @@ import org.opensearch.sql.data.model.ExprValueUtils; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.LiteralExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; class NoFieldQueryTest { NoFieldQuery query; - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); private final String testQueryName = "test_query"; private final Map actionMap = ImmutableMap.of("paramA", (o, v) -> o); @@ -41,7 +39,7 @@ void createQueryBuilderTest() { String sampleQuery = "field:query"; query.createQueryBuilder(List.of( - dsl.namedArgument("query", + DSL.namedArgument("query", new LiteralExpression(ExprValueUtils.stringValue(sampleQuery))))); verify(query).createBuilder(eq(sampleQuery)); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/SingleFieldQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/SingleFieldQueryTest.java index d6f178b1d6..b2d650602b 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/SingleFieldQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/SingleFieldQueryTest.java @@ -19,11 +19,9 @@ import org.opensearch.sql.data.model.ExprValueUtils; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.LiteralExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; class SingleFieldQueryTest { SingleFieldQuery query; - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); private final String testQueryName = "test_query"; private final Map actionMap = ImmutableMap.of("paramA", (o, v) -> o); @@ -41,9 +39,9 @@ void createQueryBuilderTest() { String sampleQuery = "sample query"; String sampleField = "fieldA"; - query.createQueryBuilder(List.of(dsl.namedArgument("field", + query.createQueryBuilder(List.of(DSL.namedArgument("field", new LiteralExpression(ExprValueUtils.stringValue(sampleField))), - dsl.namedArgument("query", + DSL.namedArgument("query", new LiteralExpression(ExprValueUtils.stringValue(sampleQuery))))); verify(query).createBuilder(eq(sampleField), 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 32aa73babe..f3e3bf5dfc 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 @@ -15,12 +15,9 @@ import org.junit.jupiter.api.Test; import org.opensearch.sql.ast.tree.Sort; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; class SortQueryBuilderTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - private SortQueryBuilder sortQueryBuilder = new SortQueryBuilder(); @Test @@ -31,7 +28,7 @@ void build_sortbuilder_from_reference() { @Test void build_sortbuilder_from_function_should_throw_exception() { final IllegalStateException exception = - assertThrows(IllegalStateException.class, () -> sortQueryBuilder.build(dsl.equal(DSL.ref( + assertThrows(IllegalStateException.class, () -> sortQueryBuilder.build(DSL.equal(DSL.ref( "intV", INTEGER), DSL.literal(1)), Sort.SortOption.DEFAULT_ASC)); assertThat(exception.getMessage(), Matchers.containsString("unsupported expression")); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/serialization/DefaultExpressionSerializerTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/serialization/DefaultExpressionSerializerTest.java index 1bec475e04..72a319dbfe 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/serialization/DefaultExpressionSerializerTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/serialization/DefaultExpressionSerializerTest.java @@ -12,7 +12,6 @@ import static org.opensearch.sql.expression.DSL.literal; import static org.opensearch.sql.expression.DSL.ref; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -21,17 +20,11 @@ import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.ExpressionNodeVisitor; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class DefaultExpressionSerializerTest { - /** - * Initialize function repository manually to avoid dependency on Spring container. - */ - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - private final ExpressionSerializer serializer = new DefaultExpressionSerializer(); @Test @@ -50,14 +43,14 @@ public void can_serialize_and_deserialize_references() { @Test public void can_serialize_and_deserialize_predicates() { - Expression original = dsl.or(literal(true), dsl.less(literal(1), literal(2))); + Expression original = DSL.or(literal(true), DSL.less(literal(1), literal(2))); Expression actual = serializer.deserialize(serializer.serialize(original)); assertEquals(original, actual); } @Test public void can_serialize_and_deserialize_functions() { - Expression original = dsl.abs(literal(30.0)); + Expression original = DSL.abs(literal(30.0)); Expression actual = serializer.deserialize(serializer.serialize(original)); assertEquals(original, actual); } diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java index e1d29a5775..fab14966d8 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java @@ -5,13 +5,24 @@ package org.opensearch.sql.plugin; +import static org.opensearch.sql.datasource.model.DataSourceMetadata.defaultOpenSearchDataSourceMetadata; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.opensearch.action.ActionRequest; import org.opensearch.action.ActionResponse; import org.opensearch.action.ActionType; @@ -40,7 +51,10 @@ import org.opensearch.script.ScriptContext; import org.opensearch.script.ScriptEngine; import org.opensearch.script.ScriptService; -import org.opensearch.sql.catalog.CatalogService; +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.DataSourceServiceImpl; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; import org.opensearch.sql.legacy.esdomain.LocalClusterState; import org.opensearch.sql.legacy.executor.AsyncRestExecutor; import org.opensearch.sql.legacy.metrics.Metrics; @@ -50,12 +64,11 @@ import org.opensearch.sql.opensearch.security.SecurityAccess; import org.opensearch.sql.opensearch.setting.LegacyOpenDistroSettings; import org.opensearch.sql.opensearch.setting.OpenSearchSettings; -import org.opensearch.sql.opensearch.storage.OpenSearchStorageEngine; +import org.opensearch.sql.opensearch.storage.OpenSearchDataSourceFactory; import org.opensearch.sql.opensearch.storage.script.ExpressionScriptEngine; import org.opensearch.sql.opensearch.storage.serialization.DefaultExpressionSerializer; -import org.opensearch.sql.plugin.catalog.CatalogServiceImpl; -import org.opensearch.sql.plugin.catalog.CatalogSettings; import org.opensearch.sql.plugin.config.OpenSearchPluginConfig; +import org.opensearch.sql.plugin.datasource.DataSourceSettings; import org.opensearch.sql.plugin.rest.RestPPLQueryAction; import org.opensearch.sql.plugin.rest.RestPPLStatsAction; import org.opensearch.sql.plugin.rest.RestQuerySettingsAction; @@ -63,8 +76,9 @@ import org.opensearch.sql.plugin.transport.TransportPPLQueryAction; import org.opensearch.sql.plugin.transport.TransportPPLQueryResponse; import org.opensearch.sql.ppl.config.PPLServiceConfig; +import org.opensearch.sql.prometheus.storage.PrometheusStorageFactory; import org.opensearch.sql.sql.config.SQLServiceConfig; -import org.opensearch.sql.storage.StorageEngine; +import org.opensearch.sql.storage.DataSourceFactory; import org.opensearch.threadpool.ExecutorBuilder; import org.opensearch.threadpool.FixedExecutorBuilder; import org.opensearch.threadpool.ThreadPool; @@ -73,6 +87,8 @@ public class SQLPlugin extends Plugin implements ActionPlugin, ScriptPlugin, ReloadablePlugin { + private static final Logger LOG = LogManager.getLogger(); + private ClusterService clusterService; /** @@ -84,6 +100,8 @@ public class SQLPlugin extends Plugin implements ActionPlugin, ScriptPlugin, Rel private AnnotationConfigApplicationContext applicationContext; + private DataSourceService dataSourceService; + public String name() { return "sql"; } @@ -142,8 +160,15 @@ public Collection createComponents( this.clusterService = clusterService; this.pluginSettings = new OpenSearchSettings(clusterService.getClusterSettings()); this.client = (NodeClient) client; - CatalogServiceImpl.getInstance().loadConnectors(clusterService.getSettings()); - CatalogServiceImpl.getInstance().registerDefaultOpenSearchCatalog(openSearchStorageEngine()); + this.dataSourceService = + new DataSourceServiceImpl( + new ImmutableSet.Builder() + .add(new OpenSearchDataSourceFactory( + new OpenSearchNodeClient(this.client), pluginSettings)) + .add(new PrometheusStorageFactory()) + .build()); + dataSourceService.addDataSource(defaultOpenSearchDataSourceMetadata()); + loadDataSources(dataSourceService, clusterService.getSettings()); LocalClusterState.state().setClusterService(clusterService); LocalClusterState.state().setPluginSettings((OpenSearchSettings) pluginSettings); @@ -155,7 +180,7 @@ public Collection createComponents( applicationContext.registerBean( org.opensearch.sql.common.setting.Settings.class, () -> pluginSettings); applicationContext.registerBean( - CatalogService.class, () -> CatalogServiceImpl.getInstance()); + DataSourceService.class, () -> dataSourceService); applicationContext.register(OpenSearchPluginConfig.class); applicationContext.register(PPLServiceConfig.class); applicationContext.register(SQLServiceConfig.class); @@ -184,7 +209,7 @@ public List> getSettings() { return new ImmutableList.Builder>() .addAll(LegacyOpenDistroSettings.legacySettings()) .addAll(OpenSearchSettings.pluginSettings()) - .add(CatalogSettings.CATALOG_CONFIG) + .add(DataSourceSettings.DATASOURCE_CONFIG) .build(); } @@ -195,12 +220,34 @@ public ScriptEngine getScriptEngine(Settings settings, Collection { + InputStream inputStream = DataSourceSettings.DATASOURCE_CONFIG.get(settings); + if (inputStream != null) { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + try { + List metadataList = + objectMapper.readValue(inputStream, new TypeReference<>() {}); + dataSourceService.addDataSource(metadataList.toArray(new DataSourceMetadata[0])); + } catch (IOException e) { + LOG.error( + "DataSource Configuration File uploaded is malformed. Verify and re-upload.", e); + } catch (Throwable e) { + LOG.error("DataSource construction failed.", e); + } + } + return null; + }); } - } diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/catalog/CatalogServiceImpl.java b/plugin/src/main/java/org/opensearch/sql/plugin/catalog/CatalogServiceImpl.java deleted file mode 100644 index 3c6e0e5281..0000000000 --- a/plugin/src/main/java/org/opensearch/sql/plugin/catalog/CatalogServiceImpl.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.plugin.catalog; - -import static org.opensearch.sql.analysis.CatalogSchemaIdentifierNameResolver.DEFAULT_CATALOG_NAME; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.common.settings.Settings; -import org.opensearch.sql.catalog.CatalogService; -import org.opensearch.sql.catalog.model.Catalog; -import org.opensearch.sql.catalog.model.CatalogMetadata; -import org.opensearch.sql.catalog.model.ConnectorType; -import org.opensearch.sql.opensearch.security.SecurityAccess; -import org.opensearch.sql.prometheus.storage.PrometheusStorageFactory; -import org.opensearch.sql.storage.StorageEngine; -import org.opensearch.sql.storage.StorageEngineFactory; - -/** - * This class manages catalogs and responsible for creating connectors to these catalogs. - */ -public class CatalogServiceImpl implements CatalogService { - - private static final CatalogServiceImpl INSTANCE = new CatalogServiceImpl(); - - private static final String CATALOG_NAME_REGEX = "[@*A-Za-z]+?[*a-zA-Z_\\-0-9]*"; - - private static final Logger LOG = LogManager.getLogger(); - - private Map catalogMap = new HashMap<>(); - - private final Map connectorTypeStorageEngineFactoryMap; - - public static CatalogServiceImpl getInstance() { - return INSTANCE; - } - - private CatalogServiceImpl() { - connectorTypeStorageEngineFactoryMap = new HashMap<>(); - PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(); - connectorTypeStorageEngineFactoryMap.put(prometheusStorageFactory.getConnectorType(), - prometheusStorageFactory); - } - - /** - * This function reads settings and loads connectors to the data stores. - * This will be invoked during start up and also when settings are updated. - * - * @param settings settings. - */ - public void loadConnectors(Settings settings) { - SecurityAccess.doPrivileged(() -> { - InputStream inputStream = CatalogSettings.CATALOG_CONFIG.get(settings); - if (inputStream != null) { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - try { - List catalogs = - objectMapper.readValue(inputStream, new TypeReference<>() { - }); - validateCatalogs(catalogs); - constructConnectors(catalogs); - } catch (IOException e) { - LOG.error("Catalog Configuration File uploaded is malformed. Verify and re-upload.", e); - } catch (Throwable e) { - LOG.error("Catalog construction failed.", e); - } - } - return null; - }); - } - - @Override - public Set getCatalogs() { - return new HashSet<>(catalogMap.values()); - } - - @Override - public Catalog getCatalog(String catalogName) { - if (!catalogMap.containsKey(catalogName)) { - throw new IllegalArgumentException( - String.format("Catalog with name %s doesn't exist.", catalogName)); - } - return catalogMap.get(catalogName); - } - - - @Override - public void registerDefaultOpenSearchCatalog(StorageEngine storageEngine) { - if (storageEngine == null) { - throw new IllegalArgumentException("Default storage engine can't be null"); - } - catalogMap.put(DEFAULT_CATALOG_NAME, - new Catalog(DEFAULT_CATALOG_NAME, ConnectorType.OPENSEARCH, storageEngine)); - } - - private StorageEngine createStorageEngine(CatalogMetadata catalog) { - ConnectorType connector = catalog.getConnector(); - switch (connector) { - case PROMETHEUS: - return connectorTypeStorageEngineFactoryMap - .get(catalog.getConnector()) - .getStorageEngine(catalog.getName(), catalog.getProperties()); - default: - throw new IllegalStateException( - String.format("Unsupported Connector: %s", connector.name())); - } - } - - private void constructConnectors(List catalogs) { - catalogMap = new HashMap<>(); - for (CatalogMetadata catalog : catalogs) { - try { - String catalogName = catalog.getName(); - StorageEngine storageEngine = createStorageEngine(catalog); - catalogMap.put(catalogName, - new Catalog(catalog.getName(), catalog.getConnector(), storageEngine)); - } catch (Throwable e) { - LOG.error("Catalog : {} storage engine creation failed with the following message: {}", - catalog.getName(), e.getMessage(), e); - } - } - } - - /** - * This can be moved to a different validator class - * when we introduce more connectors. - * - * @param catalogs catalogs. - */ - private void validateCatalogs(List catalogs) { - - Set reviewedCatalogs = new HashSet<>(); - for (CatalogMetadata catalog : catalogs) { - - if (StringUtils.isEmpty(catalog.getName())) { - throw new IllegalArgumentException( - "Missing Name Field from a catalog. Name is a required parameter."); - } - - if (!catalog.getName().matches(CATALOG_NAME_REGEX)) { - throw new IllegalArgumentException( - String.format("Catalog Name: %s contains illegal characters." - + " Allowed characters: a-zA-Z0-9_-*@ ", catalog.getName())); - } - - String catalogName = catalog.getName(); - if (reviewedCatalogs.contains(catalogName)) { - throw new IllegalArgumentException("Catalogs with same name are not allowed."); - } else { - reviewedCatalogs.add(catalogName); - } - - if (Objects.isNull(catalog.getProperties())) { - throw new IllegalArgumentException("Missing properties field in catalog configuration. " - + "Properties are required parameters"); - } - - } - } - - -} diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/config/OpenSearchPluginConfig.java b/plugin/src/main/java/org/opensearch/sql/plugin/config/OpenSearchPluginConfig.java index 596296522c..1a98510aad 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/config/OpenSearchPluginConfig.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/config/OpenSearchPluginConfig.java @@ -12,14 +12,12 @@ import org.opensearch.client.node.NodeClient; import org.opensearch.sql.analysis.Analyzer; import org.opensearch.sql.analysis.ExpressionAnalyzer; -import org.opensearch.sql.catalog.CatalogService; import org.opensearch.sql.common.setting.Settings; +import org.opensearch.sql.datasource.DataSourceService; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.QueryManager; import org.opensearch.sql.executor.QueryService; import org.opensearch.sql.executor.execution.QueryPlanFactory; -import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.function.BuiltinFunctionRepository; import org.opensearch.sql.monitor.ResourceMonitor; import org.opensearch.sql.opensearch.client.OpenSearchClient; @@ -38,7 +36,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Scope; /** @@ -46,7 +43,6 @@ * and initialize OpenSearch storage and execution engine. */ @Configuration -@Import({ExpressionConfig.class}) public class OpenSearchPluginConfig { @Autowired @@ -56,7 +52,7 @@ public class OpenSearchPluginConfig { private Settings settings; @Autowired - private CatalogService catalogService; + private DataSourceService dataSourceService; @Bean @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @@ -101,21 +97,12 @@ public QueryManager queryManager() { */ @Bean @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public QueryPlanFactory queryExecutionFactory(BuiltinFunctionRepository functionRepository) { - catalogService - .getCatalogs() - .forEach( - catalog -> - catalog - .getStorageEngine() - .getFunctions() - .forEach( - functionResolver -> - functionRepository.register(catalog.getName(), functionResolver))); + public QueryPlanFactory queryExecutionFactory() { + BuiltinFunctionRepository functionRepository = BuiltinFunctionRepository.getInstance(); Analyzer analyzer = new Analyzer(new ExpressionAnalyzer(functionRepository), - catalogService, functionRepository); + dataSourceService, functionRepository); Planner planner = - new Planner(LogicalPlanOptimizer.create(new DSL(functionRepository))); + new Planner(LogicalPlanOptimizer.create()); return new QueryPlanFactory(new QueryService(analyzer, executionEngine(), planner)); } } diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/catalog/CatalogSettings.java b/plugin/src/main/java/org/opensearch/sql/plugin/datasource/DataSourceSettings.java similarity index 62% rename from plugin/src/main/java/org/opensearch/sql/plugin/catalog/CatalogSettings.java rename to plugin/src/main/java/org/opensearch/sql/plugin/datasource/DataSourceSettings.java index 558e7558ca..9a3466df45 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/catalog/CatalogSettings.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/datasource/DataSourceSettings.java @@ -3,15 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.sql.plugin.catalog; +package org.opensearch.sql.plugin.datasource; import java.io.InputStream; import org.opensearch.common.settings.SecureSetting; import org.opensearch.common.settings.Setting; -public class CatalogSettings { +public class DataSourceSettings { - public static final Setting CATALOG_CONFIG = SecureSetting.secureFile( + public static final Setting DATASOURCE_CONFIG = SecureSetting.secureFile( "plugins.query.federation.datasources.config", null); } diff --git a/plugin/src/test/java/org/opensearch/sql/plugin/catalog/CatalogServiceImplTest.java b/plugin/src/test/java/org/opensearch/sql/plugin/catalog/CatalogServiceImplTest.java deleted file mode 100644 index cdbce55cb1..0000000000 --- a/plugin/src/test/java/org/opensearch/sql/plugin/catalog/CatalogServiceImplTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.plugin.catalog; - -import static org.opensearch.sql.analysis.CatalogSchemaIdentifierNameResolver.DEFAULT_CATALOG_NAME; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.Set; -import lombok.SneakyThrows; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.opensearch.common.settings.MockSecureSettings; -import org.opensearch.common.settings.Settings; -import org.opensearch.sql.catalog.model.Catalog; -import org.opensearch.sql.catalog.model.ConnectorType; -import org.opensearch.sql.storage.StorageEngine; - -@RunWith(MockitoJUnitRunner.class) -public class CatalogServiceImplTest { - - public static final String CATALOG_SETTING_METADATA_KEY = - "plugins.query.federation.datasources.config"; - - @Mock - private StorageEngine storageEngine; - - @SneakyThrows - @Test - public void testLoadConnectors() { - Settings settings = getCatalogSettings("catalogs.json"); - CatalogServiceImpl.getInstance().loadConnectors(settings); - Set expected = new HashSet<>() {{ - add(new Catalog("prometheus", ConnectorType.PROMETHEUS, storageEngine)); - }}; - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - } - - - @SneakyThrows - @Test - public void testLoadConnectorsWithMultipleCatalogs() { - Settings settings = getCatalogSettings("multiple_catalogs.json"); - CatalogServiceImpl.getInstance().loadConnectors(settings); - Set expected = new HashSet<>() {{ - add(new Catalog("prometheus", ConnectorType.PROMETHEUS, storageEngine)); - add(new Catalog("prometheus-1", ConnectorType.PROMETHEUS, storageEngine)); - }}; - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - } - - @SneakyThrows - @Test - public void testLoadConnectorsWithMissingName() { - Settings settings = getCatalogSettings("catalog_missing_name.json"); - Set expected = CatalogServiceImpl.getInstance().getCatalogs(); - CatalogServiceImpl.getInstance().loadConnectors(settings); - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - } - - @SneakyThrows - @Test - public void testLoadConnectorsWithDuplicateCatalogNames() { - Settings settings = getCatalogSettings("duplicate_catalog_names.json"); - Set expected = CatalogServiceImpl.getInstance().getCatalogs(); - CatalogServiceImpl.getInstance().loadConnectors(settings); - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - } - - @SneakyThrows - @Test - public void testLoadConnectorsWithMalformedJson() { - Settings settings = getCatalogSettings("malformed_catalogs.json"); - Set expected = CatalogServiceImpl.getInstance().getCatalogs(); - CatalogServiceImpl.getInstance().loadConnectors(settings); - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - } - - @SneakyThrows - @Test - public void testGetStorageEngineAfterGetCatalogs() { - Settings settings = getCatalogSettings("empty_catalog.json"); - CatalogServiceImpl.getInstance().loadConnectors(settings); - CatalogServiceImpl.getInstance().registerDefaultOpenSearchCatalog(storageEngine); - Set expected = new HashSet<>(); - expected.add(new Catalog(DEFAULT_CATALOG_NAME, ConnectorType.OPENSEARCH, storageEngine)); - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - Assert.assertEquals(storageEngine, - CatalogServiceImpl.getInstance().getCatalog(DEFAULT_CATALOG_NAME).getStorageEngine()); - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - Assert.assertEquals(storageEngine, - CatalogServiceImpl.getInstance().getCatalog(DEFAULT_CATALOG_NAME).getStorageEngine()); - IllegalArgumentException illegalArgumentException - = Assert.assertThrows(IllegalArgumentException.class, - () -> CatalogServiceImpl.getInstance().getCatalog("test")); - Assert.assertEquals("Catalog with name test doesn't exist.", - illegalArgumentException.getMessage()); - } - - - @SneakyThrows - @Test - public void testGetStorageEngineAfterLoadingConnectors() { - Settings settings = getCatalogSettings("empty_catalog.json"); - CatalogServiceImpl.getInstance().registerDefaultOpenSearchCatalog(storageEngine); - //Load Connectors will empty the catalogMap.So OpenSearch Storage Engine - CatalogServiceImpl.getInstance().loadConnectors(settings); - Set expected = new HashSet<>(); - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - } - - @SneakyThrows - @Test - public void testLoadConnectorsWithIllegalCatalogNames() { - Settings settings = getCatalogSettings("illegal_catalog_name.json"); - Set expected = CatalogServiceImpl.getInstance().getCatalogs(); - CatalogServiceImpl.getInstance().loadConnectors(settings); - Assert.assertEquals(expected, CatalogServiceImpl.getInstance().getCatalogs()); - } - - private Settings getCatalogSettings(String filename) throws URISyntaxException, IOException { - MockSecureSettings mockSecureSettings = new MockSecureSettings(); - ClassLoader classLoader = getClass().getClassLoader(); - Path filepath = Paths.get(classLoader.getResource(filename).toURI()); - mockSecureSettings.setFile(CATALOG_SETTING_METADATA_KEY, Files.readAllBytes(filepath)); - return Settings.builder().setSecureSettings(mockSecureSettings).build(); - } - -} diff --git a/plugin/src/test/java/org/opensearch/sql/plugin/datasource/DataSourceMetaDataTest.java b/plugin/src/test/java/org/opensearch/sql/plugin/datasource/DataSourceMetaDataTest.java new file mode 100644 index 0000000000..dc6eadbf7e --- /dev/null +++ b/plugin/src/test/java/org/opensearch/sql/plugin/datasource/DataSourceMetaDataTest.java @@ -0,0 +1,129 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.plugin.datasource; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import com.google.common.collect.ImmutableMap; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import lombok.SneakyThrows; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.opensearch.common.settings.MockSecureSettings; +import org.opensearch.common.settings.Settings; +import org.opensearch.sql.datasource.DataSourceService; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.plugin.SQLPlugin; + +@RunWith(MockitoJUnitRunner.class) +public class DataSourceMetaDataTest { + + public static final String DATASOURCE_SETTING_METADATA_KEY = + "plugins.query.federation.datasources.config"; + + @Mock + private DataSourceService dataSourceService; + + @SneakyThrows + @Test + public void testLoadConnectors() { + Settings settings = getDataSourceSettings("datasources.json"); + loadConnectors(settings); + List expected = + new ArrayList<>() { + { + add( + metadata( + "prometheus", + DataSourceType.PROMETHEUS, + ImmutableMap.of( + "prometheus.uri", "http://localhost:9090", + "prometheus.auth.type", "basicauth", + "prometheus.auth.username", "admin", + "prometheus.auth.password", "type"))); + } + }; + + verifyAddDataSourceWithMetadata(expected); + } + + @SneakyThrows + @Test + public void testLoadConnectorsWithMultipleDataSources() { + Settings settings = getDataSourceSettings("multiple_datasources.json"); + loadConnectors(settings); + List expected = new ArrayList<>() {{ + add(metadata("prometheus", DataSourceType.PROMETHEUS, ImmutableMap.of( + "prometheus.uri", "http://localhost:9090", + "prometheus.auth.type", "basicauth", + "prometheus.auth.username", "admin", + "prometheus.auth.password", "type" + ))); + add(metadata("prometheus-1", DataSourceType.PROMETHEUS, ImmutableMap.of( + "prometheus.uri", "http://localhost:9090", + "prometheus.auth.type", "awssigv4", + "prometheus.auth.region", "us-east-1", + "prometheus.auth.access_key", "accessKey", + "prometheus.auth.secret_key", "secretKey" + ))); + }}; + + verifyAddDataSourceWithMetadata(expected); + } + + @SneakyThrows + @Test + public void testLoadConnectorsWithMalformedJson() { + Settings settings = getDataSourceSettings("malformed_datasources.json"); + loadConnectors(settings); + + verify(dataSourceService, never()).addDataSource(any()); + } + + private Settings getDataSourceSettings(String filename) throws URISyntaxException, IOException { + MockSecureSettings mockSecureSettings = new MockSecureSettings(); + ClassLoader classLoader = getClass().getClassLoader(); + Path filepath = Paths.get(classLoader.getResource(filename).toURI()); + mockSecureSettings.setFile(DATASOURCE_SETTING_METADATA_KEY, Files.readAllBytes(filepath)); + return Settings.builder().setSecureSettings(mockSecureSettings).build(); + } + + void loadConnectors(Settings settings) { + SQLPlugin.loadDataSources(dataSourceService, settings); + } + + void verifyAddDataSourceWithMetadata(List metadataList) { + ArgumentCaptor metadataCaptor = + ArgumentCaptor.forClass(DataSourceMetadata.class); + verify(dataSourceService, times(1)).addDataSource(metadataCaptor.capture()); + List actualValues = metadataCaptor.getAllValues(); + assertEquals(metadataList.size(), actualValues.size()); + assertEquals(metadataList, actualValues); + } + + DataSourceMetadata metadata(String name, DataSourceType type, Map properties) { + DataSourceMetadata dataSourceMetadata = new DataSourceMetadata(); + dataSourceMetadata.setName(name); + dataSourceMetadata.setConnector(type); + dataSourceMetadata.setProperties(properties); + return dataSourceMetadata; + } +} diff --git a/plugin/src/test/resources/catalog_missing_name.json b/plugin/src/test/resources/catalog_missing_name.json deleted file mode 100644 index 4491ebb0db..0000000000 --- a/plugin/src/test/resources/catalog_missing_name.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "connector": "prometheus", - "properties" : { - "prometheus.uri" : "http://localhost:9090", - "prometheus.auth.type" : "basicauth", - "prometheus.auth.username" : "admin", - "prometheus.auth.password" : "type" - } - } -] \ No newline at end of file diff --git a/plugin/src/test/resources/catalogs.json b/plugin/src/test/resources/datasources.json similarity index 100% rename from plugin/src/test/resources/catalogs.json rename to plugin/src/test/resources/datasources.json diff --git a/plugin/src/test/resources/duplicate_catalog_names.json b/plugin/src/test/resources/duplicate_catalog_names.json deleted file mode 100644 index eefc56b6ef..0000000000 --- a/plugin/src/test/resources/duplicate_catalog_names.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "name" : "prometheus", - "connector": "prometheus", - "properties" : { - "prometheus.uri" : "http://localhost:9090", - "prometheus.auth.type" : "basicauth", - "prometheus.auth.username" : "admin", - "prometheus.auth.password" : "type" - } - }, - { - "name" : "prometheus", - "connector": "prometheus", - "properties" : { - "prometheus.uri" : "http://localhost:9090", - "prometheus.auth.type" : "basicauth", - "prometheus.auth.username" : "admin", - "prometheus.auth.password" : "type" - } - } -] \ No newline at end of file diff --git a/plugin/src/test/resources/empty_catalog.json b/plugin/src/test/resources/empty_catalog.json deleted file mode 100644 index 0637a088a0..0000000000 --- a/plugin/src/test/resources/empty_catalog.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/plugin/src/test/resources/illegal_catalog_name.json b/plugin/src/test/resources/illegal_catalog_name.json deleted file mode 100644 index 212ca6ec93..0000000000 --- a/plugin/src/test/resources/illegal_catalog_name.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "name" : "prometheus.test", - "connector": "prometheus", - "properties" : { - "prometheus.uri" : "http://localhost:9090", - "prometheus.auth.type" : "basicauth", - "prometheus.auth.username" : "admin", - "prometheus.auth.password" : "type" - } - } -] \ No newline at end of file diff --git a/plugin/src/test/resources/malformed_catalogs.json b/plugin/src/test/resources/malformed_datasources.json similarity index 100% rename from plugin/src/test/resources/malformed_catalogs.json rename to plugin/src/test/resources/malformed_datasources.json diff --git a/plugin/src/test/resources/multiple_catalogs.json b/plugin/src/test/resources/multiple_datasources.json similarity index 100% rename from plugin/src/test/resources/multiple_catalogs.json rename to plugin/src/test/resources/multiple_datasources.json diff --git a/ppl/src/main/antlr/OpenSearchPPLLexer.g4 b/ppl/src/main/antlr/OpenSearchPPLLexer.g4 index 75b99f2daf..e0aeb0ac47 100644 --- a/ppl/src/main/antlr/OpenSearchPPLLexer.g4 +++ b/ppl/src/main/antlr/OpenSearchPPLLexer.g4 @@ -43,7 +43,7 @@ SOURCE: 'SOURCE'; INDEX: 'INDEX'; D: 'D'; DESC: 'DESC'; -CATALOGS: 'DATASOURCES'; +DATASOURCES: 'DATASOURCES'; // CLAUSE KEYWORDS SORTBY: 'SORTBY'; diff --git a/ppl/src/main/antlr/OpenSearchPPLParser.g4 b/ppl/src/main/antlr/OpenSearchPPLParser.g4 index 7de8e19aa0..0dd30ddcd7 100644 --- a/ppl/src/main/antlr/OpenSearchPPLParser.g4 +++ b/ppl/src/main/antlr/OpenSearchPPLParser.g4 @@ -29,7 +29,7 @@ queryStatement pplCommands : searchCommand | describeCommand - | showCatalogsCommand + | showDataSourcesCommand ; commands @@ -46,8 +46,8 @@ describeCommand : DESCRIBE tableSourceClause ; -showCatalogsCommand - : SHOW CATALOGS +showDataSourcesCommand + : SHOW DATASOURCES ; whereCommand diff --git a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java index c72b638645..73c7238624 100644 --- a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java +++ b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java @@ -23,7 +23,7 @@ import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.TableSourceClauseContext; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.TopCommandContext; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.WhereCommandContext; -import static org.opensearch.sql.utils.SystemIndexUtils.CATALOGS_TABLE_NAME; +import static org.opensearch.sql.utils.SystemIndexUtils.DATASOURCES_TABLE_NAME; import static org.opensearch.sql.utils.SystemIndexUtils.mappingTable; import com.google.common.collect.ImmutableList; @@ -46,7 +46,6 @@ import org.opensearch.sql.ast.expression.Map; import org.opensearch.sql.ast.expression.ParseMethod; import org.opensearch.sql.ast.expression.QualifiedName; -import org.opensearch.sql.ast.expression.UnresolvedArgument; import org.opensearch.sql.ast.expression.UnresolvedExpression; import org.opensearch.sql.ast.tree.AD; import org.opensearch.sql.ast.tree.Aggregation; @@ -63,7 +62,6 @@ import org.opensearch.sql.ast.tree.Relation; import org.opensearch.sql.ast.tree.Rename; import org.opensearch.sql.ast.tree.Sort; -import org.opensearch.sql.ast.tree.TableFunction; import org.opensearch.sql.ast.tree.UnresolvedPlan; import org.opensearch.sql.common.utils.StringUtils; import org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser; @@ -122,7 +120,7 @@ public UnresolvedPlan visitSearchFilterFrom(SearchFilterFromContext ctx) { * Describe command. * Current logic separates table and metadata info about table by adding * MAPPING_ODFE_SYS_TABLE as suffix. - * Even with the introduction of catalog and schema name in fully qualified table name, + * Even with the introduction of datasource and schema name in fully qualified table name, * we do the same thing by appending MAPPING_ODFE_SYS_TABLE as syffix to the last part * of qualified name. */ @@ -139,9 +137,9 @@ public UnresolvedPlan visitDescribeCommand(DescribeCommandContext ctx) { * Show command. */ @Override - public UnresolvedPlan visitShowCatalogsCommand( - OpenSearchPPLParser.ShowCatalogsCommandContext ctx) { - return new Relation(qualifiedName(CATALOGS_TABLE_NAME)); + public UnresolvedPlan visitShowDataSourcesCommand( + OpenSearchPPLParser.ShowDataSourcesCommandContext ctx) { + return new Relation(qualifiedName(DATASOURCES_TABLE_NAME)); } diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java index 1bcc1b9de9..d301b7b918 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java @@ -18,8 +18,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.opensearch.sql.catalog.CatalogService; import org.opensearch.sql.common.response.ResponseListener; +import org.opensearch.sql.datasource.DataSourceService; import org.opensearch.sql.executor.DefaultQueryManager; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.ExecutionEngine.ExplainResponse; @@ -54,7 +54,7 @@ public class PPLServiceTest { private ExecutionEngine executionEngine; @Mock - private CatalogService catalogService; + private DataSourceService dataSourceService; @Mock private ExecutionEngine.Schema schema; @@ -71,7 +71,7 @@ public void setUp() { context.registerBean(QueryPlanFactory.class, () -> new QueryPlanFactory(queryService)); context.registerBean(StorageEngine.class, () -> storageEngine); context.registerBean(ExecutionEngine.class, () -> executionEngine); - context.registerBean(CatalogService.class, () -> catalogService); + context.registerBean(DataSourceService.class, () -> dataSourceService); context.register(PPLServiceConfig.class); context.refresh(); pplService = context.getBean(PPLService.class); diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java index 1e6cc5a7b9..533254a599 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java @@ -40,6 +40,7 @@ import static org.opensearch.sql.ast.dsl.AstDSL.stringLiteral; import static org.opensearch.sql.ast.dsl.AstDSL.tableFunction; import static org.opensearch.sql.ast.dsl.AstDSL.unresolvedArg; +import static org.opensearch.sql.utils.SystemIndexUtils.DATASOURCES_TABLE_NAME; import static org.opensearch.sql.utils.SystemIndexUtils.mappingTable; import com.google.common.collect.ImmutableMap; @@ -84,7 +85,7 @@ public void testPrometheusSearchCommand() { } @Test - public void testSearchCommandWithCatalogEscape() { + public void testSearchCommandWithDataSourceEscape() { assertEqual("search source = `prometheus.http_requests_total`", relation("prometheus.http_requests_total") ); @@ -799,9 +800,9 @@ public void test_batchRCFADCommand() { } @Test - public void testShowCatalogsCommand() { + public void testShowDataSourcesCommand() { assertEqual("show datasources", - relation(".CATALOGS")); + relation(DATASOURCES_TABLE_NAME)); } protected void assertEqual(String query, Node expectedPlan) { diff --git a/prometheus/build.gradle b/prometheus/build.gradle index 45a3a4a8ed..57063fff87 100644 --- a/prometheus/build.gradle +++ b/prometheus/build.gradle @@ -42,6 +42,7 @@ test { configurations.all { resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.6.0" resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0" + resolutionStrategy.force "org.junit.jupiter:junit-jupiter:5.6.2" } jacocoTestReport { diff --git a/prometheus/src/main/java/org/opensearch/sql/prometheus/request/system/PrometheusDescribeMetricRequest.java b/prometheus/src/main/java/org/opensearch/sql/prometheus/request/system/PrometheusDescribeMetricRequest.java index 9b76cbff27..2e0d46b3e8 100644 --- a/prometheus/src/main/java/org/opensearch/sql/prometheus/request/system/PrometheusDescribeMetricRequest.java +++ b/prometheus/src/main/java/org/opensearch/sql/prometheus/request/system/PrometheusDescribeMetricRequest.java @@ -22,7 +22,7 @@ import lombok.ToString; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.data.model.ExprTupleValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.type.ExprCoreType; @@ -43,7 +43,7 @@ public class PrometheusDescribeMetricRequest implements PrometheusSystemRequest @ToString.Include private final String metricName; - private final CatalogSchemaName catalogSchemaName; + private final DataSourceSchemaName dataSourceSchemaName; private static final Logger LOG = LogManager.getLogger(); @@ -53,15 +53,15 @@ public class PrometheusDescribeMetricRequest implements PrometheusSystemRequest * metric names are optional. * * @param prometheusClient prometheusClient. - * @param catalogSchemaName catalogSchemaName. + * @param dataSourceSchemaName dataSourceSchemaName. * @param metricName metricName. */ public PrometheusDescribeMetricRequest(PrometheusClient prometheusClient, - CatalogSchemaName catalogSchemaName, + DataSourceSchemaName dataSourceSchemaName, @NonNull String metricName) { this.prometheusClient = prometheusClient; this.metricName = metricName; - this.catalogSchemaName = catalogSchemaName; + this.dataSourceSchemaName = dataSourceSchemaName; } @@ -94,16 +94,16 @@ public List search() { List results = new ArrayList<>(); for (Map.Entry entry : getFieldTypes().entrySet()) { results.add(row(entry.getKey(), entry.getValue().legacyTypeName().toLowerCase(), - catalogSchemaName)); + dataSourceSchemaName)); } return results; } private ExprTupleValue row(String fieldName, String fieldType, - CatalogSchemaName catalogSchemaName) { + DataSourceSchemaName dataSourceSchemaName) { LinkedHashMap valueMap = new LinkedHashMap<>(); - valueMap.put("TABLE_CATALOG", stringValue(catalogSchemaName.getCatalogName())); - valueMap.put("TABLE_SCHEMA", stringValue(catalogSchemaName.getSchemaName())); + valueMap.put("TABLE_CATALOG", stringValue(dataSourceSchemaName.getDataSourceName())); + valueMap.put("TABLE_SCHEMA", stringValue(dataSourceSchemaName.getSchemaName())); valueMap.put("TABLE_NAME", stringValue(metricName)); valueMap.put("COLUMN_NAME", stringValue(fieldName)); valueMap.put("DATA_TYPE", stringValue(fieldType)); diff --git a/prometheus/src/main/java/org/opensearch/sql/prometheus/request/system/PrometheusListMetricsRequest.java b/prometheus/src/main/java/org/opensearch/sql/prometheus/request/system/PrometheusListMetricsRequest.java index c4dbbebde1..f5d2a44340 100644 --- a/prometheus/src/main/java/org/opensearch/sql/prometheus/request/system/PrometheusListMetricsRequest.java +++ b/prometheus/src/main/java/org/opensearch/sql/prometheus/request/system/PrometheusListMetricsRequest.java @@ -19,7 +19,7 @@ import lombok.RequiredArgsConstructor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.data.model.ExprTupleValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.prometheus.client.PrometheusClient; @@ -30,7 +30,7 @@ public class PrometheusListMetricsRequest implements PrometheusSystemRequest { private final PrometheusClient prometheusClient; - private final CatalogSchemaName catalogSchemaName; + private final DataSourceSchemaName dataSourceSchemaName; private static final Logger LOG = LogManager.getLogger(); @@ -60,7 +60,7 @@ public List search() { private ExprTupleValue row(String metricName, String tableType, String unit, String help) { LinkedHashMap valueMap = new LinkedHashMap<>(); - valueMap.put("TABLE_CATALOG", stringValue(catalogSchemaName.getCatalogName())); + valueMap.put("TABLE_CATALOG", stringValue(dataSourceSchemaName.getDataSourceName())); valueMap.put("TABLE_SCHEMA", stringValue("default")); valueMap.put("TABLE_NAME", stringValue(metricName)); valueMap.put("TABLE_TYPE", stringValue(tableType)); diff --git a/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/PrometheusStorageEngine.java b/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/PrometheusStorageEngine.java index f8ae0936ee..4bda60b822 100644 --- a/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/PrometheusStorageEngine.java +++ b/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/PrometheusStorageEngine.java @@ -7,13 +7,13 @@ package org.opensearch.sql.prometheus.storage; -import static org.opensearch.sql.analysis.CatalogSchemaIdentifierNameResolver.INFORMATION_SCHEMA_NAME; +import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.INFORMATION_SCHEMA_NAME; import static org.opensearch.sql.utils.SystemIndexUtils.isSystemIndex; import java.util.Collection; import java.util.Collections; import lombok.RequiredArgsConstructor; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.exception.SemanticCheckException; import org.opensearch.sql.expression.function.FunctionResolver; import org.opensearch.sql.prometheus.client.PrometheusClient; @@ -39,21 +39,21 @@ public Collection getFunctions() { } @Override - public Table getTable(CatalogSchemaName catalogSchemaName, String tableName) { + public Table getTable(DataSourceSchemaName dataSourceSchemaName, String tableName) { if (isSystemIndex(tableName)) { - return new PrometheusSystemTable(prometheusClient, catalogSchemaName, tableName); - } else if (INFORMATION_SCHEMA_NAME.equals(catalogSchemaName.getSchemaName())) { - return resolveInformationSchemaTable(catalogSchemaName, tableName); + return new PrometheusSystemTable(prometheusClient, dataSourceSchemaName, tableName); + } else if (INFORMATION_SCHEMA_NAME.equals(dataSourceSchemaName.getSchemaName())) { + return resolveInformationSchemaTable(dataSourceSchemaName, tableName); } else { return new PrometheusMetricTable(prometheusClient, tableName); } } - private Table resolveInformationSchemaTable(CatalogSchemaName catalogSchemaName, + private Table resolveInformationSchemaTable(DataSourceSchemaName dataSourceSchemaName, String tableName) { if (SystemIndexUtils.TABLE_NAME_FOR_TABLES_INFO.equals(tableName)) { return new PrometheusSystemTable(prometheusClient, - catalogSchemaName, SystemIndexUtils.TABLE_INFO); + dataSourceSchemaName, SystemIndexUtils.TABLE_INFO); } else { throw new SemanticCheckException( String.format("Information Schema doesn't contain %s table", tableName)); diff --git a/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactory.java b/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactory.java index 41cbf3748f..4e8b30af2f 100644 --- a/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactory.java +++ b/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactory.java @@ -14,16 +14,18 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import okhttp3.OkHttpClient; -import org.opensearch.sql.catalog.model.ConnectorType; -import org.opensearch.sql.catalog.model.auth.AuthenticationType; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.datasource.model.auth.AuthenticationType; import org.opensearch.sql.prometheus.authinterceptors.AwsSigningInterceptor; import org.opensearch.sql.prometheus.authinterceptors.BasicAuthenticationInterceptor; import org.opensearch.sql.prometheus.client.PrometheusClient; import org.opensearch.sql.prometheus.client.PrometheusClientImpl; +import org.opensearch.sql.storage.DataSourceFactory; import org.opensearch.sql.storage.StorageEngine; -import org.opensearch.sql.storage.StorageEngineFactory; -public class PrometheusStorageFactory implements StorageEngineFactory { +public class PrometheusStorageFactory implements DataSourceFactory { public static final String URI = "prometheus.uri"; public static final String AUTH_TYPE = "prometheus.auth.type"; @@ -33,14 +35,20 @@ public class PrometheusStorageFactory implements StorageEngineFactory { public static final String ACCESS_KEY = "prometheus.auth.access_key"; public static final String SECRET_KEY = "prometheus.auth.secret_key"; - @Override - public ConnectorType getConnectorType() { - return ConnectorType.PROMETHEUS; + public DataSourceType getDataSourceType() { + return DataSourceType.PROMETHEUS; } @Override - public StorageEngine getStorageEngine(String catalogName, Map requiredConfig) { + public DataSource createDataSource(DataSourceMetadata metadata) { + return new DataSource( + metadata.getName(), + DataSourceType.PROMETHEUS, + getStorageEngine(metadata.getName(), metadata.getProperties())); + } + + StorageEngine getStorageEngine(String catalogName, Map requiredConfig) { validateFieldsInConfig(requiredConfig, Set.of(URI)); PrometheusClient prometheusClient; try { diff --git a/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTable.java b/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTable.java index 2d185d4a5d..dca946da57 100644 --- a/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTable.java +++ b/prometheus/src/main/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTable.java @@ -12,7 +12,7 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.planner.DefaultImplementor; import org.opensearch.sql.planner.logical.LogicalPlan; @@ -34,11 +34,11 @@ public class PrometheusSystemTable implements Table { */ private final Pair systemIndexBundle; - private final CatalogSchemaName catalogSchemaName; + private final DataSourceSchemaName dataSourceSchemaName; public PrometheusSystemTable( - PrometheusClient client, CatalogSchemaName catalogSchemaName, String indexName) { - this.catalogSchemaName = catalogSchemaName; + PrometheusClient client, DataSourceSchemaName dataSourceSchemaName, String indexName) { + this.dataSourceSchemaName = dataSourceSchemaName; this.systemIndexBundle = buildIndexBundle(client, indexName); } @@ -68,11 +68,11 @@ private Pair buildIndexBun SystemIndexUtils.SystemTable systemTable = systemTable(indexName); if (systemTable.isSystemInfoTable()) { return Pair.of(PrometheusSystemTableSchema.SYS_TABLE_TABLES, - new PrometheusListMetricsRequest(client, catalogSchemaName)); + new PrometheusListMetricsRequest(client, dataSourceSchemaName)); } else { return Pair.of(PrometheusSystemTableSchema.SYS_TABLE_MAPPINGS, new PrometheusDescribeMetricRequest(client, - catalogSchemaName, systemTable.getTableName())); + dataSourceSchemaName, systemTable.getTableName())); } } } diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/planner/logical/PrometheusLogicOptimizerTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/planner/logical/PrometheusLogicOptimizerTest.java index 7d6d3bed28..a1d1cef91d 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/planner/logical/PrometheusLogicOptimizerTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/planner/logical/PrometheusLogicOptimizerTest.java @@ -25,7 +25,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.sql.expression.DSL; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.optimizer.LogicalPlanOptimizer; import org.opensearch.sql.storage.Table; @@ -33,8 +32,6 @@ @ExtendWith(MockitoExtension.class) public class PrometheusLogicOptimizerTest { - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - @Mock private Table table; @@ -43,13 +40,13 @@ void project_filter_merge_with_relation() { assertEquals( project( indexScan("prometheus_http_total_requests", - dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200")))) + DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200")))) ), optimize( project( filter( relation("prometheus_http_total_requests", table), - dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))) + DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))) )) ) ); @@ -61,7 +58,7 @@ void aggregation_merge_relation() { project( indexScanAgg("prometheus_http_total_requests", ImmutableList .of(DSL.named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(DSL.named("code", DSL.ref("code", STRING)))), DSL.named("AVG(intV)", DSL.ref("AVG(intV)", DOUBLE))), optimize( @@ -70,7 +67,7 @@ void aggregation_merge_relation() { relation("prometheus_http_total_requests", table), ImmutableList .of(DSL.named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(DSL.named("code", DSL.ref("code", STRING)))), DSL.named("AVG(intV)", DSL.ref("AVG(intV)", DOUBLE))) @@ -84,11 +81,11 @@ void aggregation_merge_filter_relation() { assertEquals( project( indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), ImmutableList .of(DSL.named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(DSL.named("job", DSL.ref("job", STRING)))), DSL.named("AVG(@value)", DSL.ref("AVG(@value)", DOUBLE))), optimize( @@ -96,15 +93,15 @@ void aggregation_merge_filter_relation() { aggregation( filter( relation("prometheus_http_total_requests", table), - dsl.and( - dsl.equal(DSL.ref("code", STRING), + DSL.and( + DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))) ), ImmutableList .of(DSL.named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(DSL.named("job", DSL.ref("job", STRING)))), DSL.named("AVG(@value)", DSL.ref("AVG(@value)", DOUBLE))) diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusDescribeMetricRequestTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusDescribeMetricRequestTest.java index a190abb6a1..dfc9aee7dc 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusDescribeMetricRequestTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusDescribeMetricRequestTest.java @@ -26,7 +26,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.data.model.ExprTupleValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.type.ExprCoreType; @@ -56,7 +56,7 @@ void testGetFieldTypes() { }}; PrometheusDescribeMetricRequest prometheusDescribeMetricRequest = new PrometheusDescribeMetricRequest(prometheusClient, - new CatalogSchemaName("prometheus", "default"), METRIC_NAME); + new DataSourceSchemaName("prometheus", "default"), METRIC_NAME); assertEquals(expected, prometheusDescribeMetricRequest.getFieldTypes()); verify(prometheusClient, times(1)).getLabels(METRIC_NAME); } @@ -71,7 +71,7 @@ void testGetFieldTypesWithEmptyMetricName() { }}; assertThrows(NullPointerException.class, () -> new PrometheusDescribeMetricRequest(prometheusClient, - new CatalogSchemaName("prometheus", "default"), + new DataSourceSchemaName("prometheus", "default"), null)); } @@ -82,7 +82,7 @@ void testGetFieldTypesWhenException() { when(prometheusClient.getLabels(METRIC_NAME)).thenThrow(new RuntimeException("ERROR Message")); PrometheusDescribeMetricRequest prometheusDescribeMetricRequest = new PrometheusDescribeMetricRequest(prometheusClient, - new CatalogSchemaName("prometheus", "default"), METRIC_NAME); + new DataSourceSchemaName("prometheus", "default"), METRIC_NAME); RuntimeException exception = assertThrows(RuntimeException.class, prometheusDescribeMetricRequest::getFieldTypes); verify(prometheusClient, times(1)).getLabels(METRIC_NAME); @@ -95,7 +95,7 @@ void testGetFieldTypesWhenIOException() { when(prometheusClient.getLabels(METRIC_NAME)).thenThrow(new IOException("ERROR Message")); PrometheusDescribeMetricRequest prometheusDescribeMetricRequest = new PrometheusDescribeMetricRequest(prometheusClient, - new CatalogSchemaName("prometheus", "default"), METRIC_NAME); + new DataSourceSchemaName("prometheus", "default"), METRIC_NAME); RuntimeException exception = assertThrows(RuntimeException.class, prometheusDescribeMetricRequest::getFieldTypes); assertEquals("Error while fetching labels for http_requests_total" @@ -113,7 +113,7 @@ void testSearch() { }); PrometheusDescribeMetricRequest prometheusDescribeMetricRequest = new PrometheusDescribeMetricRequest(prometheusClient, - new CatalogSchemaName("test", "default"), METRIC_NAME); + new DataSourceSchemaName("test", "default"), METRIC_NAME); List result = prometheusDescribeMetricRequest.search(); assertEquals(3, result.size()); assertEquals(expectedRow(), result.get(0)); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java index 2d0bf3f1e9..bf5bb22e96 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java @@ -25,7 +25,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.data.model.ExprTupleValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.prometheus.client.PrometheusClient; @@ -51,7 +51,7 @@ void testSearch() { when(prometheusClient.getAllMetrics()).thenReturn(metricsResult); PrometheusListMetricsRequest prometheusListMetricsRequest = new PrometheusListMetricsRequest(prometheusClient, - new CatalogSchemaName("prometheus", "information_schema")); + new DataSourceSchemaName("prometheus", "information_schema")); List result = prometheusListMetricsRequest.search(); assertEquals(expectedRow(), result.get(0)); assertEquals(2, result.size()); @@ -65,7 +65,7 @@ void testSearchWhenIOException() { when(prometheusClient.getAllMetrics()).thenThrow(new IOException("ERROR Message")); PrometheusListMetricsRequest prometheusListMetricsRequest = new PrometheusListMetricsRequest(prometheusClient, - new CatalogSchemaName("prometheus", "information_schema")); + new DataSourceSchemaName("prometheus", "information_schema")); RuntimeException exception = assertThrows(RuntimeException.class, prometheusListMetricsRequest::search); assertEquals("Error while fetching metric list for from prometheus: ERROR Message", diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricTableTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricTableTest.java index e106fa225b..7e2de95604 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricTableTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricTableTest.java @@ -50,7 +50,6 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.NamedExpression; -import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.physical.PhysicalPlan; import org.opensearch.sql.planner.physical.ProjectOperator; @@ -64,8 +63,6 @@ class PrometheusMetricTableTest { @Mock private PrometheusClient client; - private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - @Test @SneakyThrows void testGetFieldTypesFromMetric() { @@ -172,12 +169,12 @@ void testImplementPrometheusQueryWithStatsQueryAndNoFilter() { filter( indexScanAgg("prometheus_http_total_requests", ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("code", DSL.ref("code", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s")))), - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))))); + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))))); assertTrue(plan.getChild().get(0) instanceof PrometheusMetricScan); PrometheusQueryRequest prometheusQueryRequest = @@ -197,11 +194,11 @@ void testImplementPrometheusQueryWithStatsQueryAndFilter() { // IndexScanAgg with Filter PhysicalPlan plan = prometheusMetricTable.implement( indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("job", DSL.ref("job", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s"))))); @@ -227,11 +224,11 @@ void testImplementPrometheusQueryWithStatsQueryAndFilterAndProject() { finalProjectList.add(DSL.named(TIMESTAMP, DSL.ref(TIMESTAMP, ExprCoreType.TIMESTAMP))); PhysicalPlan plan = prometheusMetricTable.implement( project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), ImmutableList .of(DSL.named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(DSL.named("job", DSL.ref("job", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s")))), @@ -267,20 +264,20 @@ void testTimeRangeResolver() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); PhysicalPlan plan = prometheusMetricTable.implement( project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.and(dsl.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.and(DSL.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(startTime)), ExprCoreType.TIMESTAMP))), - dsl.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(endTime)), ExprCoreType.TIMESTAMP)))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("job", DSL.ref("job", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s")))), @@ -314,16 +311,16 @@ void testTimeRangeResolverWithOutEndTimeInFilter() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); PhysicalPlan plan = prometheusMetricTable.implement( project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(startTime)), ExprCoreType.TIMESTAMP))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("job", DSL.ref("job", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s")))), @@ -357,16 +354,16 @@ void testTimeRangeResolverWithOutStartTimeInFilter() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); PhysicalPlan plan = prometheusMetricTable.implement( project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(endTime)), ExprCoreType.TIMESTAMP))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("job", DSL.ref("job", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s")))), @@ -399,20 +396,20 @@ void testSpanResolverWithoutSpanExpression() { Long startTime = new Date(System.currentTimeMillis() - 4800 * 1000).getTime(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); LogicalPlan plan = project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.and(dsl.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.and(DSL.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(startTime)), ExprCoreType.TIMESTAMP))), - dsl.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(endTime)), ExprCoreType.TIMESTAMP)))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), null), finalProjectList, null); RuntimeException runtimeException @@ -436,20 +433,20 @@ void testSpanResolverWithEmptyGroupByList() { Long startTime = new Date(System.currentTimeMillis() - 4800 * 1000).getTime(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); LogicalPlan plan = project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.and(dsl.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.and(DSL.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(startTime)), ExprCoreType.TIMESTAMP))), - dsl.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(endTime)), ExprCoreType.TIMESTAMP)))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of()), finalProjectList, null); RuntimeException runtimeException @@ -475,20 +472,20 @@ void testSpanResolverWithSpanExpression() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); PhysicalPlan plan = prometheusMetricTable.implement( project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.and(dsl.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.and(DSL.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(startTime)), ExprCoreType.TIMESTAMP))), - dsl.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(endTime)), ExprCoreType.TIMESTAMP)))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("job", DSL.ref("job", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s")))), @@ -521,20 +518,20 @@ void testExpressionWithMissingTimeUnitInSpanExpression() { Long startTime = new Date(System.currentTimeMillis() - 4800 * 1000).getTime(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); LogicalPlan logicalPlan = project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.and(dsl.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.and(DSL.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(startTime)), ExprCoreType.TIMESTAMP))), - dsl.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(endTime)), ExprCoreType.TIMESTAMP)))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("job", DSL.ref("job", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "")))), @@ -560,20 +557,20 @@ void testPrometheusQueryWithOnlySpanExpressionInGroupByList() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); PhysicalPlan plan = prometheusMetricTable.implement( project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.and(dsl.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.and(DSL.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(startTime)), ExprCoreType.TIMESTAMP))), - dsl.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(endTime)), ExprCoreType.TIMESTAMP)))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of( named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s")))), @@ -607,20 +604,20 @@ void testStatsWithNoGroupByList() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); PhysicalPlan plan = prometheusMetricTable.implement( project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.and( - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), - dsl.and(dsl.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.and( + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))), + DSL.and(DSL.gte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(startTime)), ExprCoreType.TIMESTAMP))), - dsl.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), + DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal( fromObjectValue(dateFormat.format(new Date(endTime)), ExprCoreType.TIMESTAMP)))))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s")))), @@ -657,13 +654,13 @@ void testMultipleAggregationsThrowsRuntimeException() { PrometheusMetricTable prometheusMetricTable = new PrometheusMetricTable(client, "prometheus_http_total_requests"); LogicalPlan plan = project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER))), + DSL.avg(DSL.ref("@value", INTEGER))), named("SUM(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("job", DSL.ref("job", STRING))))); RuntimeException runtimeException = Assertions.assertThrows(RuntimeException.class, @@ -678,11 +675,11 @@ void testUnSupportedAggregation() { PrometheusMetricTable prometheusMetricTable = new PrometheusMetricTable(client, "prometheus_http_total_requests"); LogicalPlan plan = project(indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), ImmutableList .of(named("VAR_SAMP(@value)", - dsl.varSamp(DSL.ref("@value", INTEGER)))), + DSL.varSamp(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("job", DSL.ref("job", STRING))))); RuntimeException runtimeException = Assertions.assertThrows(RuntimeException.class, @@ -695,8 +692,8 @@ void testImplementWithORConditionInWhereClause() { PrometheusMetricTable prometheusMetricTable = new PrometheusMetricTable(client, "prometheus_http_total_requests"); LogicalPlan plan = indexScan("prometheus_http_total_requests", - dsl.or(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))))); + DSL.or(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))))); RuntimeException exception = assertThrows(RuntimeException.class, () -> prometheusMetricTable.implement(plan)); assertEquals("Prometheus Catalog doesn't support or in where command.", exception.getMessage()); @@ -710,8 +707,8 @@ void testImplementWithRelationAndFilter() { PrometheusMetricTable prometheusMetricTable = new PrometheusMetricTable(client, "prometheus_http_total_requests"); LogicalPlan logicalPlan = project(indexScan("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))))), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/"))))), finalProjectList, null); PhysicalPlan physicalPlan = prometheusMetricTable.implement(logicalPlan); assertTrue(physicalPlan instanceof ProjectOperator); @@ -761,11 +758,11 @@ void testImplementPrometheusQueryWithBackQuotedFieldNamesInStatsQuery() { // IndexScanAgg with Filter PhysicalPlan plan = prometheusMetricTable.implement( indexScanAgg("prometheus_http_total_requests", - dsl.and(dsl.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), - dsl.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), + DSL.and(DSL.equal(DSL.ref("code", STRING), DSL.literal(stringValue("200"))), + DSL.equal(DSL.ref("handler", STRING), DSL.literal(stringValue("/ready/")))), ImmutableList .of(named("AVG(@value)", - dsl.avg(DSL.ref("@value", INTEGER)))), + DSL.avg(DSL.ref("@value", INTEGER)))), ImmutableList.of(named("`job`", DSL.ref("job", STRING)), named("span", DSL.span(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP), DSL.literal(40), "s"))))); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageEngineTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageEngineTest.java index fadd061072..f4c9734e15 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageEngineTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageEngineTest.java @@ -7,7 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opensearch.sql.utils.SystemIndexUtils.TABLE_INFO; @@ -17,7 +16,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.exception.SemanticCheckException; import org.opensearch.sql.expression.function.FunctionResolver; import org.opensearch.sql.prometheus.client.PrometheusClient; @@ -34,7 +33,7 @@ class PrometheusStorageEngineTest { @Test public void getTable() { PrometheusStorageEngine engine = new PrometheusStorageEngine(client); - Table table = engine.getTable(new CatalogSchemaName("prometheus", "default"), "test"); + Table table = engine.getTable(new DataSourceSchemaName("prometheus", "default"), "test"); assertNotNull(table); assertTrue(table instanceof PrometheusMetricTable); } @@ -53,7 +52,7 @@ public void getFunctions() { @Test public void getSystemTable() { PrometheusStorageEngine engine = new PrometheusStorageEngine(client); - Table table = engine.getTable(new CatalogSchemaName("prometheus", "default"), TABLE_INFO); + Table table = engine.getTable(new DataSourceSchemaName("prometheus", "default"), TABLE_INFO); assertNotNull(table); assertTrue(table instanceof PrometheusSystemTable); } @@ -62,7 +61,7 @@ public void getSystemTable() { public void getSystemTableForAllTablesInfo() { PrometheusStorageEngine engine = new PrometheusStorageEngine(client); Table table - = engine.getTable(new CatalogSchemaName("prometheus", "information_schema"), "tables"); + = engine.getTable(new DataSourceSchemaName("prometheus", "information_schema"), "tables"); assertNotNull(table); assertTrue(table instanceof PrometheusSystemTable); } @@ -71,7 +70,8 @@ public void getSystemTableForAllTablesInfo() { public void getSystemTableWithWrongInformationSchemaTable() { PrometheusStorageEngine engine = new PrometheusStorageEngine(client); SemanticCheckException exception = assertThrows(SemanticCheckException.class, - () -> engine.getTable(new CatalogSchemaName("prometheus", "information_schema"), "test")); + () -> engine.getTable(new DataSourceSchemaName("prometheus", "information_schema"), + "test")); assertEquals("Information Schema doesn't contain test table", exception.getMessage()); } diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java index 1b54cde5d9..91cb8df1ea 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java @@ -13,7 +13,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.catalog.model.ConnectorType; +import org.opensearch.sql.datasource.model.DataSource; +import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasource.model.DataSourceType; import org.opensearch.sql.storage.StorageEngine; @ExtendWith(MockitoExtension.class) @@ -22,7 +24,8 @@ public class PrometheusStorageFactoryTest { @Test void testGetConnectorType() { PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(); - Assertions.assertEquals(ConnectorType.PROMETHEUS, prometheusStorageFactory.getConnectorType()); + Assertions.assertEquals( + DataSourceType.PROMETHEUS, prometheusStorageFactory.getDataSourceType()); } @Test @@ -130,6 +133,21 @@ void testGetStorageEngineWithInvalidURISyntax() { exception.getMessage().contains("Prometheus Client creation failed due to:")); } + @Test + void createDataSourceSuccess() { + HashMap properties = new HashMap<>(); + properties.put("prometheus.uri", "http://dummyprometheus:9090"); + properties.put("prometheus.auth.type", "basicauth"); + properties.put("prometheus.auth.username", "admin"); + properties.put("prometheus.auth.password", "admin"); + DataSourceMetadata metadata = new DataSourceMetadata(); + metadata.setName("prometheus"); + metadata.setConnector(DataSourceType.PROMETHEUS); + metadata.setProperties(properties); + + DataSource dataSource = new PrometheusStorageFactory().createDataSource(metadata); + Assertions.assertTrue(dataSource.getStorageEngine() instanceof PrometheusStorageEngine); + } } diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableTest.java index 960b5b1319..0721f82c07 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableTest.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.CatalogSchemaName; +import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.NamedExpression; import org.opensearch.sql.planner.physical.PhysicalPlan; @@ -44,7 +44,7 @@ public class PrometheusSystemTableTest { @Test void testGetFieldTypesOfMetaTable() { PrometheusSystemTable systemIndex = new PrometheusSystemTable(client, - new CatalogSchemaName("prometheus", "information_schema"), TABLE_INFO); + new DataSourceSchemaName("prometheus", "information_schema"), TABLE_INFO); final Map fieldTypes = systemIndex.getFieldTypes(); assertThat(fieldTypes, anyOf( hasEntry("TABLE_CATALOG", STRING) @@ -57,7 +57,7 @@ void testGetFieldTypesOfMetaTable() { @Test void testGetFieldTypesOfMappingTable() { PrometheusSystemTable systemIndex = new PrometheusSystemTable(client, - new CatalogSchemaName("prometheus", "information_schema"), mappingTable( + new DataSourceSchemaName("prometheus", "information_schema"), mappingTable( "test_metric")); final Map fieldTypes = systemIndex.getFieldTypes(); assertThat(fieldTypes, anyOf( @@ -70,7 +70,7 @@ void testGetFieldTypesOfMappingTable() { @Test void implement() { PrometheusSystemTable systemIndex = new PrometheusSystemTable(client, - new CatalogSchemaName("prometheus", "information_schema"), TABLE_INFO); + new DataSourceSchemaName("prometheus", "information_schema"), TABLE_INFO); NamedExpression projectExpr = named("TABLE_NAME", ref("TABLE_NAME", STRING)); final PhysicalPlan plan = systemIndex.implement(