apache beam: how to override source parquet file with updated data

Viewed 96

I have a beam pipeline written in python that reads two parquet files: state and updates. The pipeline keeps the current data "state" in the state file, reads a updates file and it will update the state file (possibly adding new rows) with the content of updates. Ideally my pipeline should overwrite the state file so that next time my pipeline runs with new updates I am comparing them with the most recent state. Here is my issue. My starting file is called state.parquet after my pipeline ends, it won't override the file but it will create a new file called state-00000-of-00001.parquet. This makes me realise that this is probably not a really good idea to do this, because when the file will grow I could have the output file sharded across multiple separate files, and will cause problems.

What would be a better approach to accomplish what I am trying to do?

1 Answers

You can give your files an execution id suffix such as state-run0001-00000-of-0000x.parquet and update-run0002-00000-of-0000x.parquet. Use the file names such as state-run0001 and update-run0002 as inputs of your pipelines. Then write the output to state-run0002-00000-of-0000x.parquet.

You just need to keep track of the execution id run000x to schedule your jobs.

Related