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

Add take() aggregation function in PPL #949

Merged
merged 20 commits into from
Oct 27, 2022

Conversation

joshuali925
Copy link
Member

@joshuali925 joshuali925 commented Oct 21, 2022

Description

take(field) returns some documents of a field per each stats response. It is implemented using top hits metrics aggregation when pushed down to opensearch. In memory it works similar to head command.

A sample use case would be aggregating logs by a category, take allows user to see a sample log per each category: stats take(log_string, 1) by category.

This returns a list of patterns with the count and one sample message.

Currently take only supports text fields. it's not very useful on other types, and array implementation might need to be improved. Support for other types can be extended in the future if needed.

Issues Resolved

Linking issue: opensearch-project/observability#1172

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.

Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
@joshuali925 joshuali925 requested a review from a team as a code owner October 21, 2022 20:38
@joshuali925 joshuali925 self-assigned this Oct 21, 2022

* field: mandatory. The field must be a text field.
* size: optional number. The number of values should be returned. Default is 10.
* from: optional number. The number of values should be skipped. Default is 0.
Copy link
Member Author

Choose a reason for hiding this comment

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

just realized from doesn't make much sense without sort, will remove it for now

@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2022

Codecov Report

Merging #949 (45f7116) into 2.x (0699baa) will decrease coverage by 32.44%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##                2.x     #949       +/-   ##
=============================================
- Coverage     95.21%   62.76%   -32.45%     
=============================================
  Files           313       10      -303     
  Lines          8441      658     -7783     
  Branches        620      119      -501     
=============================================
- Hits           8037      413     -7624     
+ Misses          350      192      -158     
+ Partials         54       53        -1     
Flag Coverage Δ
query-workbench 62.76% <ø> (ø)
sql-engine ?

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

Impacted Files Coverage Δ
...rg/opensearch/sql/analysis/ExpressionAnalyzer.java
...c/main/java/org/opensearch/sql/expression/DSL.java
...sql/expression/aggregation/AggregatorFunction.java
...h/sql/expression/function/BuiltinFunctionName.java
...nsearch/data/value/OpenSearchExprValueFactory.java
...ript/aggregation/dsl/MetricAggregationBuilder.java
...pensearch/sql/ppl/parser/AstExpressionBuilder.java
...search/sql/planner/optimizer/pattern/Patterns.java
...ript/aggregation/dsl/BucketAggregationBuilder.java
...ensearch/sql/ppl/utils/PPLQueryDataAnonymizer.java
... and 293 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Joshua Li <joshuali925@gmail.com>
@joshuali925 joshuali925 added the v2.4.0 'Issues and PRs related to version v2.4.0' label Oct 21, 2022
@Yury-Fridlyand
Copy link
Collaborator

Yury-Fridlyand commented Oct 21, 2022

Currently take only supports text fields

Do you have a test for non-text fields?
A test on field which doesn't exit?

@joshuali925
Copy link
Member Author

Currently take only supports text fields

Do you have a test for non-text fields? A test on field which doesn't exit?

That should be responsibilities of function resolver and expression analyzer? i didn't modify those logic, i think UT already covers those. If it happens error will say

take function expected {[STRING,INTEGER]}, but get [LONG,INTEGER]

or

can't resolve Symbol(namespace=FIELD_NAME, name=nonexist) in type env

Signed-off-by: Joshua Li <joshuali925@gmail.com>

Example::

os> source=accounts | stats take(firstname);
Copy link
Member

Choose a reason for hiding this comment

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

Would you consider adding more examples with groupBy, size and may be patterns if possible?
or add a complex Example which covers all.
will you be including ITs in this PR or other PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

will add one with groupBy and ITs. I don't know if we should put patterns here since this is the stats doc

Copy link
Member Author

Choose a reason for hiding this comment

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

@vamsi-amazon
Copy link
Member

When we push down to OS, what is the default sort applied? Will it be consistent with our in-memory implementation?

@joshuali925
Copy link
Member Author

When we push down to OS, what is the default sort applied? Will it be consistent with our in-memory implementation?

take command doesn't guarantee on order

Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
vamsi-amazon
vamsi-amazon previously approved these changes Oct 26, 2022
Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
@dai-chen dai-chen added the PPL Piped processing language label Oct 27, 2022
@joshuali925 joshuali925 merged commit f37736f into opensearch-project:2.x Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PPL Piped processing language v2.4.0 'Issues and PRs related to version v2.4.0'
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants