-
Notifications
You must be signed in to change notification settings - Fork 508
ORC-2149: Supports merging multiple ORC files with the same schema into multiple ORC files #2601
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
Open
QianyongY
wants to merge
6
commits into
apache:main
Choose a base branch
from
QianyongY:features/ORC-2149
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+915
−14
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb3c041
Supports merging multiple ORC files with the same schema into multipl…
QianyongY 5af4860
Enhance maxSize option validation and output directory checks in Merg…
QianyongY 2334079
Add --preserveStructure, deterministic input sorting and --overwrite …
QianyongY d30754d
fix style
QianyongY fef080e
Adjust merging logic to ensure contiguous part file naming and improv…
QianyongY 5e235bf
Add output path validation to prevent overlap with input roots in Mer…
QianyongY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -53,6 +53,7 @@ public class TestMergeFiles implements TestConf { | |||
| @BeforeEach | ||||
| public void openFileSystem() throws Exception { | ||||
| fs = FileSystem.getLocal(conf); | ||||
| fs.delete(workDir, true); | ||||
| fs.mkdirs(workDir); | ||||
| fs.deleteOnExit(workDir); | ||||
| testFilePath = new Path(workDir + File.separator + "TestMergeFiles.testMerge.orc"); | ||||
|
|
@@ -107,4 +108,85 @@ public void testMerge() throws Exception { | |||
| assertEquals(10000 + 20000, reader.getNumberOfRows()); | ||||
| } | ||||
| } | ||||
|
|
||||
| /** | ||||
| * Verifies that --maxSize splits input files into multiple part files under the output | ||||
| * directory. Three source files are created; a tight size threshold forces them to be | ||||
| * written into at least two part files. | ||||
| */ | ||||
| @Test | ||||
| public void testMergeWithMaxSize() throws Exception { | ||||
|
QianyongY marked this conversation as resolved.
|
||||
| TypeDescription schema = TypeDescription.fromString("struct<x:int,y:string>"); | ||||
|
|
||||
| // Create 3 source ORC files. | ||||
| String[] sourceNames = { | ||||
| workDir + File.separator + "ms-1.orc", | ||||
| workDir + File.separator + "ms-2.orc", | ||||
| workDir + File.separator + "ms-3.orc" | ||||
| }; | ||||
| int[] rowCounts = {5000, 5000, 5000}; | ||||
| for (int f = 0; f < sourceNames.length; f++) { | ||||
| Writer writer = OrcFile.createWriter(new Path(sourceNames[f]), | ||||
| OrcFile.writerOptions(conf).setSchema(schema)); | ||||
| VectorizedRowBatch batch = schema.createRowBatch(); | ||||
| LongColumnVector x = (LongColumnVector) batch.cols[0]; | ||||
| BytesColumnVector y = (BytesColumnVector) batch.cols[1]; | ||||
| for (int r = 0; r < rowCounts[f]; ++r) { | ||||
| int row = batch.size++; | ||||
| x.vector[row] = r; | ||||
| byte[] buffer = ("val-" + r).getBytes(); | ||||
| y.setRef(row, buffer, 0, buffer.length); | ||||
| if (batch.size == batch.getMaxSize()) { | ||||
| writer.addRowBatch(batch); | ||||
| batch.reset(); | ||||
| } | ||||
| } | ||||
| if (batch.size != 0) { | ||||
| writer.addRowBatch(batch); | ||||
| } | ||||
| writer.close(); | ||||
| } | ||||
|
|
||||
| // Measure the size of the first source file to compute a threshold that forces a split. | ||||
| long singleFileSize = fs.getFileStatus(new Path(sourceNames[0])).getLen(); | ||||
| // Threshold: slightly larger than one file so at most one file fits per part. | ||||
| long maxSize = singleFileSize + 1; | ||||
|
QianyongY marked this conversation as resolved.
Outdated
|
||||
|
|
||||
| Path outputDir = new Path(workDir + File.separator + "merge-multi-out"); | ||||
| fs.delete(outputDir, true); | ||||
|
|
||||
| PrintStream origOut = System.out; | ||||
| ByteArrayOutputStream myOut = new ByteArrayOutputStream(); | ||||
| System.setOut(new PrintStream(myOut, false, StandardCharsets.UTF_8)); | ||||
| try { | ||||
| MergeFiles.main(conf, new String[]{workDir.toString(), | ||||
| "--output", outputDir.toString(), | ||||
| "--maxSize", String.valueOf(maxSize)}); | ||||
| System.out.flush(); | ||||
| } finally { | ||||
| System.setOut(origOut); | ||||
| } | ||||
| String output = myOut.toString(StandardCharsets.UTF_8); | ||||
| System.out.println(output); | ||||
|
||||
| System.out.println(output); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.