PQL XOR()
The Xor()
query performs a set xor on the row calls passed as arguments. This is equivalent to a symmetric difference over two or more sets.
Xor()
is a row call.
Call Definition
Xor(ROW_CALL, ... )
Mandatory Arguments
ROW_CALL
: a row call (set of record IDs / keys)
Optional Arguments
...
: Any number of additional row call seperated by commas
Returns
- list of record IDs or record keys
Examples
Data:
Index: customer (non keyed index)
_id | age (Int) | has_purchased (Set) | last_purchase (Timestamp)
-----+-----------+------------------------------+---------------------------
0 | 23 | ["brand1","brand2"] | 2021-01-05T08:30:00Z
1 | 31 | ["brand1","brand3"] | 2020-09-12T12:30:00Z
2 | 28 | ["brand1","brand3","brand4"] | 2021-08-06T16:15:00Z
3 | 19 | [] | null
4 | 25 | ["brand1","brand4"] | 2021-10-01T20:45:00Z
5 | 40 | ["brand4"] | 2022-01-13T11:00:00Z
Example 1
Which users have purchased from brand1 or brand4 but not both?
Query
[customer]Xor(
Row(has_purchased = brand1),
Row(has_purchased = brand4)
)
Tabular Response
_id
-----
0
1
2
5
HTTP Response
{
"results": [
{
"columns": [
0,
1,
2,
5
]
}
]
}
Explanation
Row(has_purchased = brand1)
returns [0,1,2,4]
and Row(has_purchased = brand4)
returns [4,5]
. [0,1,2,5] are the records that can be found but aren’t in both sets.
Example 1
Which users have purchased from brand1 or brand4 but not both?
Query
[customer]Xor(
Row(has_purchased = brand1),
Row(has_purchased = brand3),
Row(has_purchased = brand4)
)
Tabular Response
_id
-----
0
2
5
HTTP Response
{
"results": [
{
"columns": [
0,
2,
5
]
}
]
}
Explanation
Row(has_purchased = brand1)
returns [0,1,2,4]
, Row(has_purchased=brand3)
returns [1,2]
, and Row(has_purchased = brand4)
returns [4,5]
. [0,2]
are only contained in a single set and are thus returned. 5 is contained in all of the sets and is returned for that reason.