Lenses SQL allows you to utilize the ANSI SQL command to store new records into a table.
Single or multi record inserts are supported:
INSERT INTO $Table(column1[, column2, column3]) VALUES(value1[,value2, value3]) INSERT INTO $Table(column1[, column2, column3]) VALUES (value1[,value2, value3]), (value4[,value5, value6])
1 + 1
NOW()
Example:
INSERT INTO customer ( _key, id , address.line , address.city , address.postcode , email) VALUES ('maria.wood','maria.wood', '698 E. Bedford Lane','Los Angeles', 90044, 'maria.wood@lenses.io'), ('david.green', 'david.green', '4309 S Morgan St', 'Chicago', 60609, 'david.green@lenses.io');
Records can be inserted from the result of SELECT statement.
The syntax is:
INSERT INTO $TABLE1 SELECT */column1[,column2, ...] FROM $Table2 [WHERE $condition] [LIMIT N]
For example, to copy all the records from the customer table into customer_avro one:
INSERT INTO customer_avro SELECT * FROM customer
There are two ways to delete data:
DELETE
-- Delete records across all partitions up to the offset 10 DELETE FROM customer WHERE _meta.offset <= 10; -- Delete records from a specific partition DELETE FROM customer WHERE _meta.offset <= 10 AND _meta.partition = 2
Key
customer_avro
DELETE FROM customer_avro WHERE _key = 'andy.perez'
Deleting is an insert operation. Until the compaction takes place, there will be at least one record with the Key used earlier. The latest (or last) record will have the Value set to null.
To remove all records from a table:
TRUNCATE TABLE $Table
where the $Table is the table name to delete all records from. This operation is only supported on non-compacted topics, which is a Kafka design restriction. To remove the data from a compacted topic, you have two options: either dropping and recreating the topic or inserting null Value records for each unique Key on the topic.
$Table
After rebuilding the customer table to be non-compacted, perform the truncate:
customer
TRUNCATE TABLE customer; /* SELECT count(*) FROM customer returns 0 after the previous statement */
On this page