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 index ccae09d050..a026c51919 100644 --- a/core/src/main/java/org/opensearch/sql/expression/config/ExpressionConfig.java +++ b/core/src/main/java/org/opensearch/sql/expression/config/ExpressionConfig.java @@ -25,6 +25,7 @@ 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.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -56,10 +57,8 @@ public BuiltinFunctionRepository functionRepository(FunctionProperties functionC return builtinFunctionRepository; } - @Bean - public FunctionProperties functionExecutionContext() { - return new FunctionProperties(Instant.now(), ZoneId.systemDefault()); - } + @Autowired + FunctionProperties functionProperties; @Bean public DSL dsl(BuiltinFunctionRepository 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 08692481cd..3e18bb4629 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 @@ -36,7 +36,6 @@ public class BuiltinFunctionRepository { private final Map> namespaceFunctionResolverMap; - @Getter private final FunctionProperties functionProperties; @@ -65,12 +64,6 @@ public void register(String namespace, FunctionResolver resolver) { namespaceFunctionResolverMap.get(namespace).put(resolver.getFunctionName(), resolver); } - - public FunctionImplementation compile(BuiltinFunctionName functionName, - List expressions) { - return compile(functionName.getName(), expressions); - } - /** * Compile FunctionExpression under default namespace. * diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java index 279019973e..139ace2a29 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java @@ -23,6 +23,13 @@ public class FunctionProperties implements Serializable { private final Instant nowInstant; private final ZoneId currentZoneId; + /** + * By default, use current time and current timezone. + */ + public FunctionProperties() { + nowInstant = Instant.now(); + currentZoneId = ZoneId.systemDefault(); + } /** * Method to access current system clock. diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionPropertiesTestConfig.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionPropertiesTestConfig.java new file mode 100644 index 0000000000..dfc9b543ae --- /dev/null +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionPropertiesTestConfig.java @@ -0,0 +1,17 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.expression.function; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class FunctionPropertiesTestConfig { + @Bean + FunctionProperties functionProperties() { + return new FunctionProperties(); + } +} 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..dd094b77c9 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -81,6 +81,7 @@ import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.HighlightExpression; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.opensearch.sql.expression.window.WindowDefinition; import org.opensearch.sql.planner.logical.LogicalAD; import org.opensearch.sql.planner.logical.LogicalMLCommons; @@ -96,7 +97,8 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTest.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, + ExpressionConfig.class, AnalyzerTest.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) class AnalyzerTest extends AnalyzerTestBase { 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 dc97d602fa..d629ab1b37 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java @@ -33,6 +33,7 @@ import org.opensearch.sql.expression.function.BuiltinFunctionRepository; import org.opensearch.sql.expression.function.FunctionBuilder; import org.opensearch.sql.expression.function.FunctionName; +import org.opensearch.sql.expression.function.FunctionProperties; import org.opensearch.sql.expression.function.FunctionResolver; import org.opensearch.sql.expression.function.FunctionSignature; import org.opensearch.sql.expression.function.TableFunctionImplementation; 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 284540a478..fc6f0e3d27 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java @@ -48,8 +48,8 @@ import org.opensearch.sql.expression.DSL; 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.function.FunctionPropertiesTestConfig; import org.opensearch.sql.expression.window.aggregation.AggregateWindowFunction; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; @@ -57,7 +57,8 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + AnalyzerTestBase.class}) class ExpressionAnalyzerTest extends AnalyzerTestBase { @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..5e0d5a7a0e 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizerTest.java @@ -18,6 +18,7 @@ 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.FunctionPropertiesTestConfig; import org.opensearch.sql.expression.window.WindowDefinition; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.logical.LogicalPlanDSL; @@ -27,7 +28,8 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTest.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + AnalyzerTest.class}) class ExpressionReferenceOptimizerTest extends AnalyzerTestBase { @Test 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..132d9fa62c 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/NamedExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/NamedExpressionAnalyzerTest.java @@ -18,13 +18,15 @@ import org.opensearch.sql.ast.expression.Literal; import org.opensearch.sql.expression.NamedExpression; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; 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 = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + 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..22bc7b5cc6 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/QualifierAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/QualifierAnalyzerTest.java @@ -19,13 +19,15 @@ import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; 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 = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + 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..0193f1f383 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/SelectAnalyzeTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/SelectAnalyzeTest.java @@ -24,6 +24,7 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.opensearch.sql.planner.logical.LogicalPlanDSL; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; @@ -31,7 +32,8 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, SelectAnalyzeTest.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + SelectAnalyzeTest.class}) public class SelectAnalyzeTest extends AnalyzerTestBase { @Override 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..500b05b486 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; @@ -27,6 +25,7 @@ import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.NamedExpression; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -34,7 +33,8 @@ @Configuration @ExtendWith(SpringExtension.class) @ExtendWith(MockitoExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, SelectExpressionAnalyzerTest.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + SelectExpressionAnalyzerTest.class}) public class SelectExpressionAnalyzerTest extends AnalyzerTestBase { @Mock 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..6cda1a66e1 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; @@ -31,6 +30,7 @@ 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.function.FunctionPropertiesTestConfig; import org.opensearch.sql.expression.window.WindowDefinition; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.logical.LogicalPlanDSL; @@ -42,7 +42,8 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, SelectExpressionAnalyzerTest.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + SelectExpressionAnalyzerTest.class}) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class WindowExpressionAnalyzerTest extends AnalyzerTestBase { 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 e089ae376f..f46dd7331d 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java @@ -27,6 +27,7 @@ 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.function.FunctionPropertiesTestConfig; import org.opensearch.sql.expression.parse.ParseExpression; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -34,7 +35,8 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + AnalyzerTestBase.class}) class ExpressionNodeVisitorTest { @Autowired 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 dd28ea8975..ed00bbb558 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionTestBase.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionTestBase.java @@ -37,6 +37,7 @@ import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.BuiltinFunctionName; import org.opensearch.sql.expression.function.FunctionProperties; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -45,8 +46,8 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, ExpressionTestBase.class, - TestConfig.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + ExpressionTestBase.class, TestConfig.class}) public class ExpressionTestBase { @Autowired protected DSL dsl; diff --git a/core/src/test/java/org/opensearch/sql/expression/config/ExpressionConfigTest.java b/core/src/test/java/org/opensearch/sql/expression/config/ExpressionConfigTest.java deleted file mode 100644 index d36c90599e..0000000000 --- a/core/src/test/java/org/opensearch/sql/expression/config/ExpressionConfigTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.expression.config; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -import org.junit.jupiter.api.Test; -import org.opensearch.sql.expression.function.BuiltinFunctionRepository; -import org.opensearch.sql.expression.function.FunctionProperties; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; - -class ExpressionConfigTest { - private static AnnotationConfigApplicationContext createContext() { - var context = new AnnotationConfigApplicationContext(); - context.register(ExpressionConfig.class); - context.refresh(); - return context; - } - - @Test - void testContextIsFromBean() { - AnnotationConfigApplicationContext context = createContext(); - BuiltinFunctionRepository repository = context.getBean(BuiltinFunctionRepository.class); - assertEquals(repository.getFunctionProperties(), - context.getBean(FunctionProperties.class)); - } -} 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 63acdb5186..1b0883913c 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 @@ -45,24 +45,25 @@ protected ExprValue eval(Expression expression) { return expression.valueOf(env); } + protected LocalDateTime fromUnixTime(Double value) { + return fromUnixTime(DSL.literal(value)).valueOf().datetimeValue(); + } + protected FunctionExpression fromUnixTime(Expression value) { return (FunctionExpression) - functionRepository.compile(BuiltinFunctionName.FROM_UNIXTIME, List.of(value)); + functionRepository.compile(BuiltinFunctionName.FROM_UNIXTIME.getName(), List.of(value)); } protected FunctionExpression fromUnixTime(Expression value, Expression format) { return (FunctionExpression) - functionRepository.compile(BuiltinFunctionName.FROM_UNIXTIME, List.of(value, format)); + functionRepository.compile( + BuiltinFunctionName.FROM_UNIXTIME.getName(), List.of(value, format)); } protected LocalDateTime fromUnixTime(Long value) { return fromUnixTime(DSL.literal(value)).valueOf().datetimeValue(); } - protected LocalDateTime fromUnixTime(Double value) { - return fromUnixTime(DSL.literal(value)).valueOf().datetimeValue(); - } - protected String fromUnixTime(Long value, String format) { return fromUnixTime(DSL.literal(value), DSL.literal(format)) .valueOf().stringValue(); @@ -75,17 +76,19 @@ protected String fromUnixTime(Double value, String format) { protected FunctionExpression maketime(Expression hour, Expression minute, Expression second) { return (FunctionExpression) - functionRepository.compile(BuiltinFunctionName.MAKETIME, List.of(hour, minute, second)); + functionRepository.compile( + BuiltinFunctionName.MAKETIME.getName(), List.of(hour, minute, second)); } + protected LocalTime maketime(Double hour, Double minute, Double second) { return maketime(DSL.literal(hour), DSL.literal(minute), DSL.literal(second)) .valueOf().timeValue(); } protected FunctionExpression makedate(Expression year, Expression dayOfYear) { - return (FunctionExpression) - functionRepository.compile(BuiltinFunctionName.MAKEDATE, List.of(year, dayOfYear)); + return (FunctionExpression) functionRepository.compile( + BuiltinFunctionName.MAKEDATE.getName(), List.of(year, dayOfYear)); } protected LocalDate makedate(double year, double dayOfYear) { @@ -93,8 +96,8 @@ protected LocalDate makedate(double year, double dayOfYear) { } protected FunctionExpression period_add(Expression period, Expression months) { - return (FunctionExpression) - functionRepository.compile(BuiltinFunctionName.PERIOD_ADD, List.of(period, months)); + return (FunctionExpression) functionRepository.compile( + BuiltinFunctionName.PERIOD_ADD.getName(), List.of(period, months)); } protected Integer period_add(Integer period, Integer months) { @@ -103,8 +106,8 @@ protected Integer period_add(Integer period, Integer months) { } protected FunctionExpression period_diff(Expression first, Expression second) { - return (FunctionExpression) - functionRepository.compile(BuiltinFunctionName.PERIOD_DIFF, List.of(first, second)); + return (FunctionExpression) functionRepository.compile( + BuiltinFunctionName.PERIOD_DIFF.getName(), List.of(first, second)); } protected Integer period_diff(Integer first, Integer second) { @@ -113,8 +116,8 @@ protected Integer period_diff(Integer first, Integer second) { } protected FunctionExpression unixTimeStampExpr() { - return (FunctionExpression) - functionRepository.compile(BuiltinFunctionName.UNIX_TIMESTAMP, List.of()); + return (FunctionExpression) functionRepository.compile( + BuiltinFunctionName.UNIX_TIMESTAMP.getName(), List.of()); } protected Long unixTimeStamp() { @@ -123,7 +126,7 @@ protected Long unixTimeStamp() { protected FunctionExpression unixTimeStampOf(Expression value) { return (FunctionExpression) - functionRepository.compile(BuiltinFunctionName.UNIX_TIMESTAMP, List.of(value)); + functionRepository.compile(BuiltinFunctionName.UNIX_TIMESTAMP.getName(), List.of(value)); } protected Double unixTimeStampOf(Double value) { 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 b0dcf83d24..1c66fc1ee2 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 @@ -43,12 +43,14 @@ import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.FunctionExpression; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + AnalyzerTestBase.class}) class TypeCastOperatorTest { @Autowired 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 aa49c45725..d2dc43d286 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 @@ -40,13 +40,14 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class SystemFunctionsTest { 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..f6d4d2bf7e 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 @@ -22,13 +22,15 @@ import org.opensearch.sql.analysis.AnalyzerTestBase; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; 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 = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + 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..82c0dce071 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 @@ -17,13 +17,15 @@ import org.opensearch.sql.ast.dsl.AstDSL; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; 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 = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + AnalyzerTestBase.class}) @ExtendWith(MockitoExtension.class) public class LogicalEvalTest extends AnalyzerTestBase { 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..30e45b19ac 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 @@ -24,13 +24,15 @@ 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.function.FunctionPropertiesTestConfig; 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 = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + 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..134cc50239 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 @@ -22,6 +22,7 @@ import org.opensearch.sql.ast.tree.Sort; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.opensearch.sql.planner.logical.LogicalPlan; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; @@ -29,7 +30,8 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class, + AnalyzerTestBase.class}) class LogicalPlanOptimizerTest extends AnalyzerTestBase { /** * Filter - Filter --> Filter. 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..f2c79076f0 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 @@ -25,6 +25,7 @@ import org.opensearch.sql.expression.ReferenceExpression; import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -33,7 +34,7 @@ @Configuration @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class}) public class PhysicalPlanTestBase { @Autowired protected DSL dsl; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java index 0db08398b8..9a00b4c4ec 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java @@ -13,6 +13,8 @@ import java.io.IOException; import java.security.PrivilegedExceptionAction; +import java.time.Instant; +import java.time.ZoneId; import java.util.List; import javax.xml.catalog.Catalog; import org.apache.logging.log4j.LogManager; @@ -29,6 +31,7 @@ import org.opensearch.sql.common.response.ResponseListener; import org.opensearch.sql.common.setting.Settings; import org.opensearch.sql.executor.ExecutionEngine.ExplainResponse; +import org.opensearch.sql.expression.function.FunctionProperties; import org.opensearch.sql.legacy.metrics.MetricName; import org.opensearch.sql.legacy.metrics.Metrics; import org.opensearch.sql.opensearch.security.SecurityAccess; @@ -68,7 +71,8 @@ public class RestSQLQueryAction extends BaseRestHandler { /** * Constructor of RestSQLQueryAction. */ - public RestSQLQueryAction(ClusterService clusterService, Settings pluginSettings, CatalogService catalogService) { + public RestSQLQueryAction(ClusterService clusterService, Settings pluginSettings, + CatalogService catalogService) { super(); this.clusterService = clusterService; this.pluginSettings = pluginSettings; @@ -126,6 +130,7 @@ public RestChannelConsumer prepareRequest(SQLQueryRequest request, NodeClient no private SQLService createSQLService(NodeClient client) { return doPrivileged(() -> { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.registerBean(FunctionProperties.class, FunctionProperties::new); context.registerBean(ClusterService.class, () -> clusterService); context.registerBean(NodeClient.class, () -> client); context.registerBean(Settings.class, () -> pluginSettings); @@ -137,6 +142,8 @@ private SQLService createSQLService(NodeClient client) { }); } + + private ResponseListener createExplainResponseListener(RestChannel channel) { return new ResponseListener() { @Override @@ -159,7 +166,8 @@ public void onFailure(Exception e) { }; } - private ResponseListener createQueryResponseListener(RestChannel channel, SQLQueryRequest request) { + private ResponseListener createQueryResponseListener(RestChannel channel, + SQLQueryRequest request) { Format format = request.format(); ResponseFormatter formatter; if (format.equals(Format.CSV)) { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/OpenSearchTestBase.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/OpenSearchTestBase.java index 6c93ed77a1..6fd679c523 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/OpenSearchTestBase.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/OpenSearchTestBase.java @@ -8,13 +8,14 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class OpenSearchTestBase { diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java b/plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java index eaad009216..dcaf2dc44a 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java @@ -23,6 +23,7 @@ import org.opensearch.sql.common.setting.Settings; import org.opensearch.sql.common.utils.QueryContext; import org.opensearch.sql.executor.ExecutionEngine; +import org.opensearch.sql.expression.function.FunctionProperties; import org.opensearch.sql.legacy.metrics.MetricName; import org.opensearch.sql.legacy.metrics.Metrics; import org.opensearch.sql.opensearch.security.SecurityAccess; @@ -98,6 +99,7 @@ private PPLService createPPLService(NodeClient client) { return doPrivileged( () -> { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.registerBean(FunctionProperties.class, FunctionProperties::new); context.registerBean(ClusterService.class, () -> clusterService); context.registerBean(NodeClient.class, () -> client); context.registerBean(Settings.class, () -> pluginSettings); diff --git a/ppl/src/main/antlr/OpenSearchPPLParser.g4 b/ppl/src/main/antlr/OpenSearchPPLParser.g4 index 37cce6f923..1274a191bc 100644 --- a/ppl/src/main/antlr/OpenSearchPPLParser.g4 +++ b/ppl/src/main/antlr/OpenSearchPPLParser.g4 @@ -414,9 +414,11 @@ trigonometricFunctionName ; dateAndTimeFunctionBase - : datetimeConstantLiteral - | ADDDATE + : ADDDATE | CONVERT_TZ + | CURRENT_DATE + | CURRENT_TIME + | CURRENT_TIMESTAMP | DATE | DATE_ADD | DATE_FORMAT @@ -432,6 +434,8 @@ dateAndTimeFunctionBase | FROM_DAYS | FROM_UNIXTIME | HOUR + | LOCALTIME + | LOCALTIMESTAMP | MAKEDATE | MAKETIME | MICROSECOND @@ -450,6 +454,9 @@ dateAndTimeFunctionBase | TIMESTAMP | TO_DAYS | UNIX_TIMESTAMP + | UTC_DATE + | UTC_TIME + | UTC_TIMESTAMP | WEEK | YEAR ; @@ -541,18 +548,6 @@ timestampLiteral : TIMESTAMP timestamp=stringLiteral ; -// Actually, these constants are shortcuts to the corresponding functions -datetimeConstantLiteral - : CURRENT_DATE - | CURRENT_TIME - | CURRENT_TIMESTAMP - | LOCALTIME - | LOCALTIMESTAMP - | UTC_TIMESTAMP - | UTC_DATE - | UTC_TIME - ; - intervalUnit : MICROSECOND | SECOND | MINUTE | HOUR | DAY | WEEK | MONTH | QUARTER | YEAR | SECOND_MICROSECOND | MINUTE_MICROSECOND | MINUTE_SECOND | HOUR_MICROSECOND | HOUR_SECOND | HOUR_MINUTE | DAY_MICROSECOND 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 f53f333b17..a2861705ba 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java @@ -30,6 +30,7 @@ import org.opensearch.sql.executor.ExecutionEngine.QueryResponse; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.function.BuiltinFunctionRepository; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.opensearch.sql.expression.function.FunctionResolver; import org.opensearch.sql.planner.physical.PhysicalPlan; import org.opensearch.sql.ppl.config.PPLServiceConfig; @@ -88,6 +89,7 @@ public void setUp() { context.registerBean(StorageEngine.class, () -> storageEngine); context.registerBean(ExecutionEngine.class, () -> executionEngine); context.registerBean(CatalogService.class, () -> catalogService); + context.register(FunctionPropertiesTestConfig.class); context.register(PPLServiceConfig.class); context.refresh(); pplService = context.getBean(PPLService.class); 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 c181e0263c..7358705e57 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 @@ -26,6 +26,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.optimizer.LogicalPlanOptimizer; import org.opensearch.sql.storage.Table; @@ -36,7 +37,7 @@ @ExtendWith(MockitoExtension.class) @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class PrometheusLogicOptimizerTest { 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 ee42c21f97..3f39eb4dee 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,6 +50,7 @@ import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.NamedExpression; import org.opensearch.sql.expression.config.ExpressionConfig; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.physical.PhysicalPlan; import org.opensearch.sql.planner.physical.ProjectOperator; @@ -63,7 +64,7 @@ @ExtendWith(MockitoExtension.class) @ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ExpressionConfig.class}) +@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) class PrometheusMetricTableTest { diff --git a/sql/src/test/java/org/opensearch/sql/sql/SQLServiceTest.java b/sql/src/test/java/org/opensearch/sql/sql/SQLServiceTest.java index 774c5e2d52..f0776812c1 100644 --- a/sql/src/test/java/org/opensearch/sql/sql/SQLServiceTest.java +++ b/sql/src/test/java/org/opensearch/sql/sql/SQLServiceTest.java @@ -26,6 +26,7 @@ import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.ExecutionEngine.ExplainResponse; import org.opensearch.sql.executor.ExecutionEngine.ExplainResponseNode; +import org.opensearch.sql.expression.function.FunctionPropertiesTestConfig; import org.opensearch.sql.planner.physical.PhysicalPlan; import org.opensearch.sql.sql.config.SQLServiceConfig; import org.opensearch.sql.sql.domain.SQLQueryRequest; @@ -56,6 +57,7 @@ public void setUp() { context.registerBean(StorageEngine.class, () -> storageEngine); context.registerBean(ExecutionEngine.class, () -> executionEngine); context.registerBean(CatalogService.class, () -> catalogService); + context.register(FunctionPropertiesTestConfig.class); context.register(SQLServiceConfig.class); context.refresh(); sqlService = context.getBean(SQLService.class);