-
Notifications
You must be signed in to change notification settings - Fork 1
Rlookup
Relational functions rlookup
- rlookup(foreign_key, primary_key)
rlookup(foreign_key, primary_key) results in a relation from the domain unit of the foreign_key argument towards the domain unit of the primary_key argument.
- foreign_key: an attribute which can serve as primary key for the domain unit of the primary_key argument, e.g. a region code.
- primary_key: an attribute which can serve as primary key for its own domain unit and with the same values unit as the foreign_key attribute.
- attributes foreign_key and primary_key with Numeric, Point, uint2, uint4, bool or string value type
We advise that the second argument can be used as primary key for the domain unit of this argument.
If multiple instances of the second argument occur, the resulting value will be the first index number found.
The values unit of the arguments foreign_key and primary_key must match.
O(n + m) where n = size of foreign_key domain and m = size of primary_key domain. Builds an index on primary_key values, then looks up each foreign_key. For sorted integer keys, uses direct indexing; for other types, uses hash-based lookup.
attribute<Region> Region_rel (City) := rlookup(City/RegionCode, Region/RegionCode);
| City/RegionCode | Region_rel |
|---|---|
| 100 | 0 |
| 200 | 1 |
| 300 | 2 |
| 200 | 1 |
| 400 | 3 |
| null | null |
| 400 | 3 |
domain City, nr of rows = 7
| Region/RegionCode |
|---|
| 100 |
| 200 |
| 300 |
| 400 |
| 500 |
domain Region, nr of rows = 5
GeoDMS ©Object Vision BV. Source code distributed under GNU GPL-3. Documentation distributed under CC BY-SA 4.0.