You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Avoid rewriting big files in RewriteDataFilesAction #1159
I try to use RewriteDataFilesAction to avoid too many small files.
But every time will rewrite all files even just have few small files. It is very expensive and slow.
So:
can RewriteDataFilesAction provides a Predicate<FileScanTask> like RewriteManifestsAction for giving a way to avoid rewriting big files.
I think you can specify filter expressions to rewrite files you wanted. For example, you can only rewrite data under newly added partition, not the whole data. I'm not sure if that is enough for you.
I think you can specify filter expressions to rewrite files you wanted. For example, you can only rewrite data under newly added partition, not the whole data. I'm not sure if that is enough for you.
Thanks for reply. Yes, using partition just rewrite once is OK.
I think we optimize further, if the partition is "day_time + type", some type has enough records in its files, but some others may have less records so leads to small files, so I rewrite the all newly partitions for reduce files but can skip big files in some partitions.
We do this a bit differently: instead of rewriting everything that matches a filter, we configure the rewrite to primarily look for small files. Any file already near the target size is ignored, and then we bin pack the rest of the files in each partition and rewrite. That ensures that we don't rewrite large amounts of data that are already reasonably sized. We don't care about files that are too large because they can be split, only the small files.
We also have an option to keep the files in order by file name for systems like Spark that sort the data. This is a hacky way to avoid ruining file pruning that takes advantage of clustered/sorted data.
I am working on a doc that will propose multiple compaction strategies depending on a use case. I want to map SQL extensions into that. We have been running those for a while and they proved to work even on large tables and already covers what @rdblue mentioned. I'll share the doc by the end of the week.
@rdblue logic that you described doesn't work for me. I have Spark Structured Streaming job which writes daily partitioned table and produce files of different size, primarily small ones. I ran RewriteDataFilesAction a few times on a single partition.
First run produced 86 files with size up to 128Mb as I configured. Second run took all these files and compacted them again merging them with very small files. Third run again took all files produced by previous job and compacted them again.
I understand that eventually compacted files will become so close to targetSize that they will be ignored, but until this happened we need to rewrite gigabytes of data again and again. Also it doesn't work for me because compaction process is relevant only for current day. At the beginning of new day we run major compaction with deduplication, sorting etc. and like "close" partition for previous day, it will not be modified anymore. Intermediate minor compaction is necessary only to prevent clients from reading thousands of small files.
Applying filter by row timestamp can improve the situation, but as we have many tables with completely different size we need to choose right compaction period for each table to have output files with reasonable size. It's really difficult to manage because their size can vary, new table can be added, etc. Also we have late records which could not be considered for compaction if there is no fresh records in the file.
It would be really nice to have separate configuration to limit file size or the predicate like @JingsongLi suggested.
What I was saying is that the service we built to do this chooses what to rewrite differently. The behavior of the rewrite action is as you describe: it will rewrite more than is necessary so we should add more configuration to provide more control.
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
Activity
jerryshao commentedon Jul 10, 2020
I think you can specify filter expressions to rewrite files you wanted. For example, you can only rewrite data under newly added partition, not the whole data. I'm not sure if that is enough for you.
JingsongLi commentedon Jul 13, 2020
Thanks for reply. Yes, using partition just rewrite once is OK.
I think we optimize further, if the partition is "day_time + type", some type has enough records in its files, but some others may have less records so leads to small files, so I rewrite the all newly partitions for reduce files but can skip big files in some partitions.
rdblue commentedon Jul 26, 2020
We do this a bit differently: instead of rewriting everything that matches a filter, we configure the rewrite to primarily look for small files. Any file already near the target size is ignored, and then we bin pack the rest of the files in each partition and rewrite. That ensures that we don't rewrite large amounts of data that are already reasonably sized. We don't care about files that are too large because they can be split, only the small files.
We also have an option to keep the files in order by file name for systems like Spark that sort the data. This is a hacky way to avoid ruining file pruning that takes advantage of clustered/sorted data.
aokolnychyi commentedon Jul 27, 2020
I am working on a doc that will propose multiple compaction strategies depending on a use case. I want to map SQL extensions into that. We have been running those for a while and they proved to work even on large tables and already covers what @rdblue mentioned. I'll share the doc by the end of the week.
davseitsev commentedon Aug 4, 2020
@rdblue logic that you described doesn't work for me. I have Spark Structured Streaming job which writes daily partitioned table and produce files of different size, primarily small ones. I ran
RewriteDataFilesActiona few times on a single partition.First run produced 86 files with size up to 128Mb as I configured. Second run took all these files and compacted them again merging them with very small files. Third run again took all files produced by previous job and compacted them again.
I understand that eventually compacted files will become so close to
targetSizethat they will be ignored, but until this happened we need to rewrite gigabytes of data again and again. Also it doesn't work for me because compaction process is relevant only for current day. At the beginning of new day we run major compaction with deduplication, sorting etc. and like "close" partition for previous day, it will not be modified anymore. Intermediate minor compaction is necessary only to prevent clients from reading thousands of small files.Applying filter by row timestamp can improve the situation, but as we have many tables with completely different size we need to choose right compaction period for each table to have output files with reasonable size. It's really difficult to manage because their size can vary, new table can be added, etc. Also we have late records which could not be considered for compaction if there is no fresh records in the file.
It would be really nice to have separate configuration to limit file size or the predicate like @JingsongLi suggested.
rdblue commentedon Aug 4, 2020
What I was saying is that the service we built to do this chooses what to rewrite differently. The behavior of the rewrite action is as you describe: it will rewrite more than is necessary so we should add more configuration to provide more control.
aokolnychyi commentedon Aug 4, 2020
The doc for data compaction is almost ready. It should cover what @davseitsev experiences.
aokolnychyi commentedon Aug 5, 2020
The proposal is here. I'll keep editing it in the following days.
github-actions commentedon Feb 11, 2024
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
github-actions commentedon Feb 26, 2024
This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'