PQL SET()
The Set()
call associates or assigns a value to a record in a specified field. If the value we are assigning is in a Mutex, Int, Decimal, or Timestamp field, the current value is overwritten. If the value we are assigning is in a Set or Time field, all previous values will remain.
While using “Set” in PQL is a convenient way to get familiar with FeatureBase, it’s almost always better to use a dedicated ingest tool. See ingesters for details.
Call Definition
Set(UINT_OR_STRING, FIELD=FIELD_VALUE, TIMESTAMP)
Mandatory Arguments
UINT_OR_STRING
: the record to write to – UINT or unsigned int for a non-keyed index and string for a keyed index.FIELD
: the name of the field that contains the value we want to associate with the recordFIELD_VALUE
: the value we want to associate with the record
Optional Arguments
TIMESTAMP
: when FIELD is a Time field, this is an optional arguement and is used to associate this relationship with a specific time. Otherwise, it should not be provided.
Returns
- boolean
- true indicates that the value was update or added.
- false indicates that the value was not updated or added – in some cases this means the value already existed or was alread equal to the desired value.
Examples
Example 1
Customer 3 bought from brand5 - update the index accordinly.
Data Pre-Query
Index: customer (non keyed index)
_id | age (Int) | has_purchased (Set)
-----+-----------+---------------------
0 | 23 | ["brand1","brand2"]
1 | 31 | ["brand1","brand3"]
2 | 28 | ["brand1","brand3"]
3 | 19 | []
4 | 25 | ["brand1","brand4"]
5 | 40 | ["brand4"]
Query
[customer]Set(3, has_purchased=brand5)
Tabular Response
result
--------
true
Data Post-Query
_id | age (Int) | has_purchased (Set)
-----+-----------+---------------------
0 | 23 | ["brand1","brand2"]
1 | 31 | ["brand1","brand3"]
2 | 28 | ["brand1","brand3"]
3 | 19 | ["brand5"]
4 | 25 | ["brand1","brand4"]
5 | 40 | ["brand4"]
Example 1
Update the age of customer 3 to 20.
Data Pre-Query
Index: customer (non keyed index)
_id | age (Int) | has_purchased (Set)
-----+-----------+---------------------
0 | 23 | ["brand1","brand2"]
1 | 31 | ["brand1","brand3"]
2 | 28 | ["brand1","brand3"]
3 | 19 | []
4 | 25 | ["brand1","brand4"]
5 | 40 | ["brand4"]
Query
[customer]Set(3, age=20)
Tabular Response
result
--------
true
Data Post-Query
Index: customer (non keyed index)
_id | age (Int) | has_purchased (Set)
-----+-----------+---------------------
0 | 23 | ["brand1","brand2"]
1 | 31 | ["brand1","brand3"]
2 | 28 | ["brand1","brand3"]
3 | 20 | []
4 | 25 | ["brand1","brand4"]
5 | 40 | ["brand4"]