Distinct
Distinct( source )
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. |
Examples
The following query shows all of the elements in the "elements_of_spells" index. The index contains duplicate values for "fire" and "water".
ObjectV(data: Arr(StringV(air), StringV(air), StringV(earth), StringV(fire), StringV(fire), StringV(water), StringV(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']}
{
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.
ObjectV(data: Arr(StringV(air), StringV(earth), StringV(fire), StringV(water)))
map[data:[air earth fire water]]
{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.
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)))))
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: 1594321463870000, action: "add", document: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections"))), data: ["air"]}, {ts: 1594321463870000, action: "add", document: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections"))), data: ["fire"]}, {ts: 1594321463870000, action: "add", document: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections"))), data: ["fire"]}, {ts: 1594321463870000, action: "add", document: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections"))), data: ["water"]}, {ts: 1594321463870000, action: "add", document: ref(id = "181388642088911360", collection = ref(id = "spells", collection = ref(id = "collections"))), data: ["earth"]}, {ts: 1594321463870000, action: "add", document: ref(id = "181388642088911360", collection = ref(id = "spells", collection = ref(id = "collections"))), data: ["water"]}, {ts: 1594321463870000, action: "add", document: ref(id = "181388642581742080", collection = ref(id = "spells", collection = ref(id = "collections"))), data: ["air"]}]}
{
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:
Arr(Arr(StringV(A), StringV(B), StringV(C)), Arr(StringV(A), StringV(B)), Arr(StringV(A)))
[[A B C] [A B] [A]]
[["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!