DataLab secondary queries
A secondary query answers "which of these relate to those". Build a selection per Entity Type, pair them with secondary, and add a criterion comparing each candidate against the primary it is being tested against.
The selection you pass in becomes the secondary, and the secondary is what comes back. Swapping which Type is primary and which is secondary changes the answer, not just the wording.
Basics
Primaries are compared in batches, since the join is done per primary. batch sets how many go into each request.
Reading the matches
Read the matches grouped by the primary they belong to, or on their own when it does not matter which primary produced them.
A primary that matched nothing is not reported, so the primary count here can be lower than the number of primaries in the selection. An Entity inside two overlapping primaries is answered once per primary, so walking the matches on their own can repeat it.
Criteria against the primary
Spatial criteria are the common case, but any criterion can compare against the primary by using a Ref as the value. Ref("path", on=Ref.PRIMARY) reads that attribute off the matching primary row, which only means anything in a secondary selection.
Action: Set attribute value
Runs against every matched secondary. The value can be a Ref reading the primary, which is how you copy something across the join without moving the records over the network.
Action: Save match count
Writes how many secondaries each primary matched onto the primary itself.
Action: Relationships
Creates or removes a relationship between each primary and the secondaries it matched, following a Relationship Mapping.
Things worth knowing
Actions here answer with a Pending Action, the same as an ordinary DataLab action. Read the ID with DataLabBuilder.action_id and wait with PendingAction.on_completion.
Batch size is a cost, not a limit. It sets how many primaries are joined per request, so a large batch means fewer, heavier requests. The default suits most selections.
Reading before writing. Queue edits during the walk and apply them afterwards through a ChangeSetBuilder, so the join cannot shift underneath the paging when the change would stop a record matching. The overlapping Entities FAQ works through a full example.