Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
Remove FunctionProperties from ExpressionConfig and create it
when create<LANG>Service is called. This ensures it's created for each
query.

Created FunctionPropertiesTestConfig to simplify updating unit tests
to work with the change above.

Removed an infrequently-used version of
BuiltinFunctionRepository.compile and
@Getter on BuiltinFunctionRepository.functionProperties -- it was only
used for a test -- ExpressionConfigTest. Removed the test because
it was testing Spring behavior and not very valuable.

Signed-off-by: MaxKsyunz <[email protected]>
  • Loading branch information
MaxKsyunz committed Nov 10, 2022
1 parent 703275a commit e50074b
Show file tree
Hide file tree
Showing 33 changed files with 129 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class BuiltinFunctionRepository {

private final Map<String, Map<FunctionName, FunctionResolver>> namespaceFunctionResolverMap;

@Getter
private final FunctionProperties functionProperties;


Expand Down Expand Up @@ -65,12 +64,6 @@ public void register(String namespace, FunctionResolver resolver) {
namespaceFunctionResolverMap.get(namespace).put(resolver.getFunctionName(), resolver);
}


public FunctionImplementation compile(BuiltinFunctionName functionName,
List<Expression> expressions) {
return compile(functionName.getName(), expressions);
}

/**
* Compile FunctionExpression under default namespace.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@
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;
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 ExpressionAnalyzerTest extends AnalyzerTestBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
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;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@Configuration
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {ExpressionConfig.class, SelectAnalyzeTest.class})
@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class,
SelectAnalyzeTest.class})
public class SelectAnalyzeTest extends AnalyzerTestBase {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,14 +25,16 @@
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;

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
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;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class})
@ContextConfiguration(classes = {FunctionPropertiesTestConfig.class, ExpressionConfig.class,
AnalyzerTestBase.class})
class ExpressionNodeVisitorTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

This file was deleted.

Loading

0 comments on commit e50074b

Please sign in to comment.