Join
|
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
Join( source, target )
join( source, target )
Join( source, target )
Join( source, target )
Join( source, target )
Join( source, target )
Description
The Join function joins the source set’s tuples with the
target. target can be one of:
-
An index Reference.
The
sourceset’s tuples are iterated, and an implicitMatchcall is made for each tuple against thetargetindex’sterms. The union of the results is returned. -
A
Lambdafunction.The
sourceset’s tuples are iterated and passed to the function. The function decides how each tuple should be handled. The union of the results is returned.The
Lambdafunction must be pure: it must not create side effects, such as any additional reads or writes.
In either case, if the source set’s tuples do not match the number and
types of the target, an error occurs.
Examples
-
The following query joins the "spellbooks" documents for a specific owner with the "spells_by_spellbook" index, which reports the spells for each spellbook, answering the question "what spells can this owner cast?":
{ data: [ { ref: Ref(Collection("spells"), "181388642046968320"), ts: 1632781965880000, data: { name: 'Fire Beak', element: [ 'air', 'fire' ], spellbook: Ref(Collection("spellbooks"), "181388642139243008") } }, { ref: Ref(Collection("spells"), "181388642071085568"), ts: 1632781965880000, data: { name: "Water Dragon's Claw", element: [ 'water', 'fire' ], spellbook: Ref(Collection("spellbooks"), "181388642139243008") } } ] }{'data': [{'ref': Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1626225336060000, 'data': {'name': 'Fire Beak', 'element': ['air', 'fire'], 'spellbook': Ref(id=181388642139243008, collection=Ref(id=spellbooks, collection=Ref(id=collections)))}}, {'ref': Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1626225336060000, 'data': {'name': "Water Dragon's Claw", 'element': ['water', 'fire'], 'spellbook': Ref(id=181388642139243008, collection=Ref(id=spellbooks, collection=Ref(id=collections)))}}]}map[data:[map[data:map[element:[air fire] name:Fire Beak spellbook:{181388642139243008 0xc000092780 0xc000092780 <nil>}] ref:{181388642046968320 0xc0000925a0 0xc0000925a0 <nil>} ts:1626225336060000] map[data:map[element:[water fire] name:Water Dragon's Claw spellbook:{181388642139243008 0xc000092b40 0xc000092b40 <nil>}] ref:{181388642071085568 0xc000092960 0xc000092960 <nil>} ts:1626225336060000]]]ObjectV(data: Arr(ObjectV(ref: RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections"))),ts: LongV(1626225336060000),data: ObjectV(name: StringV(Fire Beak),element: Arr(StringV(air), StringV(fire)),spellbook: RefV(id = "181388642139243008", collection = RefV(id = "spellbooks", collection = RefV(id = "collections"))))), ObjectV(ref: RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections"))),ts: LongV(1626225336060000),data: ObjectV(name: StringV(Water Dragon's Claw),element: Arr(StringV(water), StringV(fire)),spellbook: RefV(id = "181388642139243008", collection = RefV(id = "spellbooks", collection = RefV(id = "collections"))))))){data: [{ref: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections"))), ts: 1626225336060000, data: {name: "Fire Beak", element: ["air", "fire"], spellbook: ref(id = "181388642139243008", collection = ref(id = "spellbooks", collection = ref(id = "collections")))}}, {ref: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections"))), ts: 1626225336060000, data: {name: "Water Dragon's Claw", element: ["water", "fire"], spellbook: ref(id = "181388642139243008", collection = ref(id = "spellbooks", collection = ref(id = "collections")))}}]}{ data: [ { ref: Ref(Collection("spells"), "181388642046968320"), ts: 1626225336060000, data: { name: 'Fire Beak', element: [ 'air', 'fire' ], spellbook: Ref(Collection("spellbooks"), "181388642139243008") } }, { ref: Ref(Collection("spells"), "181388642071085568"), ts: 1626225336060000, data: { name: "Water Dragon's Claw", element: [ 'water', 'fire' ], spellbook: Ref(Collection("spellbooks"), "181388642139243008") } } ] } -
The following query joins the "spellbooks" documents for a specific owner with a
Lambdafunction, which performs the equivalent "spells_by_spellbook" lookup as the previous query example:{ data: [ { ref: Ref(Collection("spells"), "181388642046968320"), ts: 1632781965880000, data: { name: 'Fire Beak', element: [ 'air', 'fire' ], spellbook: Ref(Collection("spellbooks"), "181388642139243008") } }, { ref: Ref(Collection("spells"), "181388642071085568"), ts: 1632781965880000, data: { name: "Water Dragon's Claw", element: [ 'water', 'fire' ], spellbook: Ref(Collection("spellbooks"), "181388642139243008") } } ] }{'data': [{'ref': Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1626224127300000, 'data': {'name': 'Fire Beak', 'element': ['air', 'fire'], 'spellbook': Ref(id=181388642139243008, collection=Ref(id=spellbooks, collection=Ref(id=collections)))}}, {'ref': Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1626224127300000, 'data': {'name': "Water Dragon's Claw", 'element': ['water', 'fire'], 'spellbook': Ref(id=181388642139243008, collection=Ref(id=spellbooks, collection=Ref(id=collections)))}}]}map[data:[map[data:map[element:[air fire] name:Fire Beak spellbook:{181388642139243008 0xc000124510 0xc000124510 <nil>}] ref:{181388642046968320 0xc000124330 0xc000124330 <nil>} ts:1626224127300000] map[data:map[element:[water fire] name:Water Dragon's Claw spellbook:{181388642139243008 0xc0001248d0 0xc0001248d0 <nil>}] ref:{181388642071085568 0xc0001246f0 0xc0001246f0 <nil>} ts:1626224127300000]]]ObjectV(data: Arr(ObjectV(ref: RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections"))),ts: LongV(1626224127300000),data: ObjectV(name: StringV(Fire Beak),element: Arr(StringV(air), StringV(fire)),spellbook: RefV(id = "181388642139243008", collection = RefV(id = "spellbooks", collection = RefV(id = "collections"))))), ObjectV(ref: RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections"))),ts: LongV(1626224127300000),data: ObjectV(name: StringV(Water Dragon's Claw),element: Arr(StringV(water), StringV(fire)),spellbook: RefV(id = "181388642139243008", collection = RefV(id = "spellbooks", collection = RefV(id = "collections"))))))){data: [{ref: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections"))), ts: 1626224127300000, data: {name: "Fire Beak", element: ["air", "fire"], spellbook: ref(id = "181388642139243008", collection = ref(id = "spellbooks", collection = ref(id = "collections")))}}, {ref: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections"))), ts: 1626224127300000, data: {name: "Water Dragon's Claw", element: ["water", "fire"], spellbook: ref(id = "181388642139243008", collection = ref(id = "spellbooks", collection = ref(id = "collections")))}}]}{ data: [ { ref: Ref(Collection("spells"), "181388642046968320"), ts: 1626221552780000, data: { name: 'Fire Beak', element: [ 'air', 'fire' ], spellbook: Ref(Collection("spellbooks"), "181388642139243008") } }, { ref: Ref(Collection("spells"), "181388642071085568"), ts: 1626221552780000, data: { name: "Water Dragon's Claw", element: [ 'water', 'fire' ], spellbook: Ref(Collection("spellbooks"), "181388642139243008") } } ] } -
The following query uses the
Lambdavariant ofJointo answer the question "What are the inventory levels for the products in a particular store?".This question cannot be directly answered using the index variant of
Joinbecause the "products_by_store" index returns each product’s name, description, and price, and the "inventory_by_product" index uses only the product’s name in itstermsdefinition (a mismatch in tuple sizes). TheLambdafunction callsMatchwith just thenamevalue to resolve the mismatch:{ data: [ [ 1000, 'Conventional Hass, 4ct bag', Ref(Collection("products"), "204") ], [ 1000, 'Conventional, 1 ct', Ref(Collection("products"), "205") ], [ 100, 'Organic, 1 bunch', Ref(Collection("products"), "208") ], [ 50, 'Organic, 16 oz bag', Ref(Collection("products"), "206") ], [ 30, 'Conventional, 16 oz bag', Ref(Collection("products"), "207") ] ] }{'data': [[1000, 'Conventional Hass, 4ct bag', Ref(id=204, collection=Ref(id=products, collection=Ref(id=collections)))], [1000, 'Conventional, 1 ct', Ref(id=205, collection=Ref(id=products, collection=Ref(id=collections)))], [100, 'Organic, 1 bunch', Ref(id=208, collection=Ref(id=products, collection=Ref(id=collections)))], [50, 'Organic, 16 oz bag', Ref(id=206, collection=Ref(id=products, collection=Ref(id=collections)))], [30, 'Conventional, 16 oz bag', Ref(id=207, collection=Ref(id=products, collection=Ref(id=collections)))]]}map[data:[[1000 Conventional Hass, 4ct bag {204 0xc000182300 0xc000182300 <nil>}] [1000 Conventional, 1 ct {205 0xc0001824b0 0xc0001824b0 <nil>}] [100 Organic, 1 bunch {208 0xc000182660 0xc000182660 <nil>}] [50 Organic, 16 oz bag {206 0xc000182810 0xc000182810 <nil>}] [30 Conventional, 16 oz bag {207 0xc0001829c0 0xc0001829c0 <nil>}]]]ObjectV(data: Arr(Arr(LongV(1000), StringV(Conventional Hass, 4ct bag), RefV(id = "204", collection = RefV(id = "products", collection = RefV(id = "collections")))), Arr(LongV(1000), StringV(Conventional, 1 ct), RefV(id = "205", collection = RefV(id = "products", collection = RefV(id = "collections")))), Arr(LongV(100), StringV(Organic, 1 bunch), RefV(id = "208", collection = RefV(id = "products", collection = RefV(id = "collections")))), Arr(LongV(50), StringV(Organic, 16 oz bag), RefV(id = "206", collection = RefV(id = "products", collection = RefV(id = "collections")))), Arr(LongV(30), StringV(Conventional, 16 oz bag), RefV(id = "207", collection = RefV(id = "products", collection = RefV(id = "collections")))))){data: [[1000, "Conventional Hass, 4ct bag", ref(id = "204", collection = ref(id = "products", collection = ref(id = "collections")))], [1000, "Conventional, 1 ct", ref(id = "205", collection = ref(id = "products", collection = ref(id = "collections")))], [100, "Organic, 1 bunch", ref(id = "208", collection = ref(id = "products", collection = ref(id = "collections")))], [50, "Organic, 16 oz bag", ref(id = "206", collection = ref(id = "products", collection = ref(id = "collections")))], [30, "Conventional, 16 oz bag", ref(id = "207", collection = ref(id = "products", collection = ref(id = "collections")))]]}{ data: [ [ 1000, 'Conventional Hass, 4ct bag', Ref(Collection("products"), "204") ], [ 1000, 'Conventional, 1 ct', Ref(Collection("products"), "205") ], [ 100, 'Organic, 1 bunch', Ref(Collection("products"), "208") ], [ 50, 'Organic, 16 oz bag', Ref(Collection("products"), "206") ], [ 30, 'Conventional, 16 oz bag', Ref(Collection("products"), "207") ] ] }
|
The run time of For query "width" errors, the underlying set or page involves more than
100K items. This can happen when using a set function, such as
For example, instead of:
use:
This does mean that if the entire set must be evaluated to arrive at the
correct result, you would have to page through the For query timeout errors, you may specify a larger query timeout via the driver that you are using. |