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 2019/01/30 22:02:37 UTC

[orc] branch master updated: ORC-463: Add `version` command

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

dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b2b702  ORC-463: Add `version` command
9b2b702 is described below

commit 9b2b7027c120350ed4fae85ec75ba20e6efac442
Author: Dongjoon Hyun <do...@apache.org>
AuthorDate: Sat Jan 26 15:54:16 2019 -0800

    ORC-463: Add `version` command
    
    Fixes #360
    
    Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
 .../src/java/org/apache/orc/tools/Driver.java      |  5 ++-
 .../java/org/apache/orc/tools/PrintVersion.java    | 43 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/java/tools/src/java/org/apache/orc/tools/Driver.java b/java/tools/src/java/org/apache/orc/tools/Driver.java
index 01334c0..3de89b9 100644
--- a/java/tools/src/java/org/apache/orc/tools/Driver.java
+++ b/java/tools/src/java/org/apache/orc/tools/Driver.java
@@ -86,6 +86,7 @@ public class Driver {
           " [--define X=Y] <command> <args>");
       System.err.println();
       System.err.println("Commands:");
+      System.err.println("   version - print the version of this ORC tool");
       System.err.println("   meta - print the metadata about the ORC file");
       System.err.println("   data - print the data from the ORC file");
       System.err.println("   scan - scan the ORC file");
@@ -101,7 +102,9 @@ public class Driver {
     for(Map.Entry pair: confSettings.entrySet()) {
       conf.set(pair.getKey().toString(), pair.getValue().toString());
     }
-    if ("meta".equals(options.command)) {
+    if ("version".equals(options.command)) {
+      PrintVersion.main(conf, options.commandArgs);
+    } else if ("meta".equals(options.command)) {
       FileDump.main(conf, options.commandArgs);
     } else if ("data".equals(options.command)) {
       PrintData.main(conf, options.commandArgs);
diff --git a/java/tools/src/java/org/apache/orc/tools/PrintVersion.java b/java/tools/src/java/org/apache/orc/tools/PrintVersion.java
new file mode 100644
index 0000000..c738c84
--- /dev/null
+++ b/java/tools/src/java/org/apache/orc/tools/PrintVersion.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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.orc.tools;
+
+import org.apache.hadoop.conf.Configuration;
+
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Print the version of this ORC tool.
+ */
+public class PrintVersion {
+  public static final String UNKNOWN = "UNKNOWN";
+  public static final String FILE_NAME = "META-INF/maven/org.apache.orc/orc-tools/pom.properties";
+
+  static void main(Configuration conf, String[] args) throws IOException {
+    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+    try (java.io.InputStream resourceStream = classLoader.getResourceAsStream(FILE_NAME)) {
+      if (resourceStream == null) {
+        throw new IOException("Could not find " + FILE_NAME);
+      }
+      Properties props = new Properties();
+      props.load(resourceStream);
+      System.out.println("ORC " + props.getProperty("version", UNKNOWN));
+    }
+  }
+}