QuestionQ140

VerifiedData Modelling

An hourly batch job is set up to ingest data files from a cloud object-storage container, where every batch represents all records generated by the source system during a given hour. The job that processes these records into the Lakehouse is delayed sufficiently so that no late-arriving data is missed.

The user_id field is a unique key for the data, with the following schema:

user_id BIGINT, username STRING, user_utc STRING, user_region STRING, last_login BIGINT, auto_pay BOOLEAN, last_updated BIGINT

All new records are ingested into a table named account_history, which retains a complete record of all data using the same schema as the source. The next table in the system is named account_current and is implemented as a Type 1 table that represents the latest value for every unique user_id.

Assuming there are millions of user accounts and tens of thousands of records processed each hour, which implementation can efficiently update the described account_current table as part of every hourly batch job?

Explanation

A Type 1 current-state table is maintained efficiently by processing only the new hourly change set, retaining the latest row for each user_id, and merging that set into the target on user_id. MERGE performs updates for matched keys and inserts for previously unseen keys, avoiding an hourly scan and full overwrite of the complete history table. Delta Lake documentation also requires source rows to be deduplicated so that only one source row matches each target row. See Upsert into a Delta Lake table using merge.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!