commit e345995c34a3f6934001d93044f7f057fe7d4a52 Author: Abdullah Yousufi Date: Tue Jun 7 14:53:00 2016 -0700 HIVE-13964: Add a beeline --property-file parameter diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index 734eeb8db285c609303f5fd675d9592485dfa29a..f5edb658601034adf2598499cca3419979f01c92 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -151,6 +151,7 @@ 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 formats = map(new Object[] { @@ -376,6 +377,13 @@ .withLongOpt("hiveconf") .withDescription("Use value for given property") .create()); + + // --property-file + options.addOption(OptionBuilder + .hasArg() + .withLongOpt("property-file") + .withDescription("the file to read configuration properties from") + .create()); } @@ -623,7 +631,8 @@ ColorBuffer getColorBuffer(String msg) { @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))); @@ -633,7 +642,7 @@ protected void processOption(final String arg, final ListIterator iter) throws getOpts().set(parts[0], "true", true); } } else { - super.processOption(arg, iter); + super.processOption(arg, iter); } } } @@ -701,7 +710,6 @@ int initArgsFromCliVars(String[] args) { int initArgs(String[] args) { List commands = Collections.emptyList(); - List files = Collections.emptyList(); CommandLine cl; BeelineParser beelineParser; @@ -772,9 +780,10 @@ int initArgs(String[] args) { dispatch(com); } - // now load properties files - for (Iterator i = files.iterator(); i.hasNext();) { - dispatch("!properties " + i.next()); + // load property file + String propertyFile = cl.getOptionValue("property-file"); + if(propertyFile != null){ + dispatch("!properties " + propertyFile); } int code = 0; diff --git a/beeline/src/main/resources/BeeLine.properties b/beeline/src/main/resources/BeeLine.properties index e940a7d065d650702f59a142d80a9a325f5c521b..245e8a1313e6f90045d4e79b5b9b7ccfd9d5cd8f 100644 --- a/beeline/src/main/resources/BeeLine.properties +++ b/beeline/src/main/resources/BeeLine.properties @@ -157,6 +157,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= the file to read properties 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 \ diff --git a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java index 80c6e06a23e0a8dd12b9342d803adeaf8fbf3f61..d27c949113b09ce126f6d29d2e30f8fdd5a583b8 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 TestBeelineArgParsing(String connectionString, String driverClazzName, St @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 void testBeelinePasswordMask() throws Exception { 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(); + } }