Skip to content

Commit a6b4194

Browse files
committed
update
1 parent 8be0dad commit a6b4194

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

parquet-cli/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Usage: parquet [options] [command] [command options]
137137
### Configuration Options
138138

139139
- `--conf` or `--property`: Set any configuration property in format `key=value`. Can be specified multiple times.
140+
- `--config-file`: Path to a properties configuration file containing key=value pairs.
140141

141142
Examples:
142143
```bash
@@ -147,4 +148,7 @@ parquet convert input.avro -o output.parquet --conf parquet.avro.write-old-list-
147148
# Multiple options
148149
parquet convert-csv input.csv -o output.parquet --schema schema.avsc --conf parquet.avro.write-parquet-uuid=true --conf parquet.avro.write-old-list-structure=false
149150

151+
# Using config file
152+
parquet convert input.avro -o output.parquet --config-file config.properties
153+
150154
```

parquet-cli/src/main/java/org/apache/parquet/cli/Main.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import com.beust.jcommander.Parameters;
2626
import com.google.common.annotations.VisibleForTesting;
2727
import com.google.common.collect.ImmutableSet;
28+
import java.io.FileInputStream;
29+
import java.io.InputStream;
30+
import java.util.Properties;
2831
import java.util.List;
2932
import java.util.Set;
3033
import org.apache.commons.logging.LogFactory;
@@ -73,6 +76,11 @@ public class Main extends Configured implements Tool {
7376
description = "Set a configuration property (format: key=value). Can be specified multiple times.")
7477
private List<String> confProperties;
7578

79+
@Parameter(
80+
names = {"--config-file"},
81+
description = "Path to a properties configuration file containing key=value pairs.")
82+
private String configFilePath;
83+
7684
@VisibleForTesting
7785
@Parameter(names = "--dollar-zero", description = "A way for the runtime path to be passed in", hidden = true)
7886
String programName = DEFAULT_PROGRAM_NAME;
@@ -172,6 +180,18 @@ public int run(String[] args) throws Exception {
172180
// If the command does not support the configs, it would simply be ignored.
173181
if (command instanceof Configurable) {
174182
Configuration merged = new Configuration(getConf());
183+
184+
if (configFilePath != null) {
185+
try (InputStream in = new FileInputStream(configFilePath)) {
186+
Properties props = new Properties();
187+
props.load(in);
188+
props.forEach((key, value) -> merged.set(key.toString(), value.toString()));
189+
console.debug("Loaded configuration from file: {}", configFilePath);
190+
} catch (Exception e) {
191+
throw new IllegalArgumentException("Failed to load config file '" + configFilePath + "': " + e.getMessage(), e);
192+
}
193+
}
194+
175195
if (confProperties != null) {
176196
for (String prop : confProperties) {
177197
String[] parts = prop.split("=", 2);

parquet-cli/src/test/java/org/apache/parquet/cli/MainTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
*/
1919
package org.apache.parquet.cli;
2020

21+
import java.io.File;
22+
import java.io.FileWriter;
23+
import java.io.IOException;
24+
import org.apache.hadoop.conf.Configurable;
2125
import org.apache.hadoop.conf.Configuration;
2226
import org.apache.hadoop.util.ToolRunner;
2327
import org.junit.Assert;
@@ -31,4 +35,21 @@ public void mainTest() throws Exception {
3135
ToolRunner.run(new Configuration(), new Main(LoggerFactory.getLogger(MainTest.class)), new String[] {});
3236
Assert.assertTrue("we simply verify there are no errors here", true);
3337
}
38+
39+
@Test
40+
public void testConfigFileLoading() throws Exception {
41+
File configFile = File.createTempFile("test-config", ".properties");
42+
configFile.deleteOnExit();
43+
44+
try (FileWriter writer = new FileWriter(configFile)) {
45+
writer.write("test.key=test.value\n");
46+
}
47+
48+
try {
49+
new Main(LoggerFactory.getLogger(MainTest.class)).run(new String[]{"--config-file", configFile.getAbsolutePath(), "help"});
50+
Assert.assertTrue("Config file loading should not throw exception", true);
51+
} catch (IllegalArgumentException e) {
52+
Assert.fail("Config file loading failed: " + e.getMessage());
53+
}
54+
}
3455
}

0 commit comments

Comments
 (0)