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

Preserve identity of records and other structural values #363

Open
sanjiva opened this issue Oct 14, 2019 · 9 comments
Open

Preserve identity of records and other structural values #363

sanjiva opened this issue Oct 14, 2019 · 9 comments
Labels
design/usability Design does not work well for some tasks lang Relates to the Ballerina language specification

Comments

@sanjiva
Copy link
Contributor

sanjiva commented Oct 14, 2019

Suppose I have:

type Class record { string name; }
type Student record { Class class; int name; }

And assume that multiple Student records values refer the same Class. (I need to model it this way because I can't create the whole class at once - I create it and then add students to it. (See https://github.com/sanjiva/Staffing/blob/master/src/services/types.bal for a real example.)

The above record can't be json'ed as-is.

We need some way to represent references across records in a network transportable way.

@sanjiva
Copy link
Contributor Author

sanjiva commented Oct 14, 2019

Note that this is similar to what is needed to persist such a structure into a relational system. JPA etc. address this issue with various kinds of relationship annotations. For example, see: https://www.javatpoint.com/jpa-creating-an-entity.

@jclark jclark changed the title Make records easier to transmit as network entities Maintain identity of records and other structural values Oct 15, 2019
@jclark
Copy link
Collaborator

jclark commented Oct 15, 2019

More precisely, if you convert that structure to a string in JSON format and then parse that string back into a structure, your graph structure will have been turned into tree: the identity (===-ness) of the class values has not been preserved.

@jclark jclark changed the title Maintain identity of records and other structural values Preserve identity of records and other structural values Oct 15, 2019
@jclark
Copy link
Collaborator

jclark commented Oct 15, 2019

This relates to #338. We do not want to preserve the identity of all records: only those that represent "entities". For example, in the linked example Date is not an entity. But the language does not have a built-in way of distinguishing the records which have an identity. You have to do it yourself by e.g. putting in a uuid field.

@jclark
Copy link
Collaborator

jclark commented Oct 15, 2019

This also relates to #354. One big issue is primary keys, which are in effect a mechanism to give records an identity within a particular context.

@jclark
Copy link
Collaborator

jclark commented Oct 15, 2019

This also relates to #159, since BVN should provide a way to maintain graph structure of anydata.

@jclark jclark added lang Relates to the Ballerina language specification design/usability Design does not work well for some tasks labels Oct 15, 2019
@jclark
Copy link
Collaborator

jclark commented Oct 15, 2019

We can provide a layer on top of JSON to allow graph structure to be preserved by using:

@jclark
Copy link
Collaborator

jclark commented Oct 15, 2019

YAML's data model is a graph, so that might be another way to allow graph structure to be preserved.

@jclark
Copy link
Collaborator

jclark commented Oct 15, 2019

We should look at JDO and also at ODMG ODL (which JDO developed from). I think we may well need something like the extent concept.

@sanjiva
Copy link
Contributor Author

sanjiva commented Oct 15, 2019

I think the key comment you've made is the one about entities vs. records. Not all records are entities, that is, records which need to have identity on their own right (which is what #338) is about.

Once we can distinguish between them we need to address how to map entities to JSON / YAML / SQL Tables etc..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design/usability Design does not work well for some tasks lang Relates to the Ballerina language specification
Projects
None yet
Development

No branches or pull requests

2 participants