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

Provide means for accessing reference count without actually fetching the entities #650

Closed
novoj opened this issue Aug 20, 2024 · 11 comments · Fixed by #822
Closed

Provide means for accessing reference count without actually fetching the entities #650

novoj opened this issue Aug 20, 2024 · 11 comments · Fixed by #822
Assignees
Labels
breaking change Backward incompatible data model change enhancement New feature or request
Milestone

Comments

@novoj
Copy link
Collaborator

novoj commented Aug 20, 2024

After recent discussion with FE team using evitaDB, there may be use case were we want to fetch entity that has existing referenced entities of some type. On top of that however, we want to fetch count of these referenced entities without actually fetching the entities.
Something like that:

{
  listGroup(
    filterBy: {
      attributeCodeEquals: "news-group"
      referenceProductsHaving: {}
    }
  ) {
    productsCount # generated from reference `products`
  }
}

I think it could be solved also with facet summary, probably like this:

{
  queryGroup(
    filterBy: {
      attributeCodeEquals: "news-group"
      referenceProductsHaving: {}
    }
  ) {
    extraResults {
      facetSummary {
        products {
          count
        }
      }
    }
  }
}

But that's quite cumbersome to use on FE. @novoj do you think it would be valid to support the first approach at the GraphQL API level? We could also reuse the filterBy clause from the reference fields. On the backend it could be translated to basic referenceContent.


I think we could automatically provide the count attribute on EntityDecorator level. evitaDB internally always needs to compute reference primary keys to calculate the count, so we could always provide the array of these primary keys (since they have to be fetched anyway). But on the API level the primary keys can easily be thrown away and only the count could be provided to the external clients, thus saving some transport/networking costs.

@novoj novoj added the enhancement New feature or request label Aug 20, 2024
@novoj novoj added this to the Beta milestone Aug 20, 2024
@novoj novoj self-assigned this Aug 20, 2024
@novoj
Copy link
Collaborator Author

novoj commented Aug 21, 2024

This feature request partially opens up a path to a larger extension of the reference fetching enhancements. It would be also beneficial to be able to fetch only chunks of references. After discussion with @lukashornych we'd like to:

  1. be able to avoid sending all the referenced PKs over the wire in all of the protocols - this could be easily achieved by requesting zero records in the output using (page(1,0) or strip(0,0))
  2. be able to paginate the fetched references
  3. combine both above requirements with ordering and filtering constraints

In order to do so, this language extension makes sense to us:

// returns only counts for product reference (no PKs or bodies are sent)
referenceCount('products')
// returns only counts for all entity references (no PKs or bodies are sent)
referenceCount()
// returns only counts for product reference that match filtering criteria in a custom order (no PKs or bodies are sent)
referenceCount('products', filterBy(...), orderBy(...))
// returns first page of 20 primary keys that match filtering criteria in a custom order
referenceContent('products', filterBy(...), orderBy(...), page(1, 20))
// returns first page of 20 referenced entities that match filtering criteria in a custom order
referenceContent('products', filterBy(...), orderBy(...), entityFetchAll(), page(1, 20))

We still need to analyze how this proposal affects the internal structure of EntityDecorator and the connected APIs. This change would also affect all the APIs at once and would cover all our requirements.

@novoj novoj removed this from the Beta milestone Feb 7, 2025
@novoj novoj added this to the 2025.2 milestone Feb 17, 2025
@novoj
Copy link
Collaborator Author

novoj commented Feb 17, 2025

This issue will focus solely on referenced content. Pagination support in facet summary was moved to separate issue: #812

novoj added a commit that referenced this issue Feb 18, 2025
…tching the entities

Extended parser, QueryConstraints and the constraint itself to accommodate paging child and its serialization.

Refs: #650
novoj added a commit that referenced this issue Feb 18, 2025
@novoj
Copy link
Collaborator Author

novoj commented Feb 18, 2025

