This is an automated email from the ASF dual-hosted git repository.

gangwu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-java.git


The following commit(s) were added to refs/heads/master by this push:
     new 1cda24fea GH-3233: Parquet CLI supports version command (#3234)
1cda24fea is described below

commit 1cda24fea6795244716210811b18303bc7286a0c
Author: Cheng Pan <[email protected]>
AuthorDate: Thu Jun 5 15:17:48 2025 +0000

    GH-3233: Parquet CLI supports version command (#3234)
---
 parquet-cli/README.md                              | 10 +++--
 .../src/main/java/org/apache/parquet/cli/Help.java |  6 ++-
 .../src/main/java/org/apache/parquet/cli/Main.java |  2 +
 .../parquet/cli/commands/ShowVersionCommand.java   | 45 ++++++++++++++++++++++
 .../org/apache/parquet/cli/commands/FileTest.java  | 25 ++++++++++++
 .../cli/commands/ShowVersionCommandTest.java       | 43 +++++++++++++++++++++
 6 files changed, 125 insertions(+), 6 deletions(-)

diff --git a/parquet-cli/README.md b/parquet-cli/README.md
index 92693c00f..9b75efaa1 100644
--- a/parquet-cli/README.md
+++ b/parquet-cli/README.md
@@ -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
@@ -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.
@@ -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
@@ -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.
diff --git a/parquet-cli/src/main/java/org/apache/parquet/cli/Help.java 
b/parquet-cli/src/main/java/org/apache/parquet/cli/Help.java
index dab2c62c6..5a510b246 100644
--- a/parquet-cli/src/main/java/org/apache/parquet/cli/Help.java
+++ b/parquet-cli/src/main/java/org/apache/parquet/cli/Help.java
@@ -25,6 +25,8 @@ import com.beust.jcommander.Parameter;
 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;
 
@@ -116,7 +118,7 @@ public class Help implements Command {
     }
 
     jc.getCommands().keySet().stream()
-        .filter(s -> !s.equals("help"))
+        .filter(s -> !Arrays.asList("version", "help").contains(s))
         .findFirst()
         .ifPresent(command -> {
           console.info("\n  Examples:");
@@ -148,6 +150,6 @@ public class Help implements Command {
 
   @Override
   public List<String> getExamples() {
-    return null;
+    return Collections.emptyList();
   }
 }
diff --git a/parquet-cli/src/main/java/org/apache/parquet/cli/Main.java 
b/parquet-cli/src/main/java/org/apache/parquet/cli/Main.java
index 37e2aabbb..62940054e 100644
--- a/parquet-cli/src/main/java/org/apache/parquet/cli/Main.java
+++ b/parquet-cli/src/main/java/org/apache/parquet/cli/Main.java
@@ -53,6 +53,7 @@ import org.apache.parquet.cli.commands.ShowFooterCommand;
 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;
@@ -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));
diff --git 
a/parquet-cli/src/main/java/org/apache/parquet/cli/commands/ShowVersionCommand.java
 
b/parquet-cli/src/main/java/org/apache/parquet/cli/commands/ShowVersionCommand.java
new file mode 100644
index 000000000..e48202778
--- /dev/null
+++ 
b/parquet-cli/src/main/java/org/apache/parquet/cli/commands/ShowVersionCommand.java
@@ -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();
+  }
+}
diff --git 
a/parquet-cli/src/test/java/org/apache/parquet/cli/commands/FileTest.java 
b/parquet-cli/src/test/java/org/apache/parquet/cli/commands/FileTest.java
index 4b04fbaa9..6e031112f 100644
--- a/parquet-cli/src/test/java/org/apache/parquet/cli/commands/FileTest.java
+++ b/parquet-cli/src/test/java/org/apache/parquet/cli/commands/FileTest.java
@@ -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 {
 
@@ -52,4 +57,24 @@ public abstract class FileTest {
         .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();
+    }
+  }
 }
diff --git 
a/parquet-cli/src/test/java/org/apache/parquet/cli/commands/ShowVersionCommandTest.java
 
b/parquet-cli/src/test/java/org/apache/parquet/cli/commands/ShowVersionCommandTest.java
new file mode 100644
index 000000000..7eff9ad74
--- /dev/null
+++ 
b/parquet-cli/src/test/java/org/apache/parquet/cli/commands/ShowVersionCommandTest.java
@@ -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();
+  }
+}

Reply via email to