Distinct
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".
map[data:[air air earth fire fire water water]]
{
data: [
'air', 'air',
'earth', 'fire',
'fire', 'water',
'water'
]
}
{'data': ['air', 'air', 'earth', 'fire', 'fire', 'water', '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.
map[data:[air earth fire water]]
{ data: [ 'air', 'earth', 'fire', 'water' ] }
{'data': ['air', 'earth', 'fire', '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.
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]]]
{
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']}]}
{
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']]
[ [ '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!