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 Support for Nested Function Use In WHERE Clause Predicate Expresion #1657

Conversation

forestmvey
Copy link
Collaborator

Description

Syntax: nested( [field] | [field,path] )

Add support for use of the nested function in the WHERE clause as a predicate expression. Supports nested function on left of operator, and literal on right. When using nested function in WHERE clause, the inner hits of the query are not added to the nested query DSL. To do this you must use the nested function in conjunction with a SELECT clause nested function call. See documentation for this nested implementation HERE (WIP).

Example Queries

SELECT message.info FROM nested_objects WHERE nested(message.info, message) = 'a';
SELECT nested(message.info) FROM nested_objects WHERE nested(message.info, message) = 'a';
SELECT message.info FROM nested_objects WHERE nested(message.info) = 'a' OR nested(comment.data) = 'b' AND nested(message.dayOfWeek) = 4;

Issues Resolved

Issue: 1111

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.

@codecov
Copy link

codecov bot commented May 25, 2023

Codecov Report

Merging #1657 (5dc02e0) into main (9824b1c) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 5dc02e0 differs from pull request most recent head eb48a0a. Consider uploading reports for the commit eb48a0a to get more accurate results

@@             Coverage Diff              @@
##               main    #1657      +/-   ##
============================================
+ Coverage     97.16%   97.18%   +0.01%     
- Complexity     4120     4150      +30     
============================================
  Files           371      372       +1     
  Lines         10373    10429      +56     
  Branches        704      716      +12     
============================================
+ Hits          10079    10135      +56     
  Misses          287      287              
  Partials          7        7              
Flag Coverage Δ
sql-engine 97.18% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...ain/java/org/opensearch/sql/analysis/Analyzer.java 100.00% <ø> (ø)
...l/opensearch/request/OpenSearchRequestBuilder.java 100.00% <100.00%> (ø)
...arch/storage/script/filter/FilterQueryBuilder.java 100.00% <100.00%> (ø)
...search/storage/script/filter/lucene/LikeQuery.java 100.00% <100.00%> (ø)
...arch/storage/script/filter/lucene/LuceneQuery.java 100.00% <100.00%> (ø)
...arch/storage/script/filter/lucene/NestedQuery.java 100.00% <100.00%> (ø)
...java/org/opensearch/sql/sql/parser/AstBuilder.java 100.00% <100.00%> (ø)

BuiltinFunctionName.NESTED.name()
)) {
throw new SyntaxCheckException(
"Falling back to legacy engine. Nested function is not supported in the HAVING clause."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? HAVING implemented the same way as WHERE

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure I understand your question, but I implemented the fallback mechanism in AstBuilder to allow for a fallback specific to the nested function used in the HAVING clause. The old fallback mechanism could not determine between clauses for the filter, and we now support nested in the WHERE clause and not the HAVING so we need to differentiate between nested used in each.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if you remove this check, nested would be automatically supported in HAVING, so why not? Less complexity, more functionality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, may just work as is, though group by is not supported for nested yet. Will need to verify and add tests though, if it fits in the timeline maybe we can support in this release.

Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
@forestmvey forestmvey force-pushed the integ-nested-where-clause-predicate-expression branch from 5dc02e0 to eb48a0a Compare May 30, 2023 16:50
@acarbonetto acarbonetto merged commit 6d796ee into opensearch-project:main May 30, 2023
15 checks passed
@acarbonetto acarbonetto deleted the integ-nested-where-clause-predicate-expression branch May 30, 2023 17:59
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 30, 2023
…on (#1657)

* Adding support for nested function used in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

* Add support for LIKE with nested query in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

---------

Signed-off-by: forestmvey <forestv@bitquilltech.com>
(cherry picked from commit 6d796ee)
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 30, 2023
…on (#1657)

* Adding support for nested function used in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

* Add support for LIKE with nested query in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

---------

Signed-off-by: forestmvey <forestv@bitquilltech.com>
(cherry picked from commit 6d796ee)
forestmvey added a commit that referenced this pull request May 30, 2023
…on (#1657)

Signed-off-by: forestmvey <forestv@bitquilltech.com>
forestmvey added a commit that referenced this pull request May 30, 2023
…on (#1657)

Signed-off-by: forestmvey <forestv@bitquilltech.com>
acarbonetto pushed a commit that referenced this pull request May 30, 2023
…on (#1657) (#1672)

Signed-off-by: forestmvey <forestv@bitquilltech.com>
Co-authored-by: forestmvey <forestv@bitquilltech.com>
acarbonetto pushed a commit that referenced this pull request May 30, 2023
…on (#1657) (#1673)

Signed-off-by: forestmvey <forestv@bitquilltech.com>
Co-authored-by: forestmvey <forestv@bitquilltech.com>
@Yury-Fridlyand Yury-Fridlyand mentioned this pull request May 30, 2023
6 tasks
MitchellGale pushed a commit to Bit-Quill/opensearch-project-sql that referenced this pull request Jun 12, 2023
…on (opensearch-project#1657)

* Adding support for nested function used in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

* Add support for LIKE with nested query in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

---------

Signed-off-by: forestmvey <forestv@bitquilltech.com>
MitchellGale pushed a commit to Bit-Quill/opensearch-project-sql that referenced this pull request Jun 12, 2023
…on (opensearch-project#1657)

* Adding support for nested function used in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

* Add support for LIKE with nested query in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

---------

Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>
MitchellGale pushed a commit to Bit-Quill/opensearch-project-sql that referenced this pull request Jun 12, 2023
…on (opensearch-project#1657)

* Adding support for nested function used in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

* Add support for LIKE with nested query in predicate expression.

Signed-off-by: forestmvey <forestv@bitquilltech.com>

---------

Signed-off-by: forestmvey <forestv@bitquilltech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants