How to avoid iteration/loop in databricks in the given scenario

shri0509
New Contributor II

Hi all, I need your input.

I am new to Databricks and working with a dataset that consists of around 10,000 systems, each containing approximately 100 to 150 parts. These parts have attributes such as name, version, and serial number. The dataset size is around 10 million records.

The task is to retrieve the parts associated with each system for a particular day and compare them with the parts from the previous day. If there are any changes, such as modifications, deletions, or additions, I need to create a union of all these changes and store the result in Databricks. This updated dataset will then be used for comparison with the parts available on the next day, and the process repeats.

Below, I've provided an example of the input and expected output for a particular system.

Currently, I'm iterating over days for each system and calculating the deltas using left anti and inner joins in each iteration. However, this process is taking a considerable amount of time in Databricks.

Is there a more efficient way to handle this without the iterative approach? I would appreciate any suggestions.

Input:

systemlogDatenameversionserial
123456786/24/24name1version1number1
123456786/24/24name2version2number2
123456786/25/24name1version1number1
123456786/25/24name2version2number2
123456786/26/24name1version1number1
123456786/26/24name2version2number2
123456786/26/24name3version3number3
123456786/27/24name1version1number1
123456786/27/24name2version2.1number2
123456786/27/24name3version3number3
123456786/30/24name2version2.1number2
123456786/30/24name3version3number3.1

Output;

systemlogDatenameversionserial
123456786/24/24name1version1number1
123456786/24/24name2version2number2
123456786/26/24name1version1number1
123456786/26/24name2version2number2
123456786/26/24name3version3number3
123456786/27/24name1version1number1
123456786/27/24name2version2.1number2
123456786/27/24name3version3number3
123456786/30/24name1version1number1
123456786/30/24name2version2.1number2
123456786/30/24name3version3number3.1