You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by do...@apache.org on 2021/08/20 18:52:49 UTC
[orc] branch branch-1.7 updated: ORC-958: Convert command support
overwrite option (#876)
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/branch-1.7 by this push:
new cde3f1c ORC-958: Convert command support overwrite option (#876)
cde3f1c is described below
commit cde3f1cab25e24049d067d96aac37591cedda793
Author: guiyanakaung <gu...@gmail.com>
AuthorDate: Sat Aug 21 02:51:39 2021 +0800
ORC-958: Convert command support overwrite option (#876)
### What changes were proposed in this pull request?
Make the convert command support the overwrite option.
### Why are the changes needed?
You can overwrite old files when you convert multiple times.
```
$ java -jar java/tools/target/orc-tools-1.8.0-SNAPSHOT-uber.jar convert
usage: convert
-e,--escape <arg> CSV escape character
-h,--help Provide help
-H,--header <arg> CSV header lines
-n,--null <arg> CSV null string
-o,--output <arg> Output filename
-O,--overwrite Overwrite an existing file
-q,--quote <arg> CSV quote character
-s,--schema <arg> The schema to write in to the file
-S,--separator <arg> CSV separator character
-t,--timestampformat <arg> Timestamp Format
$ java -jar java/tools/target/orc-tools-1.8.0-SNAPSHOT-uber.jar convert -O examples/orc-file-11-format.orc examples/orc-file-11-format.orc
Merging schema from examples/orc-file-11-format.orc
Merging schema from examples/orc-file-11-format.orc
Processing examples/orc-file-11-format.orc
Processing examples/orc-file-11-format.orc
$ java -jar java/tools/target/orc-tools-1.8.0-SNAPSHOT-uber.jar convert -O examples/orc-file-11-format.orc examples/orc-file-11-format.orc
Merging schema from examples/orc-file-11-format.orc
Merging schema from examples/orc-file-11-format.orc
Processing examples/orc-file-11-format.orc
Processing examples/orc-file-11-format.orc
```
### How was this patch tested?
Pass the CIs.
(cherry picked from commit 2dcbd6281e2fbeeaf0ffe46aa3b78cd3df96ed62)
Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
.../tools/src/java/org/apache/orc/tools/convert/ConvertTool.java | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/java/tools/src/java/org/apache/orc/tools/convert/ConvertTool.java b/java/tools/src/java/org/apache/orc/tools/convert/ConvertTool.java
index 7bacde8..fbb2337 100644
--- a/java/tools/src/java/org/apache/orc/tools/convert/ConvertTool.java
+++ b/java/tools/src/java/org/apache/orc/tools/convert/ConvertTool.java
@@ -196,8 +196,9 @@ public class ConvertTool {
this.timestampFormat = opts.getOptionValue("t", DEFAULT_TIMESTAMP_FORMAT);
String outFilename = opts.hasOption('o')
? opts.getOptionValue('o') : "output.orc";
+ boolean overwrite = opts.hasOption('O');
writer = OrcFile.createWriter(new Path(outFilename),
- OrcFile.writerOptions(conf).setSchema(schema));
+ OrcFile.writerOptions(conf).setSchema(schema).overwrite(overwrite));
batch = schema.createRowBatch();
}
@@ -256,8 +257,12 @@ public class ConvertTool {
Option.builder("H").longOpt("header").desc("CSV header lines")
.hasArg().build());
options.addOption(
- Option.builder("t").longOpt("timestampformat").desc("Timestamp Format")
+ Option.builder("t").longOpt("timestampformat").desc("Timestamp Format")
.hasArg().build());
+ options.addOption(
+ Option.builder("O").longOpt("overwrite").desc("Overwrite an existing file")
+ .build()
+ );
CommandLine cli = new DefaultParser().parse(options, args);
if (cli.hasOption('h') || cli.getArgs().length == 0) {
HelpFormatter formatter = new HelpFormatter();