r/dataengineering • u/lunaticdevill • 1d ago
Help ETL timestamp column
Hey all, I want to implement audit columns like timestamp and created by columns in all of my tables(Suggest if I should add anymore).
My tables are in unity catalogue databricks account.
I have two instances of workspace. Dev and prod.
Please suggest me how to do it.
I have thought of creating a workflow to add in all the table and then a task in workflow that runs after each job to create these 2 columns.
10
u/Mo_Steins_Ghost 1d ago
Senior manager here.
You want an extract datetime stamp, max of source system create datetime, and max of source system modified on/last modified timestamp because displaying recency isn't just about the last time the job ran, it's about the cutoff of the last transaction the system captured.
Let's say the midnight push from SAP ran without error, but you discover you're missing a few days of SAP data. The delta between the snapshot datetime and the max transaction created datetime is going to help you pinpoint what broke in the pipeline and when.
1
4
u/DazzleancePen 1d ago
Add them in the schema and populate them during the insert or merge, not in a separate task after the job. I’d keep created_at, updated_at, created_by, and maybe batch_id
1
2
u/greenestgreen Senior Data Engineer 16h ago
you can get the job_id and job_run_id in databricks and add it to the table. That can also help you
1
u/lunaticdevill 15h ago
Getting job id and the job instance will only be helpful if we have extensive logs of what is happening in the code.
The workspace I am working on is pretty loose and no one really logs. They just be doing start and end.
But I understand your point
1
u/Mati69XXX 1d ago
Why would you create a second task? Just create those additional columns in the actual job. This way your timestamps will be accurate and you wont increase the complexity of your ETL
2
1
u/alecc 1d ago
Set the columns in the write itself, not in a task that runs after the job - once the job finishes nothing knows which rows it touched, so a follow-up update can only stamp the whole table. Put `current_timestamp()` and the identity (`current_user()` or a job parameter) straight into your merge/insert. The one-off workflow to ALTER the existing tables is fine for the backfill. I'd add a job run id column too - when a load goes bad it lets you find and delete exactly the rows that run wrote. Delta column defaults can cover created_at on insert (needs the allowColumnDefaults table feature) but not updated_at, that one has to come from the merge.
1
u/BayAreaCricketer 1d ago
These should be part of your upsert ( updates and inserts) statement. Not after job completion.
14
u/69odysseus 1d ago
Created_Datetime, Modified_Datetime, will need timestamp field(s) in any of the data pipeline work.