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

Adding Match Query Unit Tests #56

Merged
merged 6 commits into from
May 18, 2022

Conversation

forestmvey
Copy link

Description

Add unit tests for match function implementation with 100% code coverage.

Check List

  • New functionality includes testing.
  • All tests pass, including unit test, integration test and doctest
  • 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.

@forestmvey forestmvey requested a review from a team May 16, 2022 17:22
@codecov
Copy link

codecov bot commented May 16, 2022

Codecov Report

Merging #56 (4fa2578) into integ-match_query_unit_tests (a7d4395) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@                       Coverage Diff                       @@
##             integ-match_query_unit_tests      #56   +/-   ##
===============================================================
  Coverage                           97.67%   97.67%           
- Complexity                           2743     2744    +1     
===============================================================
  Files                                 266      266           
  Lines                                6797     6799    +2     
  Branches                              433      433           
===============================================================
+ Hits                                 6639     6641    +2     
  Misses                                157      157           
  Partials                                1        1           
Flag Coverage Δ
sql-engine 97.67% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...age/script/filter/lucene/relevance/MatchQuery.java 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a7d4395...4fa2578. Read the comment docs.

…ng exceptions and moved private method definition placement below public methods

Signed-off-by: forestmvey <[email protected]>
@MaxKsyunz
Copy link

MaxKsyunz commented May 16, 2022

@forestmvey, opensearch/@src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchQueryTest.java:201 now fails stylecheck :(

… Fixed checkstyle syntax errors.

Signed-off-by: forestmvey <[email protected]>
@@ -31,6 +33,82 @@ public class MatchQueryTest {
private final MatchQuery matchQuery = new MatchQuery();
private final FunctionName match = FunctionName.of("match");

static Stream<List<Expression>> generateValidData() {
final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository());
return Stream.of(

Choose a reason for hiding this comment

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

Looks good to me.

Another option is to take the list of valid args and build the stream of test cases from it.

Something like:

NamedArgument field = dsl.namedArgument("field", DSL.literal("field_value"));
NamedArgument query = dsl.namedArgument("query", DSL.literal("query_value"));
return List.of(
        dsl.namedArgument("analyzer", "standard"),
        dsl.namedArgument("auto_generate_synonyms_phrase_query", "true"),
        dsl.namedArgument("fuzziness", "AUTO"),
        dsl.namedArgument("max_expansions", "50"),
        dsl.namedArgument("prefix_length", "0"),
        dsl.namedArgument("fuzzy_transpositions", "true"),
        dsl.namedArgument("fuzzy_rewrite", "constant_score"),
        dsl.namedArgument("lenient", "false"),
        dsl.namedArgument("operator", "OR"),
        dsl.namedArgument("minimum_should_match", "3"),
        dsl.namedArgument("zero_terms_query", "NONE"),
        dsl.namedArgument("boost", "1"))
            .stream().map(arg -> List.of(field, query, arg));

build_succeeds_with_two_arguments would need to be kept.

return Stream.of(
List.of(
dsl.namedArgument("field", DSL.literal("field_value")),
dsl.namedArgument("query", DSL.literal("query_value"))

Choose a reason for hiding this comment

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

you could create

NamedArgument fieldArgument = dsl.namedArgument("field", DSL.literal("field_value"));
NamedArgument queryArgument = dsl.namedArgument("query", DSL.literal("query_value"));

once and pass it to all these lists. If you make it static and global to the class, you can use it in other tests ;)

@forestmvey forestmvey merged commit d2184f8 into integ-match_query_unit_tests May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants