
Answer-first summary for fast verification
Answer: 6 records
The streaming query is reading from the customers table using Delta Change Data Feed (readChangeFeed = true) and writing all change events to the mobiles table. Because there is no filter on the _change_type column, all change events (inserts, updates, deletes) are written to mobiles. Delta Change Data Feed produces: INSERT → 1 row (new value) DELETE → 1 row (deleted value) UPDATE → 2 rows: update_preimage (old value before update) update_postimage (new value after update) Step-by-step count: INSERT ('Tom', '8635875') → +1 row → total = 1 INSERT ('Paul', '24984567') → +1 row → total = 2 INSERT ('Ben', '79327492') → +1 row → total = 3 UPDATE Ben's mobile to '8474738' → +2 rows (old + new) → total = 5 DELETE mobile = '24984567' → +1 row → total = 6 Final total in mobiles table: 6 rows
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
spark.readStream.format(‘delta’)
.option(‘readChangeFeed’, ‘true’)
.table(‘customers’)
.select(‘mobile’)
.writeStream
.format(‘delta’)
.option(‘checkpointLocation’, ‘/tmp/cust/_checkpoints/’)
.table(‘mobiles’)
spark.readStream.format(‘delta’)
.option(‘readChangeFeed’, ‘true’)
.table(‘customers’)
.select(‘mobile’)
.writeStream
.format(‘delta’)
.option(‘checkpointLocation’, ‘/tmp/cust/_checkpoints/’)
.table(‘mobiles’)
Assuming that before starting the query, both the tables(mobiles and customers) were empty, what will be the number of records in the mobiles table after the execution of the following statements:
INSERT INTO customers VALUES (‘Tom’, ‘8635875’);
INSERT INTO customers VALUES (‘Paul’, ‘24984567′);
INSERT INTO customers VALUES (‘Ben’, ‘79327492’);
UPDATE customers SET mobile = ‘8474738’ WHERE name = ‘Ben’;
DELETE FROM customers WHERE mobile = ‘24984567’;
INSERT INTO customers VALUES (‘Tom’, ‘8635875’);
INSERT INTO customers VALUES (‘Paul’, ‘24984567′);
INSERT INTO customers VALUES (‘Ben’, ‘79327492’);
UPDATE customers SET mobile = ‘8474738’ WHERE name = ‘Ben’;
DELETE FROM customers WHERE mobile = ‘24984567’;
A
3 records
B
4 records
C
5 records
D
6 records
E
7 records