[FEATURE]: Update Metadate Columns to leverage _commit_timestamp
Is there an existing issue for this?
- [x] I have searched the existing issues
Problem statement
The lakeflow frameworks metadata columns use the function 'insert_current_timestamp()' when writing to tables. This is fine for streaming tables but causes problems for any consuming Materialised view.
Materialized views guarantee equivalent results to batch queries, or else will default to a full recompute.
Not deterministic functions like 'insert_current_timestamp()' prevent SDP from being able to incrementalize (because it changes every run), and thus force a full recompute.
Full recompute cost is proportional to size of inputs. Incremental refreshes are proportional to size of change. As such, there can be significant cost implications for a table being eligible for incremental refresh.
Proposed Solution
Leverage the '_commit_timestamp' field as supplied by the Change data feed. https://docs.databricks.com/aws/en/tables/features/change-data-feed#change-data-feed-schema
This is does not change between runs and allows MVs to incrementalize.
The 'inset_current_timestamp()' and '_commit_timestamp' are functionally the same for the purposes of tracking when a change was applied to a table.
The nuances between the two arguably support '_commit_timestamp' as the better option. '_commit_timestamp' reflects the time when the row was committed to a table. 'insert_current_timestamp()' is calculated at query time and thus can cause problems in edge cases (if there is a material difference between query calculation time and the write time'
Additional Context
No response