Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use query execution start time as the value of now-like functions. #1047

Merged
merged 15 commits into from
Dec 2, 2022

Conversation

MaxKsyunz
Copy link
Collaborator

Description

  • Add FunctionProperties interface to capture query metadata and provide to function implementations.
  • Update FunctionBuilder to take FunctionProperties in addition to function arguments when evaluating a SQL function.
  • Implement now-like functions using FunctionProperties.
  • Add FunctionDSL.nullMissingHandlingWithProperties to allow for consistent null and missing value handling across all functions.
  • Remove constant value caching from ExpressionAnalyzer. It is no longer necessary in ExpressionAnalyzer -- the same behavior is now implemented with FunctionProperties.

Unit Tests

  • Adjust getQueryStartClock_differs_from_instantNow unit test. On Windows, getQueryStartClock_differs_from_instantNow fails because Instant.now() in the test returns the same value as Instant.now() called for FunctionProperties construction.
  • Add unit tests for FunctionDSL.
  • Use Spring to instantiate dsl in OpenSearchTestBase.

Signed-off-by: MaxKsyunz [email protected]

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@MaxKsyunz MaxKsyunz requested a review from a team as a code owner November 8, 2022 20:40
@codecov-commenter
Copy link

codecov-commenter commented Nov 8, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.79%. Comparing base (e2bf254) to head (ea4588e).
Report is 406 commits behind head on 2.x.

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #1047      +/-   ##
============================================
- Coverage     98.29%   95.79%   -2.51%     
- Complexity     3465     3470       +5     
============================================
  Files           347      358      +11     
  Lines          8647     9315     +668     
  Branches        550      668     +118     
============================================
+ Hits           8500     8923     +423     
- Misses          142      334     +192     
- Partials          5       58      +53     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine 98.30% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -51,8 +56,14 @@ public BuiltinFunctionRepository functionRepository() {
return builtinFunctionRepository;
}

@Bean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FunctionProperties should be created per-request. Currently, Spring IoC container is created per-request which is not efficient and has issue (#611) , it will be changed to per jvm (#822), then BuiltinFunctionRepository is singleton instance per jvm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@penghuo in e7ccfc2 I moved FunctionProperties instantiation from ExpressionConfig to context creation time. Is that what you had in mind?

Copy link
Collaborator

@penghuo penghuo Nov 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactally.

  1. ApplicationContext should be created per-node instead of per-request. Which means FunctionProperties should not been created in ApplicationContext.
  2. @dai-chen also think of making FunctionRepositoy as singleton. Reference, Decouple function repository and DSL from IoC container for use anywhere #1045

I think FunctionProperties should be in a context and pass as paramater to Analyzer and FunctionProperties.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@penghuo, I will move Spring setup to SQLPlugin.createComponents and update as appropriate.

Copy link
Collaborator Author

@MaxKsyunz MaxKsyunz Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@penghuo, I will move Spring setup to SQLPlugin.createComponents and update as appropriate.

As discussed offline with @penghuo , this PR will wait on merge of #1045 into 2.x branch.

cc @dai-chen

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@penghuo and @dai-chen this PR is ready for another review. The branch have been updated from 2.x and modified to work with static BuiltinFunctionRepository class.

Thanks!



- Add FunctionProperties interface to capture query metadata and
 provide to function implementations.
- Update FunctionBuilder to take FunctionProperties in addition to
 function arguments when evaluating a SQL function.
- Implement now-like functions using FunctionProperties.
- Add FunctionDSL.nullMissingHandlingWithProperties to allow for
 consistent null and missing value handling across all functions.
- Remove constant value caching from ExpressionAnalyzer
 -- the same behavior is now implemented with FunctionProperties.

### Unit Tests
- Adjust getQueryStartClock_differs_from_instantNow unit test.
  On Windows, getQueryStartClock_differs_from_instantNow fails
  because Instant.now() in the test returns the same value as
  Instant.now() called for FunctionProperties construction.
- Add unit tests for FunctionDSL.
- Use Spring to instantiate dsl in OpenSearchTestBase.

Signed-off-by: MaxKsyunz <[email protected]>
@MaxKsyunz
Copy link
Collaborator Author

I'm looking into integration test failures.

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]>
@MaxKsyunz
Copy link
Collaborator Author

I'm looking into integration test failures.

Done. There was a integration test that was instantiating PPLSerivceConfig and required a registration for FunctionProperties.

MitchellGale
MitchellGale previously approved these changes Nov 11, 2022
acarbonetto
acarbonetto previously approved these changes Nov 14, 2022
The core of reimplementation is to provide FunctionProperties at
 function compilation in Analyzer *or ExpressionAnalyzer). See
  FunctionBuilder.apply(FunctionProperties, List<Expression> arguments)

AnalysisContext provides an instance of FunctionProperties.

The rest of the changes are the consequence of the above.

Signed-off-by: MaxKsyunz <[email protected]>
@MaxKsyunz MaxKsyunz dismissed stale reviews from acarbonetto and MitchellGale via f9270da November 23, 2022 22:49
MaxKsyunz added 7 commits November 23, 2022 18:06
# Conflicts:
#	core/src/main/java/org/opensearch/sql/analysis/Analyzer.java
#	integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java
#	ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java
They were introduced earlier before BuiltinFunctionRepository became
static.

Signed-off-by: MaxKsyunz <[email protected]>
Signed-off-by: MaxKsyunz <[email protected]>
MaxKsyunz added 2 commits November 23, 2022 22:26
Most functions in DSL class do not use FunctionProperties.
Use a placeholder instance.

Signed-off-by: MaxKsyunz <[email protected]>
import org.springframework.context.annotation.Configuration;

@Configuration
public class FunctionPropertiesTestConfig {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move TestConfig to test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved in ea4588e

import java.io.Serializable;
import java.time.Clock;

public interface FunctionProperties extends Serializable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the interface required? i think NONE could extend FunctionProperties, and QueryFunctionProperties could be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ea4588e


private final boolean allowExplicitIndex;

private static final Predicate<String> CONTAINS_SUBQUERY = Pattern.compile("\\(\\s*select ").asPredicate();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you elaborate more the change in RestSqlAction? I did not expect much change should in here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a white space change IntelliJ snuck in during when merging with 2.X.

I'll redo the branch to discard those changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ea4588e

MaxKsyunz added 2 commits November 30, 2022 00:42
- Change FunctionProperties into a concrete class.
- Move FunctionPropertiesConfig to test since it's only used for
testing. Required chaning how PPLServiceTest and StandaloneIT
instantiate FunctionProperties bean.

Signed-off-by: MaxKsyunz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants