Multiupdate by query

Is there any alternative in Aerospike to this SQL expression? UPDATE products SET price = price * {$myVariable};

So currently you would do this with a record UDF that you apply to all the records in the namespace (or set) products.

function update_multiply(rec, bin_name, multiplier)
    if aerospike:exists(rec) then
        local value = rec[bin_name]
        rec[bin_name] = value * multiplier
        aerospike:update(rec)
    end
end

Now to run the example, I’ll use the aql command-line tool. In the real world, you’d call it from a language client, once you’ve debugged your Lua code.

KEY_SEND = true

aql> SELECT * FROM test.products
+------------+---+
| PK         | i |
+------------+---+
| "here"     | 2 |
| "there"    | 3 |
| "anywhere" | 4 |
+------------+---+
3 rows in set (0.187 secs)

OK

aql> REGISTER MODULE 'update.lua'
OK, 1 module added.

aql> EXECUTE update.update_multiply("i", 2) ON test.products
OK, Scan job (9319251124864029115) created.

aql> SELECT * FROM test.products
+------------+---+
| PK         | i |
+------------+---+
| "here"     | 4 |
| "there"    | 6 |
| "anywhere" | 8 |
+------------+---+
3 rows in set (0.175 secs)

In a near future release of Aerospike Database you’ll be able to do this with a Write Expression instead of a UDF. At the moment Expressions are just used as a filter, allowing you to put a condition on whether a record operation, batch-read, scan, query or UDF call happens. Their use will be expanded.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.