-
Notifications
You must be signed in to change notification settings - Fork 631
HDDS-14946. Add CLI command for RewriteTablePathOzoneAction #10409
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
80ef3ef
HDDS-14946. Add CLI command for RewriteTablePathOzoneAction
727650e
Merge branch 'master' of github.com:apache/ozone into HDDS-14946
a867dfe
Addressed minor review comments
7a7af02
Added ozone iceberg subcommand and droped ozone-iceberg script
580fd49
Added parent command, removed INCLUDE_ICEBERG in dist-layout-stitchin…
cf04824
Removed unwanted edit
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
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
42 changes: 42 additions & 0 deletions
42
hadoop-ozone/iceberg/src/main/java/org/apache/hadoop/ozone/iceberg/IcebergCommand.java
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.ozone.iceberg; | ||
|
|
||
| import org.apache.hadoop.hdds.cli.GenericCli; | ||
| import org.apache.hadoop.hdds.cli.HddsVersionProvider; | ||
| import picocli.CommandLine.Command; | ||
|
|
||
| /** | ||
| * Parent command for Iceberg tables on Ozone. | ||
| */ | ||
| @Command( | ||
| name = "ozone iceberg", | ||
| aliases = "iceberg", | ||
| description = "commands for Iceberg tables on Ozone", | ||
| subcommands = { | ||
| RewriteTablePathCommand.class | ||
| }, | ||
| versionProvider = HddsVersionProvider.class, | ||
| mixinStandardHelpOptions = true | ||
| ) | ||
| public class IcebergCommand extends GenericCli { | ||
|
|
||
| public static void main(String[] args) { | ||
| new IcebergCommand().run(args); | ||
| } | ||
| } |
127 changes: 127 additions & 0 deletions
127
...-ozone/iceberg/src/main/java/org/apache/hadoop/ozone/iceberg/RewriteTablePathCommand.java
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 |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.ozone.iceberg; | ||
|
|
||
| import java.util.concurrent.Callable; | ||
| import org.apache.hadoop.hdds.cli.AbstractSubcommand; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.actions.RewriteTablePath; | ||
| import org.apache.iceberg.hadoop.HadoopTables; | ||
| import picocli.CommandLine.Command; | ||
| import picocli.CommandLine.Option; | ||
|
|
||
| /** | ||
| * CLI to rewrite Iceberg table paths. | ||
| */ | ||
| @Command( | ||
| name = "rewrite-path", | ||
| description = "Rewrite Iceberg table paths for table migration" | ||
| ) | ||
| public class RewriteTablePathCommand extends AbstractSubcommand implements Callable<Void> { | ||
|
|
||
| @Option( | ||
| names = {"-l", "--table-location"}, | ||
| required = true, | ||
| description = "The latest metadata.json file path of the table" | ||
| ) | ||
| private String tableLocation; | ||
|
|
||
| @Option( | ||
| names = {"-s", "--source-prefix"}, | ||
| required = true, | ||
| description = "Source path prefix to replace" | ||
| ) | ||
| private String sourcePrefix; | ||
|
|
||
| @Option( | ||
| names = {"-t", "--target-prefix"}, | ||
| required = true, | ||
| description = "Target path prefix" | ||
| ) | ||
| private String targetPrefix; | ||
|
|
||
| @Option( | ||
| names = {"--staging"}, | ||
| description = "Staging location where all the rewritten files will be placed " | ||
| + "(Default is a new directory under the table's current metadata directory.)" | ||
| ) | ||
| private String stagingLocation; | ||
|
|
||
| @Option( | ||
| names = {"--start-version"}, | ||
| description = "Start version metadata file name (optional, e.g., v1.metadata.json)" | ||
| ) | ||
| private String startVersion; | ||
|
|
||
| @Option( | ||
| names = {"--end-version"}, | ||
| description = "End version metadata file name (optional, defaults to current)" | ||
| ) | ||
| private String endVersion; | ||
|
|
||
| @Option( | ||
| names = {"--threads"}, | ||
| defaultValue = "10", | ||
| description = "Number of threads to use (positive integer). " | ||
| + "If omitted or zero, the default thread count 10 is used." | ||
| ) | ||
| private int threads; | ||
|
|
||
| @Override | ||
| public Void call() { | ||
| out().println("Starting Iceberg table path rewrite"); | ||
| out().println("Table location: " + tableLocation); | ||
| out().println("Source prefix: " + sourcePrefix); | ||
| out().println("Target prefix: " + targetPrefix); | ||
|
|
||
| HadoopTables tables = new HadoopTables(getOzoneConf()); | ||
| Table table = tables.load(tableLocation.trim()); | ||
| out().println("Table loaded: " + table.location()); | ||
|
|
||
| RewriteTablePathOzoneAction action = new RewriteTablePathOzoneAction(table, threads); | ||
| out().println("Threads: " + threads); | ||
|
|
||
| RewriteTablePath rewriteAction = action.rewriteLocationPrefix(sourcePrefix, targetPrefix); | ||
|
|
||
| if (stagingLocation != null && !stagingLocation.isBlank()) { | ||
| out().println("Staging location: " + stagingLocation); | ||
| rewriteAction.stagingLocation(stagingLocation); | ||
| } | ||
|
|
||
| if (startVersion != null && !startVersion.isBlank()) { | ||
| out().println("Start version: " + startVersion); | ||
| rewriteAction.startVersion(startVersion); | ||
| } | ||
|
|
||
| if (endVersion != null && !endVersion.isBlank()) { | ||
| out().println("End version: " + endVersion); | ||
| rewriteAction.endVersion(endVersion); | ||
| } | ||
|
|
||
| RewriteTablePath.Result result = rewriteAction.execute(); | ||
|
|
||
| out().println(); | ||
| out().println("Rewrite completed successfully"); | ||
| out().println(" Latest version: " + result.latestVersion()); | ||
| out().println(" Staging location: " + result.stagingLocation()); | ||
| out().println(); | ||
| out().println("Next step: Copy files from source to target using the file list"); | ||
| out().println(" File list location: " + result.fileListLocation()); | ||
| return null; | ||
| } | ||
| } | ||
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.
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.
Add
executeinside try/catch and output if any error to console, like ifvalidateInputsfails.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.
Not addressed yet?
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.
I have made
IcebergCommandextendGenericClidue to whichrewriteAction.execute() errors are handled by GenericCli's PicoCLI execution exception handler, which prints the error message and also provides --verbose with which we can see the full stack trace. So an explicit try/catch in RewriteTablePathCommand would be redundant.