-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PARQUET-1381: Support merging of rowgroups during file rewrite #1121
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import org.apache.parquet.column.ColumnReader; | ||
import org.apache.parquet.column.ColumnWriteStore; | ||
import org.apache.parquet.column.ColumnWriter; | ||
import org.apache.parquet.column.EncodingStats; | ||
import org.apache.parquet.column.ParquetProperties; | ||
import org.apache.parquet.column.impl.ColumnReadStoreImpl; | ||
import org.apache.parquet.column.page.DictionaryPage; | ||
|
@@ -45,6 +46,7 @@ | |
import org.apache.parquet.format.converter.ParquetMetadataConverter; | ||
import org.apache.parquet.hadoop.CodecFactory; | ||
import org.apache.parquet.hadoop.ColumnChunkPageWriteStore; | ||
import org.apache.parquet.hadoop.ParquetFileReader; | ||
import org.apache.parquet.hadoop.ParquetFileWriter; | ||
import org.apache.parquet.hadoop.metadata.BlockMetaData; | ||
import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; | ||
|
@@ -117,6 +119,10 @@ public class ParquetRewriter implements Closeable { | |
private String originalCreatedBy = ""; | ||
// Unique created_by information from all input files | ||
private Set<String> allOriginalCreatedBys = new HashSet<>(); | ||
// Indicates if rowgroups from different needs to be merged. | ||
private boolean mergeRowGroups; | ||
// Max size of the merged rowgroup | ||
private long maxRowGroupSize; | ||
|
||
public ParquetRewriter(RewriteOptions options) throws IOException { | ||
Configuration conf = options.getConf(); | ||
|
@@ -130,6 +136,8 @@ public ParquetRewriter(RewriteOptions options) throws IOException { | |
|
||
newCodecName = options.getNewCodecName(); | ||
pruneColumns = options.getPruneColumns(); | ||
mergeRowGroups = options.isMergeRowGroups(); | ||
maxRowGroupSize = options.getMaxRowGroupSize(); | ||
|
||
// Prune columns if specified | ||
if (pruneColumns != null && !pruneColumns.isEmpty()) { | ||
|
@@ -246,6 +254,11 @@ public void close() throws IOException { | |
} | ||
|
||
public void processBlocks() throws IOException { | ||
if (mergeRowGroups) { | ||
mergeRowGroups(); | ||
return; | ||
} | ||
|
||
while (reader != null) { | ||
processBlocksFromReader(); | ||
initNextReader(); | ||
|
@@ -752,6 +765,27 @@ public GroupConverter asGroupConverter() { | |
} | ||
} | ||
|
||
private void mergeRowGroups() throws IOException { | ||
if (null == reader) { | ||
return; | ||
} | ||
|
||
boolean v2EncodingHint = meta.getBlocks().stream() | ||
.flatMap(b -> b.getColumns().stream()) | ||
.anyMatch(chunk -> { | ||
EncodingStats stats = chunk.getEncodingStats(); | ||
return stats != null && stats.usesV2Pages(); | ||
}); | ||
|
||
List<ParquetFileReader> readers = new ArrayList<>(); | ||
do { | ||
readers.add(reader); | ||
initNextReader(); | ||
} | ||
while(reader != null); | ||
new RowGroupMerger(schema, newCodecName, v2EncodingHint).merge(readers, maxRowGroupSize, writer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't review it in depth. Does it handle encryption or masking properties internally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Underneath, it uses the same instance of ParquetFileWriter which handles these operations. |
||
} | ||
|
||
private static class ColumnChunkEncryptorRunTime { | ||
private final InternalColumnEncryptionSetup colEncrSetup; | ||
private final BlockCipher.Encryptor dataEncryptor; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
v2EncodingHint
only checks the first parquet file..Should all the files to be checked?