Continuity Problem Best Practices
Requirement Scenarios
The so-called continuity problems include:
-
Complete size (color) rate (footwear and apparel): In a certain product's colors, if more than 4 consecutive sizes have inventory, it is considered complete size
-
Consecutive ordering (purchasing) months (member-related)······
In daily report creation, continuity-related problems are often encountered. The following solutions are provided for reference:
Solution Approach
-
Arrange the data in a certain order (such as: by size, color, time, etc.)
-
Label the content to be determined (such as: whether there is inventory, yes is 1, no is 0)
-
Use row_number() to record the position of each value;
-
Group by label, use collect_list() function to record the row_number() information of 0 or 1;
-
Select the array with label 1, use the characteristic of consecutive values (max-min+1=number of values in the array) to calculate related content
Case Implementation
The following example uses the complete size rate of Red color for a certain product.
- Arrange the relevant inventory data by size;

-
Label by whether there is inventory, with inventory as: 1, without inventory as: 0;
-
Use row_number() to record the row numbers of all values;

- Group by whether there is inventory label, use collect_list() function to record the position information of 0 or 1;

-
Select the array with label 1, use the characteristic of consecutive values (max-min+1=number of values in the array) to calculate related content, calculate the consecutive number of sizes with inventory;
-
Final effect: In the array with label "1", maximum value: 5, minimum value: 2, number of values in the array: 4. Then:
Maximum value - Minimum value + 1 = Number of values in the array; i.e.: 5-2+1=4. Therefore, this product's Red color sizes are complete.