hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sp...@apache.org
Subject hive git commit: HIVE-13964: Add a parameter to beeline to allow a properties file to be passed in (Abdullah Yousufi, reviewed by Sergio Pena)
Date Mon, 20 Jun 2016 18:23:58 GMT
Repository: hive
Updated Branches:
  refs/heads/master 60311c6d3 -> 30a96a47b


HIVE-13964: Add a parameter to beeline to allow a properties file to be passed in (Abdullah
Yousufi, reviewed by Sergio Pena)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/30a96a47
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/30a96a47
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/30a96a47

Branch: refs/heads/master
Commit: 30a96a47b5105e55a974979050b7c7982015e927
Parents: 60311c6
Author: Abdullah Yousufi <abdullah.yousufi@cloudera.com>
Authored: Mon Jun 20 13:22:37 2016 -0500
Committer: Sergio Pena <sergio.pena@cloudera.com>
Committed: Mon Jun 20 13:22:37 2016 -0500

----------------------------------------------------------------------
 .../java/org/apache/hive/beeline/BeeLine.java   | 27 ++++++++++++++++----
 beeline/src/main/resources/BeeLine.properties   |  1 +
 .../hive/beeline/TestBeelineArgParsing.java     | 14 +++++++++-
 3 files changed, 36 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/30a96a47/beeline/src/java/org/apache/hive/beeline/BeeLine.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
index ba7da70..457a884 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -152,6 +152,7 @@ public class BeeLine implements Closeable {
 
   private static final String HIVE_VAR_PREFIX = "--hivevar";
   private static final String HIVE_CONF_PREFIX = "--hiveconf";
+  private static final String PROP_FILE_PREFIX = "--property-file";
   static final String PASSWD_MASK = "[passwd stripped]";
 
   private final Map<Object, Object> formats = map(new Object[] {
@@ -377,6 +378,13 @@ public class BeeLine implements Closeable {
         .withLongOpt("hiveconf")
         .withDescription("Use value for given property")
         .create());
+
+    // --property-file <file>
+    options.addOption(OptionBuilder
+        .hasArg()
+        .withLongOpt("property-file")
+        .withDescription("the file to read configuration properties from")
+        .create());
   }
 
 
@@ -624,7 +632,8 @@ public class BeeLine implements Closeable {
 
     @Override
     protected void processOption(final String arg, final ListIterator iter) throws  ParseException
{
-      if ((arg.startsWith("--")) && !(arg.equals(HIVE_VAR_PREFIX) || (arg.equals(HIVE_CONF_PREFIX))
|| (arg.equals("--help")))) {
+      if ((arg.startsWith("--")) && !(arg.equals(HIVE_VAR_PREFIX) || (arg.equals(HIVE_CONF_PREFIX))
+          || (arg.equals("--help") || (arg.equals(PROP_FILE_PREFIX))))) {
         String stripped = arg.substring(2, arg.length());
         String[] parts = split(stripped, "=");
         debug(loc("setting-prop", Arrays.asList(parts)));
@@ -702,7 +711,6 @@ public class BeeLine implements Closeable {
 
   int initArgs(String[] args) {
     List<String> commands = Collections.emptyList();
-    List<String> files = Collections.emptyList();
 
     CommandLine cl;
     BeelineParser beelineParser;
@@ -773,9 +781,18 @@ public class BeeLine implements Closeable {
       dispatch(com);
     }
 
-    // now load properties files
-    for (Iterator<String> i = files.iterator(); i.hasNext();) {
-      dispatch("!properties " + i.next());
+    // load property file
+    String propertyFile = cl.getOptionValue("property-file");
+    if (propertyFile != null) {
+      try {
+        this.consoleReader = new ConsoleReader();
+      } catch (IOException e) {
+        handleException(e);
+      }
+      if (!dispatch("!properties " + propertyFile)) {
+        exit = true;
+        return 1;
+      }
     }
 
     int code = 0;

http://git-wip-us.apache.org/repos/asf/hive/blob/30a96a47/beeline/src/main/resources/BeeLine.properties
----------------------------------------------------------------------
diff --git a/beeline/src/main/resources/BeeLine.properties b/beeline/src/main/resources/BeeLine.properties
index d85ef65..7500df9 100644
--- a/beeline/src/main/resources/BeeLine.properties
+++ b/beeline/src/main/resources/BeeLine.properties
@@ -159,6 +159,7 @@ cmd-usage: Usage: java org.apache.hive.cli.beeline.BeeLine \n \
 \                                  This is Hive specific settings in which variables\n \
 \                                  can be set at session level and referenced in Hive\n \
 \                                  commands or queries.\n \
+\  --property-file=<property-file> the file to read connection properties (url, driver,
user, password) from\n \
 \  --color=[true/false]            control whether color is used for display\n \
 \  --showHeader=[true/false]       show column names in query results\n \
 \  --headerInterval=ROWS;          the interval between which heades are displayed\n \

http://git-wip-us.apache.org/repos/asf/hive/blob/30a96a47/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
----------------------------------------------------------------------
diff --git a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
index 80c6e06..d27c949 100644
--- a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
+++ b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
@@ -70,7 +70,7 @@ public class TestBeelineArgParsing {
     @Override
     boolean dispatch(String command) {
       String connectCommand = "!connect";
-      String propertyCommand = "!property";
+      String propertyCommand = "!properties";
       if (command.startsWith(connectCommand)) {
         this.connectArgs = command.substring(connectCommand.length() + 1, command.length());
       } else if (command.startsWith(propertyCommand)) {
@@ -260,4 +260,16 @@ public class TestBeelineArgParsing {
     String errContents = new String(Files.readAllBytes(Paths.get(errFile.toString())));
     Assert.assertTrue(errContents.contains(BeeLine.PASSWD_MASK));
   }
+
+  /**
+   * Test property file parameter option.
+   */
+  @Test
+  public void testPropertyFile() throws Exception {
+    TestBeeline bl = new TestBeeline();
+    String args[] = new String[] {"--property-file", "props"};
+    Assert.assertEquals(0, bl.initArgs(args));
+    Assert.assertTrue(bl.properties.get(0).equals("props"));
+    bl.close();
+  }
 }


Mime
View raw message