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

Joins #33

Closed
kennywk opened this issue Nov 12, 2017 · 21 comments
Closed

Joins #33

kennywk opened this issue Nov 12, 2017 · 21 comments
Assignees
Milestone

Comments

@kennywk
Copy link

kennywk commented Nov 12, 2017

Support the ability to join records from other collections providing an output where the selected/join result is the document value.

@anidotnet
Copy link
Contributor

Could you elaborate more about the feature? It would be better if you provide one example to illustrate it.

@kennywk
Copy link
Author

kennywk commented Nov 13, 2017

Sure, for instance in mongo with spring you can use dbref for subdocuments. In spring if you annotate a class with @DBREF it will automatically join that document as a property of the annotated document. So for example:

public class Person{ private String id; private String name; private String addressId; }

public class Address{ private String id; private String street; }

Now obviously this is regarding POJOs however if i do a query to select a document by id, It would be awesome if i could join the address document to the returning document where the address document id is equal to the addressId field.

Another example could be that if i have 3 documents that represent portions of an object but in a very normalized way.

public class Point{ public String id; }

public class AbsolutePoint extends Point{ public String id; public Double distance; }

public class GeographicalPoint extends AbsolutePoint{ public String id; public Double latitude; public Double longitude;

It would be awesome if i could create a aggregated document where i can query the three stores/tables by id and create a single result that includes the fields/attributes from the three source documents where the id matches.

@anidotnet
Copy link
Contributor

By design I decided not to include aggregation in an embedded database. The detailed reason I described here in issue #24 . If you are asking for something else and I did not understand it, please let me know.

@kennywk
Copy link
Author

kennywk commented Nov 13, 2017 via email

@anidotnet
Copy link
Contributor

anidotnet commented Nov 13, 2017

Does projection serve your purpose? - http://www.dizitart.org/nitrite-database/doc/2.0.0/index.html#projection
Or, are you looking for something similar to lookup operation in mongo?

@kennywk
Copy link
Author

kennywk commented Nov 13, 2017 via email

@anidotnet
Copy link
Contributor

It does look like you are thinking something similar to lookup operation in mongo. So if I understand correctly, if you have 2 repositories like Address, Person

public class Address {
      private String id;
      private String personId;
      private String streetAddress;
}

public class Person {
    private String id;
    private String name;
}

public class PersonDetails {
    private String id;
    private String name;
    private List<Address> addressList;
}

you want to get a result of type PersonDetails where person.id = address.personId

@kennywk
Copy link
Author

kennywk commented Nov 13, 2017 via email

@anidotnet
Copy link
Contributor

Just out of curiosity, what is stopping you to create a repository of PersonDetails in the first place and get the Person and Address objects out of it using projection? Unlike sql databases, here you can persists embedded object directly to the database.

@kennywk
Copy link
Author

kennywk commented Nov 13, 2017 via email

@anidotnet
Copy link
Contributor

Interesting use case. If the idea of look up helps you, I'll try to add the feature

@anidotnet anidotnet self-assigned this Nov 13, 2017
@anidotnet anidotnet added this to the 2.0.2 milestone Nov 13, 2017
@kennywk
Copy link
Author

kennywk commented Nov 13, 2017 via email

@anidotnet
Copy link
Contributor

I have come up with a basic design as follows:

Lookup lookup = new Lookup();
lookup.localField = "id";
lookup.foreignField = "personId";
lookup.targetField = "addressList";

Cursor cursor = collection1.find().join(collection2.find(), lookup); // for documents
Cursor<PersonDetails> cursor = repo1.find().join(repo2.find(), lookup); // for objects

Let me know your thoughts

@kennywk
Copy link
Author

kennywk commented Nov 13, 2017 via email

@anidotnet
Copy link
Contributor

I am not inclined to introducing builder patterns right now, as other constructs like query, projection does not have any corresponding builders yet. May be later when I introduce builders for other constructs, I'll definitely add one for it. But for the first step I want to keep it as simple as possible.

@kennywk
Copy link
Author

kennywk commented Nov 13, 2017 via email

anidotnet added a commit that referenced this issue Nov 14, 2017
@anidotnet
Copy link
Contributor

I have made a commit on master. Please build it locally and test. Let me know if it serves your purpose. Once confirmed, I'll do a release, then you will be able to refer it from maven central.

@kennywk
Copy link
Author

kennywk commented Nov 14, 2017 via email

@anidotnet
Copy link
Contributor

Let me know the outcome so I can close this issue.

@kennywk
Copy link
Author

kennywk commented Nov 16, 2017 via email

@anidotnet
Copy link
Contributor

Thanks for confirmation. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants