FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. For more details, review the migration guide. Contact support@fauna.com with any questions. |
Distinct
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
Distinct( source )
distinct( source )
Distinct( source )
Distinct( source )
Distinct( source )
Description
The Distinct
function returns all of the unique items found in
source
, which can be an Array or Set.
The run time of For query timeout errors, you may specify a larger query timeout via the driver that you are using. |
Parameters
Parameter | Type | Definition and Requirements |
---|---|---|
|
Array or Set Reference |
The Array or Set Reference to evaluate for distinct elements. |
Returns
When source
is an Array, an Array of the distinct items
found in source
.
When source
is a Set Reference, a Set Reference of the
distinct items found in source
.
Examples
The following query shows all of the elements in the "elements_of_spells" index. The index contains duplicate values for "fire" and "water".
{
data: [
'air', 'air',
'earth', 'fire',
'fire', 'water',
'water'
]
}
{'data': ['air', 'air', 'earth', 'fire', 'fire', 'water', 'water']}
map[data:[air air earth fire fire water water]]
ObjectV(data: Arr(StringV(air), StringV(air), StringV(earth), StringV(fire), StringV(fire), StringV(water), StringV(water)))
{
data: [
'air', 'air',
'earth', 'fire',
'fire', 'water',
'water'
]
}
When the Distinct
function is applied to this query, the duplicate
values, "fire" and "water" are eliminated.
{ data: [ 'air', 'earth', 'fire', 'water' ] }
{'data': ['air', 'earth', 'fire', 'water']}
map[data:[air earth fire water]]
ObjectV(data: Arr(StringV(air), StringV(earth), StringV(fire), StringV(water)))
{ data: [ 'air', 'earth', 'fire', 'water' ] }
The events view of a set of values include the resources themselves, the
distinct
function returns the same set.
{
data: [
{
ts: 1592270149090000,
action: 'add',
document: Ref(Collection("spells"), "181388642046968320"),
data: [ 'air' ]
},
{
ts: 1592270149090000,
action: 'add',
document: Ref(Collection("spells"), "181388642046968320"),
data: [ 'fire' ]
},
{
ts: 1592270149090000,
action: 'add',
document: Ref(Collection("spells"), "181388642071085568"),
data: [ 'fire' ]
},
{
ts: 1592270149090000,
action: 'add',
document: Ref(Collection("spells"), "181388642071085568"),
data: [ 'water' ]
},
{
ts: 1592270149090000,
action: 'add',
document: Ref(Collection("spells"), "181388642088911360"),
data: [ 'earth' ]
},
{
ts: 1592270149090000,
action: 'add',
document: Ref(Collection("spells"), "181388642088911360"),
data: [ 'water' ]
},
{
ts: 1592270149090000,
action: 'add',
document: Ref(Collection("spells"), "181388642581742080"),
data: [ 'air' ]
}
]
}
{'data': [{'ts': 1592864274420000, 'action': 'add', 'document': Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))), 'data': ['air']}, {'ts': 1592864274420000, 'action': 'add', 'document': Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))), 'data': ['fire']}, {'ts': 1592864274420000, 'action': 'add', 'document': Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))), 'data': ['fire']}, {'ts': 1592864274420000, 'action': 'add', 'document': Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))), 'data': ['water']}, {'ts': 1592864274420000, 'action': 'add', 'document': Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))), 'data': ['earth']}, {'ts': 1592864274420000, 'action': 'add', 'document': Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))), 'data': ['water']}, {'ts': 1592864274420000, 'action': 'add', 'document': Ref(id=181388642581742080, collection=Ref(id=spells, collection=Ref(id=collections))), 'data': ['air']}]}
map[data:[map[action:add data:[air] document:{181388642046968320 0xc00009a210 0xc00009a210 <nil>} ts:1603747155400000] map[action:add data:[fire] document:{181388642046968320 0xc00009a3f0 0xc00009a3f0 <nil>} ts:1603747155400000] map[action:add data:[fire] document:{181388642071085568 0xc00008e210 0xc00008e210 <nil>} ts:1603747155400000] map[action:add data:[water] document:{181388642071085568 0xc00008e3f0 0xc00008e3f0 <nil>} ts:1603747155400000] map[action:add data:[earth] document:{181388642088911360 0xc00008e5d0 0xc00008e5d0 <nil>} ts:1603747155400000] map[action:add data:[water] document:{181388642088911360 0xc00008e7b0 0xc00008e7b0 <nil>} ts:1603747155400000] map[action:add data:[air] document:{181388642581742080 0xc00008e990 0xc00008e990 <nil>} ts:1603747155400000]]]
ObjectV(data: Arr(ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections"))),data: Arr(StringV(air))), ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections"))),data: Arr(StringV(fire))), ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections"))),data: Arr(StringV(fire))), ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections"))),data: Arr(StringV(water))), ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642088911360", collection = RefV(id = "spells", collection = RefV(id = "collections"))),data: Arr(StringV(earth))), ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642088911360", collection = RefV(id = "spells", collection = RefV(id = "collections"))),data: Arr(StringV(water))), ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642581742080", collection = RefV(id = "spells", collection = RefV(id = "collections"))),data: Arr(StringV(air)))))
{
data: [
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642046968320"),
data: [ 'air' ]
},
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642046968320"),
data: [ 'fire' ]
},
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642071085568"),
data: [ 'fire' ]
},
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642071085568"),
data: [ 'water' ]
},
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642088911360"),
data: [ 'earth' ]
},
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642088911360"),
data: [ 'water' ]
},
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642581742080"),
data: [ 'air' ]
}
]
}
The following query demonstrates how various arrays are evaluated:
[ [ 'A', 'B', 'C' ], [ 'A', 'B' ], [ 'A' ] ]
[['A', 'B', 'C'], ['A', 'B'], ['A']]
[[A B C] [A B] [A]]
Arr(Arr(StringV(A), StringV(B), StringV(C)), Arr(StringV(A), StringV(B)), Arr(StringV(A)))
[ [ 'A', 'B', 'C' ], [ 'A', 'B' ], [ 'A' ] ]
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!