D8LooPFocus modeCODE WORKSPACE
Return partition_day, row_count, and skew_flag ('hot' when row_count is above the average, else 'normal'). Order by row_count DESC, then partition_day.
Label each partition hot or normal by comparing its row_count to the table average.
Sample input
| partition_day | row_count |
|---|---|
| 2026-01-01 | 900 |
| 2026-01-02 | 1100 |
| 2026-01-03 | 800 |
| 2026-01-04 | 4200 |
| 2026-01-05 | 1000 |
| 2026-01-06 | 3000 |
| 2026-01-07 | 1200 |
| 2026-01-08 | 800 |
Expected output
| partition_day | row_count | skew_flag |
|---|---|---|
| 2026-01-04 | 4200 | hot |
| 2026-01-06 | 3000 | hot |
| 2026-01-07 | 1200 | normal |
| 2026-01-02 | 1100 | normal |
| 2026-01-05 | 1000 | normal |
| 2026-01-01 | 900 | normal |
| 2026-01-03 | 800 | normal |
| 2026-01-08 | 800 | normal |
Constraints
Compare row_count to (SELECT AVG(row_count) FROM table_partitions) inside a CASE to label hot vs normal. Order by row_count DESC, partition_day ASC.
Expected skills
Skew detection with a scalar AVG and CASE labels.
Run the SQL query to inspect preview rows.