GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp

Flatten closed-interface projection with nested entities

Open
#2,406 0 comments 0 reactions 0 assignees View on GitHub
datastore priority: p2 type: enhancement
Dominant language
Java
Stars
551
Forks
349
Avg merge
1d 13h
Merged PRs (30d)
14

Description

**Is your feature request related to a problem? Please describe.**

Subsequent ticket for https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/2387.

When I use a projection to get nested entity with closed-interface, I expect spring-cloud-gcp-data to query specified fields only through the interface in the closed-interface.

For example)

if `LightCat.java` has
```
package com.example.projectiontest.models;

import java.time.Instant;

public interface LightCat {
Long getId();

String getName();
Breed getBreed();

Person getOwner();

Instant getFound();

interface Person {
String getName();
}
}
```

Currently, when I check `PartTreeDatastoreQuery.java`'s `getEntityOrProjectionQueryBuilder()`, it queries projection with the following fields: `id, name, breed, owner, found`

I expect the query to get `id, name, breed, owner.name, found`.

**Describe alternatives you've considered**
Having Datastore Converter for converting between `Person` and `String` would make it work, but if the `Person` object is complicated, it will have some overheads for collecting all data.

**Additional context**
Sample repository: https://github.com/k8kim/spring-gcp-data-projection-demo
Spring cloud gcp version: 4.8.3
Spring cloud version: 2022.0.4

In the repository, there is a rest controller (CatController.java), datastore repository (CatRepository), and some entities (Cat.java, LightCat.java, Person.java). LightCat is an interface for projecting Cat object.

The rest controller contains 4 endpoints, but the ones that are related here are:

{POST} /cats : add a cat with name and ownerName from request parameters and some default values.
{GET} /cats: returns a list of Cats in the datastore
{GET} /light-cats: returns a list of LightCats in the datastore

Contributor guide

Open the contributing guide

Research direction

Start in PartTreeDatastoreQuery.java at getEntityOrProjectionQueryBuilder() and reproduce the LightCat projection using the sample repository's CatController and related entities. Verify the /light-cats endpoint and datastore query behavior; done means nested closed-interface fields such as owner.name are selected instead of the whole nested entity.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.