QuestionQ62

VerifiedData Modelling

An hourly batch job is configured to ingest data files from a cloud object-storage container, where each batch represents all records produced by the source system during a given hour. The batch job that processes these records into the Lakehouse is delayed sufficiently to ensure 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 most recent value for every unique user_id.

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

Explanation

A Type 1 current-state table is efficiently maintained by incrementally filtering newly processed history records, reducing them to one record per unique user_id, and using MERGE to update matching users and insert new users. MERGE supports this upsert pattern; the source must be deduplicated because multiple source rows matching one target row make the update ambiguous. Using user_id is required because it is the unique key, while overwriting from the entire history table repeatedly is unnecessarily expensive at this scale.

Learn more

Community Discussion

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