All,
I am looking at some tips with regards to optimizing a ELT on a Snowflake Fact table with approx. 15 billion rows.
We get approximately 30,000 rows every 35 mins like the one below, we always will get 3 Account Dimension Key values i.e. Sales, Cogs & MKT.
| Finance_Key | Date_Key | Department_Group_Key | Scenario_Key | Account_Key | Value | IsCurrent |
|---|---|---|---|---|---|---|
| 001 | 2019-01-01 | 001 | 0012 | SALES_001 | 100 | Y |
| 001 | 2019-01-01 | 001 | 0012 | COGS_001 | 300 | Y |
| 001 | 2019-01-01 | 001 | 0012 | MKT_001 | 200 | Y |
This is then PIVOTED based on Finance Key and Date Key and loaded into another table for reporting, like the one below
| Finance_Key | Date_Key | Department_Group_Key | Scenario_Key | SALES | COGS | MKT | IsCurrent |
|---|---|---|---|---|---|---|---|
| 001 | 2019-01-01 | 001 | 0012 | 100 | 300 | 200 | Y |
At times there is an adjustment made and for 1 Account key.
| Finance_Key | Date_Key | Department_Group_Key | Scenario_Key | Account_Key | Value |
|---|---|---|---|---|---|
| 001 | 2019-01-01 | 001 | 0012 | SALES_001 | 50 |
Hence we have to do this
| Finance_Key | Date_Key | Department_Group_Key | Scenario_Key | Account_Key | Value | IsCurrent |
|---|---|---|---|---|---|---|
| 001 | 2019-01-01 | 001 | 0012 | SALES_001 | 100 | X |
| 001 | 2019-01-01 | 001 | 0012 | COGS_001 | 300 | Y |
| 001 | 2019-01-01 | 001 | 0012 | MKT_001 | 200 | Y |
| 001 | 2019-01-01 | 001 | 0012 | SALES_001 | 50 | Y |
And the resulting value should be
| Finance_Key | Date_Key | Department_Group_Key | Scenario_Key | SALES | COGS | MKT |
|---|---|---|---|---|---|---|
| 001 | 2019-01-01 | 001 | 0012 | 50 | 300 | 200 |
However my question is how do I go about optimizing the query to scan and update the Pivoted table for approx. 15 billion rows in Snowflake.
This is more of a optimization the read and write .
Any pointers
Thanks