Skip to content

Conversation

@kotharironak
Copy link
Contributor

@kotharironak kotharironak commented Feb 11, 2021

Description

This PR addresses a gap for the handling of searching entities for not matching labels for array type field attributes.labels
Currently, we have support for searching entities for matching labels, but we need similar capabilities to search entities for not matching labels.

Currently, filtering entities for matching labels attributes.labels IN (<val1> , <val2>) is translated to attributes.labels = <val1> OR attributes.labels = <val2> This PR adds support for attributes.labels NOT_IN ( , )by translating it intoattributes.labels != AND attributes.labels != `

Testing

  • added unit tests
  • verified locally running MongoDB with the following data and query

Data:

db.mytest.insertOne(
   { item: "canvas", qty: 100, attributes: {labels: { valueList : {"values":[{"value":{"string":"attr-v1"}},{"value":{"string":"attr-v2"}},{"value":{"string":"attr-v3"}}]}} }}
)

db.mytest.insertOne(
   { item: "canvas", qty: 100, attributes: {labels: { valueList : {"values":[{"value":{"string":"attr-v01"}},{"value":{"string":"attr-v02"}},{"value":{"string":"attr-v03"}}]}} }}
)

db.mytest.insertOne(
   { item: "canvas", qty: 100, attributes: {labels: { valueList : {"values":[{"value":{"string":"attr-v01"}},{"value":{"string":"attr-v2"}},{"value":{"string":"attr-v4"}}]}} }}
)

db.mytest.insertOne(
   { item: "canvas", qty: 100, attributes: {labels: { valueList : {"values":[{"value":{"string":"attr-b1"}},{"value":{"string":"attr-b2"}},{"value":{"string":"attr-b4"}}]}} }}
)

Query:

db.mytest.find( { $and: [ {'attributes.labels.valueList.values': { $ne: {"value":{"string":"attr-b1"}}}}, {'attributes.labels.valueList.values': { $ne: {"value":{"string":"attr-v4"}}}}] } )

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

Documentation

None

Note

We have a ticket for adding NOT_IN filter support in docstore interface - hypertrace/document-store#32

@codecov
Copy link

codecov bot commented Feb 11, 2021

Codecov Report

Merging #83 (3fc02c2) into main (a6b8de8) will increase coverage by 0.41%.
The diff coverage is 96.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main      #83      +/-   ##
============================================
+ Coverage     57.38%   57.80%   +0.41%     
- Complexity      240      249       +9     
============================================
  Files            36       36              
  Lines          2619     2645      +26     
  Branches        352      354       +2     
============================================
+ Hits           1503     1529      +26     
  Misses          954      954              
  Partials        162      162              
Flag Coverage Δ Complexity Δ
integration 57.80% <96.66%> (+0.41%) 0.00 <4.00> (ø)
unit 37.96% <96.66%> (+0.63%) 0.00 <4.00> (ø)

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

Impacted Files Coverage Δ Complexity Δ
...ertrace/entity/service/util/DocStoreConverter.java 86.86% <96.66%> (+1.98%) 62.00 <4.00> (+9.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 a6b8de8...3fc02c2. Read the comment docs.

@github-actions

This comment has been minimized.

avinashkolluru
avinashkolluru previously approved these changes Feb 11, 2021
Copy link
Contributor

@avinashkolluru avinashkolluru left a comment

Choose a reason for hiding this comment

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

Looks fine. But is there no integration test for this?

@avinashkolluru
Copy link
Contributor

avinashkolluru commented Feb 11, 2021

@kotharironak
Does this return documents that dont even have the attributes.labels field?
Thats why I feel an integration test will be helpful.

@kotharironak
Copy link
Contributor Author

Looks fine. But is there no integration test for this?

Yes. there is no integration test, but we can add. Let me do that.

@github-actions

This comment has been minimized.


Filter exists = new Filter();
exists.setFieldName(fieldName);
exists.setOp(Op.EXISTS);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not exactly sure whether we need Exists or Not Exists here. Won't we want to return all the entities which do not have this field?

Here we are doing labels NOT IN [A, B]

  • Do we only want to return entities which has labels but does not have A or B
  • Or, do we also want to return entities where labels does not exist as well?

Choose a reason for hiding this comment

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

I would think #2.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kotharironak In that case, we need to do "NOT_EXISTS OR the other filter"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skjindal93 Can you check this integration test - testNotInFilterForMatchingLabelsQuery? It has 5 documents. One doesn't have attributes.labels fields. Is it expected in the result?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check this integration test - testNotInFilterForMatchingLabelsQuery? It has 5 documents. One doesn't have attributes.labels fields. Is it expected in the result?

Yeah, createdEntity5 is expected in the result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skjindal93 I have added some more integration tests for NOT_IN, IN, and EQ - testDifferentFilterForMatchingLabelsQuery

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes @kotharironak That entity is expected in the result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the changes. @avinashkolluru @skjindal93, now it's good to go. Have a look.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@kotharironak
Copy link
Contributor Author

@kotharironak
Does this return documents that dont even have the attributes.labels field?
Thats why I feel an integration test will be helpful.

@avinashkolluru What is expected behavior here? The current implementation doesn't return. Check the test case testDifferentFilterForMatchingLabelsQuery, and it has one extra entity w/o having attributes.lables fields. Let me know the expected behavior, and accordingly, we can change.

@github-actions

This comment has been minimized.

.build();
entitiesList = entityDataServiceClient.query(TENANT_ID, query);
assertTrue(entitiesList.size() == 2);
assertTrue(entitiesList.contains(createdEntity2) && entitiesList.contains(createdEntity2));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a typo here

entitiesList.contains(createdEntity2) && entitiesList.contains(createdEntity2)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be

entitiesList.contains(createdEntity2) && entitiesList.contains(createdEntity5)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Good catch, while debugging, I had checked createdEntity5, but had gone back & forth changing this condition.

@github-actions

This comment has been minimized.

@kotharironak kotharironak merged commit c5eeedb into main Feb 12, 2021
@kotharironak kotharironak deleted the handle-not-in-clause branch February 12, 2021 10:32
@kotharironak kotharironak added enhancement New feature or request fix labels Feb 12, 2021
@github-actions
Copy link

Unit Test Results

  27 files  ±0    27 suites  ±0   24s ⏱️ -2s
118 tests +3  118 ✔️ +3  0 💤 ±0  0 ❌ ±0 

Results for commit c5eeedb. ± Comparison against base commit a6b8de8.

suddendust pushed a commit to suddendust/entity-service that referenced this pull request Sep 5, 2025
* Make the Query DTO equatable/hashable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants