-
Notifications
You must be signed in to change notification settings - Fork 0
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. #149
Conversation
Add QueryContext interface to capture query metadata and provide to function implementations. Update FunctionBuilder to take QueryContext in addition to function arguments when evaluating a SQL function. Implement constant date time functions using QueryContext. Signed-off-by: MaxKsyunz <[email protected]>
- Address checkstyle errors - Add comments to QueryContext. - Address PR feedback. Signed-off-by: MaxKsyunz <[email protected]>
1. Rename QueryContext to FunctionProperties, renmae related parameter names. 2. Remove QueryContext interface. 3. Add FunctionProperties as a bean to ExpressionConfig. 4. Add unit tests for ExpressionConfig. Refactored unit tests in opensearch module to keep ExpressionCOnfig misuse in one place -- OpenSearchTestBase. Signed-off-by: MaxKsyunz <[email protected]>
Signed-off-by: MaxKsyunz <[email protected]>
Signed-off-by: MaxKsyunz <[email protected]>
Signed-off-by: MaxKsyunz <[email protected]>
# Conflicts: # core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java # core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java
Make FunctionProperties serializable -- required toString override. Signed-off-by: MaxKsyunz <[email protected]>
Are you planning to partially revert changes done in #113? You can't prove that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update UNIX_TIMESTAMP
function and its tests - opensearch-project#996.
Codecov Report
@@ Coverage Diff @@
## integ-constant-now #149 +/- ##
========================================================
- Coverage 98.26% 95.68% -2.59%
- Complexity 3325 3329 +4
========================================================
Files 324 335 +11
Lines 8399 9053 +654
Branches 553 671 +118
========================================================
+ Hits 8253 8662 +409
- Misses 142 334 +192
- Partials 4 57 +53
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Add unit tests for FunctionProperties, including ensuring it is serializable. Fix serializability of return value of FunctionDSL.implWithProperties Signed-off-by: MaxKsyunz <[email protected]>
Signed-off-by: MaxKsyunz <[email protected]>
Signed-off-by: MaxKsyunz <[email protected]>
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java
Show resolved
Hide resolved
Signed-off-by: MaxKsyunz <[email protected]>
Constant value caching is no longer necessary in ExpressionAnalyzer -- the same behavior is now implemented with FunctionProperties. Signed-off-by: MaxKsyunz <[email protected]>
On Windows, getQueryStartClock_differs_from_instantNow fails because Instant.now() in the test returns the same value as Instant.now() called for FunctionProperties construction. Signed-off-by: MaxKsyunz <[email protected]>
It's failing on Windows -- turns out the assumption about Spring it was testing does not hold true across platforms. Signed-off-by: MaxKsyunz <[email protected]>
core/src/test/java/org/opensearch/sql/expression/function/FunctionDSLTestBase.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad to see major test grooming here. Can you add brief what and why was changed? Thanks!
} | ||
}; | ||
return Pair.of(functionSignature, functionBuilder); | ||
}; | ||
} | ||
|
||
/** | ||
* Unary Function Implementation. | ||
* Implementation of no args function that uses FunctionProperties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you swap no-args-function and one-arg-function back? Just to smaller diff.
|
||
private LocalDateTime getExpectedNow() { | ||
return LocalDateTime.now( | ||
functionProperties.getQueryStartClock().withZone(ZoneId.of("UTC"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use ExprTimestampValue.ZONE
here instead?
core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java
Outdated
Show resolved
Hide resolved
{ | ||
ExpressionConfig config = new ExpressionConfig(); | ||
dsl = config.dsl(config.functionRepository(config.functionExecutionContext())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make dsl
Autowired
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you name variable DSL
(uppercase) you can avoid hundreds changes in inherited test classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you name variable
DSL
(uppercase) you can avoid hundreds changes in inherited test classes.
namedArgument
is a static method -- it works fine without an instance of DSL
class. With this updated it's clearer where DSL
instance is required and therefore which methods need Spring.
Signed-off-by: MaxKsyunz <[email protected]>
Signed-off-by: MaxKsyunz <[email protected]>
Is it supposed to fix conversion |
Don't think so?I only made changes sufficient to fix failing tests. |
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Show resolved
Hide resolved
Is it possible to use |
* `fsp` argument support is removed until refactoring to avoid bug where `now()`, `now(x)` and | ||
* `now(y) return different values. | ||
*/ | ||
private FunctionResolver now(FunctionName functionName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to return FunctionResolver
, but not DefaultFunctionResolver
? Does this matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FunctionResolver
is an interface and DefaultFunctionResolver
is an implementation.
Standard practice is to return the most generic type possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we groom then to return FunctionResolver
everywhere in DateTimeFunction
?
"localtime", | ||
"now", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't checkstyle blame indents there?
Good point! I'll add that. |
Add FunctionDSL.nullMissingHandlingWithProperties to all for consistent null and missing value handling across all functions. Signed-off-by: MaxKsyunz <[email protected]>
527a735
to
5bed983
Compare
- 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]>
- 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]>
Validated ✅ LGTM |
…notes for 2.3.0 version. (#149) Signed-off-by: Navneet Verma <[email protected]> Signed-off-by: Navneet Verma <[email protected]>
Description
Implement now-family of functions using FunctionProperties object.
This object is created at query execution start.
This ensures that each call to
now
inSELECT now(), now(), now()
will return the same value..Issues Resolved
[List any issues this PR will resolve]
Check List
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.