-
Notifications
You must be signed in to change notification settings - Fork 176
Support time modifiers in search command #4224
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
Conversation
can you review this: #4152 |
Hi @vamsimanohar, thank you for reminding! I think the functionality does not overlap, I'll re-implement this based on your grammar. |
@yuancu Few things to keep in mind.
I think it should be possible with your changes. |
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Unit test search with absolute time range Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Rephrase timeRange and timeModifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Switch to earliest and latest udf Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Add a convert util Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Verify time correctness during coversion Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix quarter parsing bugs Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix week snap parsing Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Remove old implementation that translates time modifier to time filter Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
core/src/main/java/org/opensearch/sql/expression/function/udf/condition/EarliestFunction.java
Show resolved
Hide resolved
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
core/build.gradle
Outdated
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: "${hamcrest_version}" | ||
testImplementation group: 'org.mockito', name: 'mockito-core', version: "${mockito_version}" | ||
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockito_version}" | ||
testImplementation group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}" |
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.
This dependency is added for the access of org.opensearch.common.time.DateMathParser
-- I want to make sure that the parsed OpenSearch date math like now-1d/M-2M
returns the intended instant for -1d@q
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.
parseRelativeTime() is called by PPL module only, right? if move parseRelativeTime to PPL module, does opensearch depedency still needed?
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.
Yes, it is only called by PPL module. If I still want to assure the correctness of the parsed instant, I'll have to move this dependency to the PPL module.
Is there any concern over this dependency? If it's for the performance, as the dependency is only test time, I assume there would be no harm to the runtime performance.
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.
we want core modules to not depend on any opensearch dependencies. This helps in our future plans to publish ppl as a library or running sql engine as a separate service.
If we can avoid, its better to avoid.
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.
Thanks for the explanation! I've removed the dependency and related tests.
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
Show resolved
Hide resolved
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Unit test and explaining IT covers all of them. I did not cover some relative time modifier in integration test because they either have something to do with the current time, which may be flaky to mock and test. I'll try to cover more of them in the integration test. E.g. there exists unknown latency after I write a timestamp and before the query is executed. |
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
The requested change has been addressed.
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.19-dev 2.19-dev
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.19-dev
# Create a new branch
git switch --create backport/backport-4224-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 e4685137de681a5f513a88c681b406ad5a786c27
# Push it to GitHub
git push --set-upstream origin backport/backport-4224-to-2.19-dev
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.19-dev Then, create a pull request where the |
* Implement absolute time range in search command Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Unit test search with absolute time range Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Rephrase timeRange and timeModifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Switch to earliest and latest udf Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Add a convert util Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Verify time correctness during coversion Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix quarter parsing bugs Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix week snap parsing Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Remove old implementation that translates time modifier to time filter Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix anomalyzed test & add a todo for an ignored test Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support now() in time range Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix time modifier explain ITs Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support unixtimestamp (second) as a time modifier value Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update docs for search command with time modifiers Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Test accessing fields with name earliest and latest in search command Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update doctest in condition.rst due to the update in the implementation of earliest and latest conditions Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update PPLQueryDataAnonymizerTest.java Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update explain ITs to use yaml plan files Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update a link to OpenSearch exists Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support using timesnaps without quotes Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add a unit test for direct format - additionally rename parseRelativeTime to resolveTimeModifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add support to ISO 8601 date format to time modifier, as it is now widely supported in PPL Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update syntax by reusing SPANLENGTH definition Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update explain IT for search with time modifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add integration tests for time modifiers Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Parse timestamp string with multiple parsers in a loop Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Remove opensearch test dependency from core module Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix unit tests Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Minor updates to explain limitations in search doc Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> --------- Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> (cherry picked from commit e468513)
* Implement absolute time range in search command Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Unit test search with absolute time range Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Rephrase timeRange and timeModifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Switch to earliest and latest udf Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Add a convert util Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Verify time correctness during coversion Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix quarter parsing bugs Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix week snap parsing Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Remove old implementation that translates time modifier to time filter Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix anomalyzed test & add a todo for an ignored test Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support now() in time range Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix time modifier explain ITs Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support unixtimestamp (second) as a time modifier value Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update docs for search command with time modifiers Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Test accessing fields with name earliest and latest in search command Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update doctest in condition.rst due to the update in the implementation of earliest and latest conditions Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update PPLQueryDataAnonymizerTest.java Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update explain ITs to use yaml plan files Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update a link to OpenSearch exists Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support using timesnaps without quotes Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add a unit test for direct format - additionally rename parseRelativeTime to resolveTimeModifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add support to ISO 8601 date format to time modifier, as it is now widely supported in PPL Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update syntax by reusing SPANLENGTH definition Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update explain IT for search with time modifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add integration tests for time modifiers Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Parse timestamp string with multiple parsers in a loop Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Remove opensearch test dependency from core module Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix unit tests Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Minor updates to explain limitations in search doc Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> --------- Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> (cherry picked from commit e468513)
* Implement absolute time range in search command Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Unit test search with absolute time range Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Rephrase timeRange and timeModifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Switch to earliest and latest udf Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Add a convert util Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Verify time correctness during coversion Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix quarter parsing bugs Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix week snap parsing Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Remove old implementation that translates time modifier to time filter Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix anomalyzed test & add a todo for an ignored test Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support now() in time range Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix time modifier explain ITs Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support unixtimestamp (second) as a time modifier value Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update docs for search command with time modifiers Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Test accessing fields with name earliest and latest in search command Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update doctest in condition.rst due to the update in the implementation of earliest and latest conditions Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update PPLQueryDataAnonymizerTest.java Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update explain ITs to use yaml plan files Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update a link to OpenSearch exists Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Support using timesnaps without quotes Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add a unit test for direct format - additionally rename parseRelativeTime to resolveTimeModifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add support to ISO 8601 date format to time modifier, as it is now widely supported in PPL Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update syntax by reusing SPANLENGTH definition Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Update explain IT for search with time modifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Add integration tests for time modifiers Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Parse timestamp string with multiple parsers in a loop Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Remove opensearch test dependency from core module Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Fix unit tests Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> * Minor updates to explain limitations in search doc Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> --------- Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> (cherry picked from commit e468513)
* Implement absolute time range in search command Unit test search with absolute time range Rephrase timeRange and timeModifier Switch to earliest and latest udf Add a convert util Verify time correctness during coversion Fix quarter parsing bugs Fix week snap parsing Remove old implementation that translates time modifier to time filter * Fix anomalyzed test & add a todo for an ignored test * Support now() in time range * Fix time modifier explain ITs * Support unixtimestamp (second) as a time modifier value * Update docs for search command with time modifiers * Test accessing fields with name earliest and latest in search command * Update doctest in condition.rst due to the update in the implementation of earliest and latest conditions * Update PPLQueryDataAnonymizerTest.java * Update explain ITs to use yaml plan files * Update a link to OpenSearch exists * Support using timesnaps without quotes * Add a unit test for direct format - additionally rename parseRelativeTime to resolveTimeModifier * Add support to ISO 8601 date format to time modifier, as it is now widely supported in PPL * Update syntax by reusing SPANLENGTH definition * Update explain IT for search with time modifier * Add integration tests for time modifiers * Parse timestamp string with multiple parsers in a loop * Remove opensearch test dependency from core module * Fix unit tests * Minor updates to explain limitations in search doc --------- (cherry picked from commit e468513) Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
* main-apple: (218 commits) Add ignorePrometheus Flag for integTest and docTest (opensearch-project#4442) Create fab-radar.yml PPL `fillnull` command enhancement (opensearch-project#4421) reverting to _doc + _id (opensearch-project#4435) Support `multisearch` command in calcite (opensearch-project#4332) Add 3.3 release notes (opensearch-project#4422) (opensearch-project#4423) [SQL/PPL] Fix the `count(*)` and `dc(field)` to be capped at MAX_INTEGER opensearch-project#4416 (opensearch-project#4418) Change the default search sort tiebreaker to `_shard_doc` for PIT search (opensearch-project#4378) [Enhancement] Add error handling for known limitation of sql `JOIN` (opensearch-project#4344) Bugfix: SQL type mapping for legacy JDBC output (opensearch-project#3613) Version bump: 3.3 (opensearch-project#4417) Add max/min eval functions (opensearch-project#4333) Support time modifiers in search command (opensearch-project#4224) Fix numbered token bug and make it optional output in patterns command (opensearch-project#4402) refactor span (opensearch-project#4334) Move release notes categories (opensearch-project#3818) [Doc] Enable doctest with Calcite (opensearch-project#4379) Mod function should return decimal instead of float when handle the operands are decimal literal (opensearch-project#4407) Scale of decimal literal should always be positive in Calcite (opensearch-project#4401) Enable Calcite by default and implicit fallback the unsupported commands (opensearch-project#4372) ...
Description
Support time modifier in search command.
Examples:
Queries with earliest and latest time modifiers will be converted to a query string query with comparison conditions on the implicit timestamp field
@timestamp
. For example, querysource=time_test earliest=-1year latest='-50d@w3'
is converted to the following DSL:Work items
2012-10-10
now
,-30m
,-2h@h
,@w0
-mon@mon+7d
1
(UTC January 1, 1970 at 12:00:01 AM)Related Issues
Resolves #4135
Implementation Walk-through
Implementation Details
The core functionality is implemented in the
visitTimeModifierValue
andvisitTimeModifierExpression
methods in AstExpressionBuilder.java:visitTimeModifierValue
: Converts time values to OpenSearch date math expressionsvisitTimeModifierExpression
: Creates comparison conditions for@timestamp
field in query stringThe PR extends DateTimeUtils.java with the parseRelativeTime method, which transforms PPL time expressions to OpenSearch date math expressions.
Time modifiers are converted to search comparisons with a query string on the implicit
@timestamp
field, which is now defined as a constant in OpenSearchConstants.java. For example,search earliest=-10days@month latest=now()
is converted to a query string query like the following:PPL Time Modifiers to OpenSearch Date Math Examples
Absolute Times
Relative Times
Snapping to Time Units (Using @)
Week Days
Special Cases
Limitations
Currently, the following formats has to be quoted:
-1day@month+1h
or+1year-4day
Check List
--signoff
or-s
.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.