Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions parquet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ You can build this project using maven:
The build produces a shaded Jar that can be run using the `hadoop` command:

```
hadoop jar parquet-cli-1.12.3-runtime.jar org.apache.parquet.cli.Main
hadoop jar parquet-cli-1.16.0-runtime.jar org.apache.parquet.cli.Main
```

For a shorter command-line invocation, add an alias to your shell like this:

```
alias parquet="hadoop jar /path/to/parquet-cli-1.12.3-runtime.jar org.apache.parquet.cli.Main --dollar-zero parquet"
alias parquet="hadoop jar /path/to/parquet-cli-1.16.0-runtime.jar org.apache.parquet.cli.Main --dollar-zero parquet"
```

### Running without Hadoop
Expand All @@ -51,7 +51,7 @@ To run from the target directory instead of using the `hadoop` command, first co
Then, run the command-line and add `target/dependencies/*` to the classpath:

```
java -cp 'target/parquet-cli-1.12.3.jar:target/dependency/*' org.apache.parquet.cli.Main
java -cp 'target/parquet-cli-1.16.0.jar:target/dependency/*' org.apache.parquet.cli.Main
```

Note that you shouldn't include the runtime jar used above into the classpath in this case.
Expand Down Expand Up @@ -79,6 +79,8 @@ Usage: parquet [options] [command] [command options]

help
Retrieves details on the functions of other commands
version
Print version of the Parquet CLI tool
meta
Print a Parquet file's metadata
pages
Expand Down Expand Up @@ -126,7 +128,7 @@ Usage: parquet [options] [command] [command options]

Examples:

# print information for create
# print information for meta
parquet help meta

See 'parquet help <command>' for more information on a specific command.
Expand Down
6 changes: 4 additions & 2 deletions parquet-cli/src/main/java/org/apache/parquet/cli/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.beust.jcommander.ParameterDescription;
import com.beust.jcommander.Parameters;
import com.google.common.collect.Lists;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;

Expand Down Expand Up @@ -116,7 +118,7 @@ public void printGenericHelp() {
}

jc.getCommands().keySet().stream()
.filter(s -> !s.equals("help"))
.filter(s -> !Arrays.asList("version", "help").contains(s))
.findFirst()
.ifPresent(command -> {
console.info("\n Examples:");
Expand Down Expand Up @@ -148,6 +150,6 @@ private String formatDefault(ParameterDescription param) {

@Override
public List<String> getExamples() {
return null;
return Collections.emptyList();
}
}
2 changes: 2 additions & 0 deletions parquet-cli/src/main/java/org/apache/parquet/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.parquet.cli.commands.ShowGeospatialStatisticsCommand;
import org.apache.parquet.cli.commands.ShowPagesCommand;
import org.apache.parquet.cli.commands.ShowSizeStatisticsCommand;
import org.apache.parquet.cli.commands.ShowVersionCommand;
import org.apache.parquet.cli.commands.ToAvroCommand;
import org.apache.parquet.cli.commands.TransCompressionCommand;
import org.slf4j.Logger;
Expand Down Expand Up @@ -87,6 +88,7 @@ public class Main extends Configured implements Tool {
this.help = new Help(jc, console);
jc.setProgramName(DEFAULT_PROGRAM_NAME);
jc.addCommand("help", help, "-h", "-help", "--help");
jc.addCommand("version", new ShowVersionCommand(console), "-version", "--version");
jc.addCommand("meta", new ParquetMetadataCommand(console));
jc.addCommand("pages", new ShowPagesCommand(console));
jc.addCommand("dictionary", new ShowDictionaryCommand(console));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.parquet.cli.commands;

import com.beust.jcommander.Parameters;
import java.util.Collections;
import java.util.List;
import org.apache.parquet.Version;
import org.apache.parquet.cli.BaseCommand;
import org.slf4j.Logger;

@Parameters(commandDescription = "Print version of the Parquet CLI tool")
public class ShowVersionCommand extends BaseCommand {

public ShowVersionCommand(Logger console) {
super(console);
}

@Override
public int run() {
console.info(Version.FULL_VERSION);
return 0;
}

@Override
public List<String> getExamples() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
package org.apache.parquet.cli.commands;

import java.io.File;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.LoggingEvent;
import org.slf4j.event.SubstituteLoggingEvent;
import org.slf4j.helpers.SubstituteLoggerFactory;

public abstract class FileTest {

Expand Down Expand Up @@ -52,4 +57,24 @@ protected static Logger createLogger() {
.setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
return console;
}

@FunctionalInterface
public interface ThrowableBiConsumer<T, U> {
void accept(T t, U u) throws Exception;
}

protected static void withLogger(ThrowableBiConsumer<Logger, Queue<? extends LoggingEvent>> body) {
SubstituteLoggerFactory loggerFactory = new SubstituteLoggerFactory();
LinkedBlockingQueue<SubstituteLoggingEvent> loggingEvents = loggerFactory.getEventQueue();
Logger console = loggerFactory.getLogger(ParquetFileTest.class.getName());
try {
body.accept(console, loggingEvents);
} catch (RuntimeException rethrow) {
throw rethrow;
} catch (Exception checkedException) {
throw new RuntimeException(checkedException);
} finally {
loggerFactory.clear();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.parquet.cli.commands;

import java.util.Queue;
import org.apache.parquet.Version;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.event.LoggingEvent;

public class ShowVersionCommandTest extends FileTest {

@Test
public void testVersionCommand() {
withLogger(this::testVersionCommand0);
}

private void testVersionCommand0(Logger console, Queue<? extends LoggingEvent> loggingEvents) {
ShowVersionCommand command = new ShowVersionCommand(console);
Assert.assertEquals(0, command.run());
Assert.assertEquals(1, loggingEvents.size());
LoggingEvent loggingEvent = loggingEvents.remove();
Assert.assertEquals(Version.FULL_VERSION, loggingEvent.getMessage());
loggingEvents.clear();
}
}