Is this a right way to get data that is joined via many different tables in Datastore?

62 views
Skip to first unread message

Hung Ha

unread,
Jan 19, 2016, 2:30:35 AM1/19/16
to Google App Engine

ok, let see this table structure in Datastore:

Structure Table
StructureNo StructureName
1           Structure1
2           Structure2


Line Table
LineNo LineName StructureNo
1      Line1    1
2      Line2    1
3      Line3    2

Let say we want to show all the Lines with their structures as the following:

LineNo LineName StructureNo StructureName
1      Line1    1           Structurre1
2      Line2    1           Structurre1
3      Line3    2           Structurre2

Google said that we can't do the Join, then what is the professional way to get data?

So, we first

filter all lines in Line Table
//put StructureNo into a structureNoList<Integer>
//then filter all structures in Structure Table that have structureNo in the  structureNoList<Integer>
//then assemble line and structure data via Java list

Is this a right way to get data that is joined via many different tables in Datastore?

Nick

unread,
Jan 19, 2016, 3:28:12 PM1/19/16
to Google App Engine
Yes, manually reassembling objects like this is how you create objects which are spread across entities.

There are other approaches though, which mean you may not have to do this. Consider storing
A line and line items as a single document, which allows you to read the whole thing in one hit.
Typically you should design a document like this to satisfy your primary use case. If it's read heavy on the top level entity but requires the children too, you should model it that way. If it's write heavy on the children, model the way you described.

If you're comfortable with relational databases, consider using cloudsql.

Hung Ha

unread,
Jan 19, 2016, 8:28:01 PM1/19/16
to Google App Engine
Thank you very much
Reply all
Reply to author
Forward
0 new messages