#639: allow metadata fields and score opensearch function (#228)#1456
#639: allow metadata fields and score opensearch function (#228)#1456MaxKsyunz merged 9 commits intoopensearch-project:mainfrom
Conversation
…nction (#228) * Rebase from main Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update to define and include metadata when visiting the expr node Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Add specific metadata identifiers Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Add IT tests and add parser changes Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Rebase from main Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update score function expression analyzer to return boosted relevance function Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update builder to track scores Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Remove ScoreExpression.java and cleanup checkstyle Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * cleanup checkstyle Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Cleanup and add alternative score function syntax Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Cleanup and add alternative score function syntax Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Fix some bugs and add Expression tests Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Add expresssion and analyzer tests Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Add score doctests Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Add score function doctests Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Add metafield tests Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Move legacy test and mark old as ignore Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * fix checkstyle violations Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * fix checkstyle violations Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update tests and identifier to accept metafields Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Checkstyle fixes Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Rebase from main Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Rebase from main Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Rebase from main Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * fix checkstyle violations Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Revert bad conflict resolution Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Fix for review comments Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update IT tests and legacy tests for comments Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Minor comment Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Updates for whitespace Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update basics.rst to show OS result Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update basics.rst to show OS result Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update basics.rst description Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Change Score function to accept a double/integer not an unresolved Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update functions.rst Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Checkstyle update Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Move reserved world symbol table to OpenSearchTable Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Update functions.rst for review comments Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Removed parser meta tokens; Changes ImmutableMap to Map Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> * Removed parser meta tokens; Changes ImmutableMap to Map Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com> --------- Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1456 +/- ##
============================================
+ Coverage 98.46% 98.49% +0.02%
- Complexity 3869 3928 +59
============================================
Files 345 347 +2
Lines 9603 9771 +168
Branches 616 645 +29
============================================
+ Hits 9456 9624 +168
Misses 142 142
Partials 5 5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
MaxKsyunz
left a comment
There was a problem hiding this comment.
@acarbonetto Do metafields work with aliases? E.g. SELECT h._id FROM tableA AS h
Is there a test that confirms this?
Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com>
IT test for this added in f3d89b8 |
core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java
Outdated
Show resolved
Hide resolved
| // Identifiers cannot start with a single '_' since this an OpenSearch reserved | ||
| // metadata field. Two underscores (or more) is acceptable, such as '__field'. |
There was a problem hiding this comment.
Does this comment match the rule below? So ID_LITERAL won't accept token starting with single underscore?
There was a problem hiding this comment.
Good catch! I need to update this comment since I've updated the pattern.
Thank you!
opensearch/src/main/java/org/opensearch/sql/opensearch/response/OpenSearchResponse.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java
Show resolved
Hide resolved
| FetchSourceContext fetchSource = this.sourceBuilder.fetchSource(); | ||
| List<String> includes = fetchSource != null && fetchSource.includes() != null | ||
| ? Arrays.asList(fetchSource.includes()) | ||
| : List.of(); |
There was a problem hiding this comment.
May be do this in the query builder?
There was a problem hiding this comment.
OpenSearchQueryRequest and OpenSearchScrollRequest needs a refactor before this makes any sense.
There was a problem hiding this comment.
Please assist in creating an issue to monitor and manage future modifications.
opensearch/src/main/java/org/opensearch/sql/opensearch/request/OpenSearchScrollRequest.java
Show resolved
Hide resolved
opensearch/src/main/java/org/opensearch/sql/opensearch/response/OpenSearchResponse.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com>
ccdc290
Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com>
…elds and the score OpenSearch function (#228) (opensearch-project#1456) Allow metadata fields and score OpenSearch function. Signed-off-by: Andrew Carbonetto <andrewc@bitquilltech.com>
Description
OpenSearch reserved fields (_id, _index, _sort, _score, _max_score) are not allowed to be used in SQL clauses (SELECT, WHERE, ORDER BY) because the field format starting with underscore _ is not allowed.
This ticket allows for the
score(),score_query()andscorequery()function to be used to wrap around relevance-search queries to force the_scoreand_max_scoremetadata fields to be returned with values. For some queries,_scorereturnsnullunless thescore()function is included.scorefunction also allows for an optionalboostargument to be included that boosts the score of the child relevance function.Example - metadata fields returned:
Example - Metadata fields not requested are not displayed:
Example - relevance search without and with score function
Example - boost score on the _sql/_explain call:
Issues Resolved
__is missing in the returned result when query by SQL with extrafilter#783Check 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.