Server side implementation except API integration done. @lukashornych please see usage patterns in tests:

  • io.evitadb.api.EntityFetchingFunctionalTest#shouldPaginateReferences
  • io.evitadb.api.EntityFetchingFunctionalTest#shouldStrippedReferences
  • io.evitadb.api.EntityFetchingFunctionalTest#shouldCombinePaginatedAndStrippedReferences

Client (gRPC/Java) will follow next.

novoj added a commit that referenced this issue Feb 18, 2025
…tching the entities

Server side implementation done with tests.

Refs: #650
novoj added a commit that referenced this issue Feb 18, 2025
…tching the entities

Server side implementation done with tests.

Refs: #650
novoj added a commit that referenced this issue Feb 19, 2025
…tching the entities

Client side implementation done with tests.

Refs: #650
novoj added a commit that referenced this issue Feb 19, 2025
…tching the entities

Fix for providing total count only.

Refs: #650
novoj added a commit that referenced this issue Feb 19, 2025
…ching the entities

Added documentation (so far not tested).

Refs: #650
novoj added a commit that referenced this issue Feb 20, 2025
…tching the entities

Fixed problem when there are multiple entities in the result with slicing that needs to respect individual references of particular entities. Reference fetching was also optimized to avoid unnecessary bitmap unwrapping and rewrapping.

Refs: #650
novoj added a commit that referenced this issue Feb 20, 2025
novoj added a commit that referenced this issue Feb 20, 2025
novoj added a commit that referenced this issue Feb 24, 2025
Fixed problem and added tests that verify that it's possible to exchange chunks during entity enrichment.

Refs: #650
novoj added a commit that referenced this issue Feb 24, 2025
When entity is enriched and doesn't redefine locales, it should inherit original locale.

Refs: #650
lukashornych added a commit that referenced this issue Feb 26, 2025
lukashornych added a commit that referenced this issue Feb 26, 2025
@novoj
Copy link
Collaborator Author

novoj commented Feb 27, 2025

  • add support for spacing inside pagination in reference content

lukashornych added a commit that referenced this issue Feb 27, 2025
@lukashornych
Copy link
Collaborator

@novoj Shouldn't the lastPageNumber be 1 in this case?

Image

@novoj
Copy link
Collaborator Author

novoj commented Feb 28, 2025

Why do you think so? When pageSize is zero, how many pages would you have for 17 records? Infinite. But we cannot pass infinite value, so better is zero or -1 (as non-possible value). I chose zero. But let's discuss.

@lukashornych
Copy link
Collaborator

Yeah, you are right, that does make sense. I was coming from the pageNumber: 1, but that's from a request, so it makes sense it is 1 and not 0.

@lukashornych
Copy link
Collaborator

@novoj GQL and REST API are completely done (API logic, int. tests, user docs).

But I think you will need to implement some printing logic for referenceContentPageEmpty.evitaql.json.md, right now, it doesn't print references at all.

@lukashornych lukashornych removed their assignment Feb 28, 2025
@novoj
Copy link
Collaborator Author

novoj commented Feb 28, 2025

Spacing support finalized, however there are still some tests failing.

novoj added a commit that referenced this issue Mar 5, 2025
Still some tests are not passing. Corrected issue with duplicated groups in array during sorting and swapped arguments in OffsetAndLimit that led to invalid last page number.

Refs: #650
novoj added a commit that referenced this issue Mar 5, 2025
novoj added a commit that referenced this issue Mar 6, 2025
@lukashornych lukashornych added the breaking change Backward incompatible data model change label Mar 6, 2025
lukashornych added a commit that referenced this issue Mar 6, 2025
…ying label headers, missing CORS headers

BREAKING-CHANGE: REST API no longer support HTTP header `X-EvitaDB-Query-Label` for specifying query headers. Instead use `X-EvitaDB-Label`.

Refs: #650
novoj added a commit that referenced this issue Mar 6, 2025
lukashornych added a commit that referenced this issue Mar 6, 2025
lukashornych added a commit that referenced this issue Mar 6, 2025
@lukashornych
Copy link
Collaborator

@novoj All tests seems to be working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Backward incompatible data model change enhancement New feature or request
Projects
None yet
2 participants