Skip to content

Commit af7c33d

Browse files
committed
update
1 parent af71b7c commit af7c33d

File tree

5 files changed

+109
-7
lines changed

5 files changed

+109
-7
lines changed

parquet-cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +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.
140+
- `--config-file`: Path to a configuration file (`.properties` or `.xml` format).
141141

142142
Examples:
143143
```bash

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.hadoop.conf.Configurable;
3535
import org.apache.hadoop.conf.Configuration;
3636
import org.apache.hadoop.conf.Configured;
37+
import org.apache.hadoop.fs.Path;
3738
import org.apache.hadoop.util.Tool;
3839
import org.apache.hadoop.util.ToolRunner;
3940
import org.apache.log4j.Level;
@@ -78,7 +79,7 @@ public class Main extends Configured implements Tool {
7879

7980
@Parameter(
8081
names = {"--config-file"},
81-
description = "Path to a properties configuration file containing key=value pairs.")
82+
description = "Path to a configuration file (properties or Hadoop XML format).")
8283
private String configFilePath;
8384

8485
@VisibleForTesting
@@ -182,11 +183,16 @@ public int run(String[] args) throws Exception {
182183
Configuration merged = new Configuration(getConf());
183184

184185
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);
186+
try {
187+
if (isXmlConfigFile(configFilePath)) {
188+
loadXmlConfiguration(merged, configFilePath);
189+
} else if (isPropertiesConfigFile(configFilePath)) {
190+
loadPropertiesConfiguration(merged, configFilePath);
191+
} else {
192+
throw new IllegalArgumentException(
193+
"Unsupported config file format. Only .xml and .properties files are supported: "
194+
+ configFilePath);
195+
}
190196
} catch (Exception e) {
191197
throw new IllegalArgumentException(
192198
"Failed to load config file '" + configFilePath + "': " + e.getMessage(), e);
@@ -239,4 +245,27 @@ public static void main(String[] args) throws Exception {
239245
int rc = ToolRunner.run(new Configuration(), new Main(console), args);
240246
System.exit(rc);
241247
}
248+
249+
private boolean isXmlConfigFile(String filePath) {
250+
return filePath.toLowerCase().endsWith(".xml");
251+
}
252+
253+
private boolean isPropertiesConfigFile(String filePath) {
254+
String lowerPath = filePath.toLowerCase();
255+
return lowerPath.endsWith(".properties");
256+
}
257+
258+
private void loadXmlConfiguration(Configuration config, String filePath) {
259+
config.addResource(new Path(filePath));
260+
console.debug("Loaded XML configuration from file: {}", filePath);
261+
}
262+
263+
private void loadPropertiesConfiguration(Configuration config, String filePath) throws Exception {
264+
try (InputStream in = new FileInputStream(filePath)) {
265+
Properties props = new Properties();
266+
props.load(in);
267+
props.forEach((key, value) -> config.set(key.toString(), value.toString()));
268+
console.debug("Loaded properties configuration from file: {}", filePath);
269+
}
270+
}
242271
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,20 @@ public void testConfigFileLoading() throws Exception {
5151
Assert.fail("Config file loading failed: " + e.getMessage());
5252
}
5353
}
54+
55+
@Test
56+
public void testLocalPropertiesFile() throws Exception {
57+
String configFile = getClass().getResource("/test-config.properties").getPath();
58+
ToolRunner.run(new Configuration(), new Main(LoggerFactory.getLogger(MainTest.class)), new String[] {
59+
"--config-file", configFile, "version"
60+
});
61+
}
62+
63+
@Test
64+
public void testLocalXmlFile() throws Exception {
65+
String configFile = getClass().getResource("/test-config.xml").getPath();
66+
ToolRunner.run(new Configuration(), new Main(LoggerFactory.getLogger(MainTest.class)), new String[] {
67+
"--config-file", configFile, "version"
68+
});
69+
}
5470
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
test.key=test.value
19+
parquet.avro.write-old-list-structure=false
20+
parquet.compression=SNAPPY
21+
parquet.block.size=134217728
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<configuration>
21+
<property>
22+
<name>test.key</name>
23+
<value>test.value</value>
24+
</property>
25+
26+
<property>
27+
<name>parquet.avro.write-old-list-structure</name>
28+
<value>false</value>
29+
</property>
30+
31+
<property>
32+
<name>parquet.compression</name>
33+
<value>SNAPPY</value>
34+
</property>
35+
36+
</configuration>

0 commit comments

Comments
 (0)