diff --git bin/ext/cli.sh bin/ext/cli.sh index 054d1e8..914aae3 100644 --- bin/ext/cli.sh +++ bin/ext/cli.sh @@ -1,3 +1,18 @@ +# 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. + THISSERVICE=cli export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " @@ -7,8 +22,7 @@ cli () { } cli_help () { - echo "usage ./hive [-e 'hql'| -f file ] " - echo " -e 'hwl' : execute specified query" - echo " -f file : exeute query in file" + CLASS=org.apache.hadoop.hive.cli.CliDriver + execHiveCmd $CLASS "--help" } diff --git bin/ext/help.sh bin/ext/help.sh index 6d1e484..432859a 100644 --- bin/ext/help.sh +++ bin/ext/help.sh @@ -1,3 +1,18 @@ +# 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. + THISSERVICE=help export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " diff --git bin/ext/hiveserver.sh bin/ext/hiveserver.sh index d8f6657..b5edce4 100644 --- bin/ext/hiveserver.sh +++ bin/ext/hiveserver.sh @@ -1,3 +1,18 @@ +# 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. + THISSERVICE=hiveserver export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " @@ -9,29 +24,8 @@ hiveserver() { fi JAR=${HIVE_LIB}/hive-service-*.jar - version=$($HADOOP version | awk '{if (NR == 1) {print $2;}}'); - - # Save the regex to a var to workaround quoting incompatabilities - # between Bash 3.1 and 3.2 - version_re="^([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?.*$" - - if [[ "$version" =~ $version_re ]]; then - major_ver=${BASH_REMATCH[1]} - minor_ver=${BASH_REMATCH[2]} - patch_ver=${BASH_REMATCH[4]} - else - echo "Unable to determine Hadoop version information." - echo "'hadoop version' returned:" - echo `$HADOOP version` - exit 6 - fi - - if [ $minor_ver -lt 20 ]; then - exec $HADOOP jar $AUX_JARS_CMD_LINE $JAR $CLASS $HIVE_PORT "$@" - else - # hadoop 20 or newer - skip the aux_jars option and hiveconf - exec $HADOOP jar $JAR $CLASS $HIVE_PORT "$@" - fi + # hadoop 20 or newer - skip the aux_jars option and hiveconf + exec $HADOOP jar $JAR $CLASS $HIVE_PORT "$@" } hiveserver_help() { diff --git bin/ext/hwi.sh bin/ext/hwi.sh index 74de9ad..f9cd8ec 100644 --- bin/ext/hwi.sh +++ bin/ext/hwi.sh @@ -1,3 +1,18 @@ +# 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. + THISSERVICE=hwi export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " @@ -24,32 +39,10 @@ hwi() { HADOOP_CLASSPATH=${HADOOP_CLASSPATH}:$f done - version=$($HADOOP version | awk '{if (NR == 1) {print $2;}}'); - # Save the regex to a var to workaround quoting incompatabilities - # between Bash 3.1 and 3.2 - version_re="^([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?.*$" - - if [[ "$version" =~ $version_re ]]; then - major_ver=${BASH_REMATCH[1]} - minor_ver=${BASH_REMATCH[2]} - patch_ver=${BASH_REMATCH[4]} - else - echo "Unable to determine Hadoop version information." - echo "'hadoop version' returned:" - echo `$HADOOP version` - exit 6 - fi - export HADOOP_CLASSPATH - if [ $minor_ver -lt 20 ]; then - exec $HADOOP jar $AUX_JARS_CMD_LINE ${HWI_JAR_FILE} $CLASS $HIVE_OPTS "$@" - else - # hadoop 20 or newer - skip the aux_jars option and hiveconf - exec $HADOOP jar ${HWI_JAR_FILE} $CLASS $HIVE_OPTS "$@" - fi - #nohup $HADOOP jar $AUX_JARS_CMD_LINE ${HWI_JAR_FILE} $CLASS $HIVE_OPTS "$@" >/dev/null 2>/dev/null & - + # hadoop 20 or newer - skip the aux_jars option and hiveconf + exec $HADOOP jar ${HWI_JAR_FILE} $CLASS $HIVE_OPTS "$@" } hwi_help(){ diff --git bin/ext/jar.sh bin/ext/jar.sh index d16aa4c..b52f9a7 100644 --- bin/ext/jar.sh +++ bin/ext/jar.sh @@ -27,23 +27,6 @@ jar () { HIVE_LIB=`cygpath -w "$HIVE_LIB"` fi - version=$($HADOOP version | awk '{if (NR == 1) {print $2;}}'); - - # Save the regex to a var to workaround quoting incompatabilities - # between Bash 3.1 and 3.2 - version_re="^([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?.*$" - - if [[ "$version" =~ $version_re ]]; then - major_ver=${BASH_REMATCH[1]} - minor_ver=${BASH_REMATCH[2]} - patch_ver=${BASH_REMATCH[4]} - else - echo "Unable to determine Hadoop version information." - echo "'hadoop version' returned:" - echo `$HADOOP version` - exit 6 - fi - if [ -z "$RUNJAR" ] ; then echo "RUNJAR not specified" exit 3 @@ -54,12 +37,8 @@ jar () { exit 3 fi - if [ $minor_ver -lt 20 ]; then - exec $HADOOP jar $AUX_JARS_CMD_LINE $RUNJAR $RUNCLASS $HIVE_OPTS "$@" - else - # hadoop 20 or newer - skip the aux_jars option and hiveconf - exec $HADOOP jar $RUNJAR $RUNCLASS $HIVE_OPTS "$@" - fi + # hadoop 20 or newer - skip the aux_jars option and hiveconf + exec $HADOOP jar $RUNJAR $RUNCLASS $HIVE_OPTS "$@" } jar_help () { diff --git bin/ext/metastore.sh bin/ext/metastore.sh index a894f7f..db15f6e 100644 --- bin/ext/metastore.sh +++ bin/ext/metastore.sh @@ -1,3 +1,18 @@ +# 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. + THISSERVICE=metastore export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " @@ -9,29 +24,8 @@ metastore() { fi JAR=${HIVE_LIB}/hive-service-*.jar - version=$($HADOOP version | awk '{if (NR == 1) {print $2;}}'); - - # Save the regex to a var to workaround quoting incompatabilities - # between Bash 3.1 and 3.2 - version_re="^([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?.*$" - - if [[ "$version" =~ $version_re ]]; then - major_ver=${BASH_REMATCH[1]} - minor_ver=${BASH_REMATCH[2]} - patch_ver=${BASH_REMATCH[4]} - else - echo "Unable to determine Hadoop version information." - echo "'hadoop version' returned:" - echo `$HADOOP version` - exit 6 - fi - - if [ $minor_ver -lt 20 ]; then - exec $HADOOP jar $AUX_JARS_CMD_LINE $JAR $CLASS $METASTORE_PORT "$@" - else - # hadoop 20 or newer - skip the aux_jars option and hiveconf - exec $HADOOP jar $JAR $CLASS $METASTORE_PORT "$@" - fi + # hadoop 20 or newer - skip the aux_jars option and hiveconf + exec $HADOOP jar $JAR $CLASS $METASTORE_PORT "$@" } metastore_help() { diff --git bin/ext/rcfilecat.sh bin/ext/rcfilecat.sh index 21d515c..3a9264b 100644 --- bin/ext/rcfilecat.sh +++ bin/ext/rcfilecat.sh @@ -1,3 +1,18 @@ +# 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. + THISSERVICE=rcfilecat export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " diff --git bin/ext/util/execHiveCmd.sh bin/ext/util/execHiveCmd.sh index 61b8635..7871a7d 100644 --- bin/ext/util/execHiveCmd.sh +++ bin/ext/util/execHiveCmd.sh @@ -1,3 +1,18 @@ +# 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. + execHiveCmd () { CLASS=$1; shift; @@ -12,28 +27,6 @@ execHiveCmd () { HIVE_LIB=`cygpath -w "$HIVE_LIB"` fi - version=$($HADOOP version | awk '{if (NR == 1) {print $2;}}'); - - # Save the regex to a var to workaround quoting incompatabilities - # between Bash 3.1 and 3.2 - version_re="^([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?.*$" - - if [[ "$version" =~ $version_re ]]; then - major_ver=${BASH_REMATCH[1]} - minor_ver=${BASH_REMATCH[2]} - patch_ver=${BASH_REMATCH[4]} - else - echo "Unable to determine Hadoop version information." - echo "'hadoop version' returned:" - echo `$HADOOP version` - exit 6 - fi - - if [ $minor_ver -lt 20 ]; then - exec $HADOOP jar $AUX_JARS_CMD_LINE ${HIVE_LIB}/hive-cli-*.jar $CLASS $HIVE_OPTS "$@" - else - # hadoop 20 or newer - skip the aux_jars option. picked up from hiveconf - exec $HADOOP jar ${HIVE_LIB}/hive-cli-*.jar $CLASS $HIVE_OPTS "$@" - fi - + # hadoop 20 or newer - skip the aux_jars option. picked up from hiveconf + exec $HADOOP jar ${HIVE_LIB}/hive-cli-*.jar $CLASS $HIVE_OPTS "$@" } diff --git bin/hive bin/hive index c0eba07..f9a7f69 100755 --- bin/hive +++ bin/hive @@ -155,6 +155,31 @@ if [ ! -f ${HADOOP} ]; then exit 4; fi +# Make sure we're using a compatible version of Hadoop +hadoop_version=$($HADOOP version | awk '{if (NR == 1) {print $2;}}'); + +# Save the regex to a var to workaround quoting incompatabilities +# between Bash 3.1 and 3.2 +hadoop_version_re="^([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?.*$" + +if [[ "$hadoop_version" =~ $hadoop_version_re ]]; then + hadoop_major_ver=${BASH_REMATCH[1]} + hadoop_minor_ver=${BASH_REMATCH[2]} + hadoop_patch_ver=${BASH_REMATCH[4]} +else + echo "Unable to determine Hadoop version information." + echo "'hadoop version' returned:" + echo `$HADOOP version` + exit 5 +fi + +if [ $hadoop_minor_ver -ne 20 -o $hadoop_patch_ver -eq 0 ]; then + echo "Hive requires Hadoop 0.20.x (x >= 1)." + echo "'hadoop version' returned:" + echo `$HADOOP version` + exit 6 +fi + if [ "${AUX_PARAM}" != "" ]; then HIVE_OPTS="$HIVE_OPTS -hiveconf hive.aux.jars.path=${AUX_PARAM}" AUX_JARS_CMD_LINE="-libjars ${AUX_PARAM}" @@ -180,7 +205,7 @@ done if [ "$TORUN" = "" ] ; then echo "Service $SERVICE not found" echo "Available Services: $SERVICE_LIST" - exit 5 + exit 7 else $TORUN "$@" fi diff --git bin/hive-config.sh bin/hive-config.sh index f474189..c8fdc1a 100644 --- bin/hive-config.sh +++ bin/hive-config.sh @@ -1,4 +1,3 @@ - # 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. @@ -67,3 +66,4 @@ export HIVE_AUX_JARS_PATH=$HIVE_AUX_JARS_PATH # Default to use 256MB export HADOOP_HEAPSIZE=${HADOOP_HEAPSIZE:-256} + diff --git build-common.xml build-common.xml index dac20d4..852a668 100644 --- build-common.xml +++ build-common.xml @@ -272,7 +272,7 @@ - + + - + + diff --git cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java index 0346060..e8d46a9 100644 --- cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java +++ cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java @@ -18,175 +18,81 @@ package org.apache.hadoop.hive.cli; -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; - -import org.apache.commons.cli2.Argument; -import org.apache.commons.cli2.CommandLine; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.OptionException; -import org.apache.commons.cli2.WriteableCommandLine; -import org.apache.commons.cli2.builder.ArgumentBuilder; -import org.apache.commons.cli2.builder.DefaultOptionBuilder; -import org.apache.commons.cli2.builder.GroupBuilder; -import org.apache.commons.cli2.commandline.Parser; -import org.apache.commons.cli2.option.PropertyOption; -import org.apache.commons.cli2.resource.ResourceConstants; +import java.util.Arrays; +import java.util.Properties; + +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * OptionsProcessor. - * + * */ public class OptionsProcessor { - protected static final Log l4j = LogFactory.getLog(OptionsProcessor.class.getName()); + private final Options options = new Options(); + private org.apache.commons.cli.CommandLine commandLine; - private final Parser parser = new Parser(); - private final Option confOptions, initFilesOption, isSilentOption, - execOption, fileOption, isHelpOption, isVerboseOption; - - /** - * Shamelessly cloned from Hadoop streaming take in multiple -hiveconf x=y parameters. - */ - class MultiPropertyOption extends PropertyOption { - private String optionString; - private boolean keyValue; - - MultiPropertyOption() { - super(); - } - - MultiPropertyOption(final String optionString, final String description, final int id, boolean keyValue) { - super(optionString, description, id); - this.optionString = optionString; - this.keyValue = keyValue; - } - - @Override - public boolean canProcess(final WriteableCommandLine commandLine, final String argument) { - boolean ret = (argument != null) && argument.startsWith(optionString); - - return ret; - } - - @Override - public void process(final WriteableCommandLine commandLine, final ListIterator arguments) - throws OptionException { - final String arg = (String) arguments.next(); - - if (!canProcess(commandLine, arg)) { - throw new OptionException(this, ResourceConstants.UNEXPECTED_TOKEN, arg); - } - - ArrayList properties = new ArrayList(); - String next = ""; - while (arguments.hasNext()) { - next = (String) arguments.next(); - if (!next.startsWith("-")) { - - if (keyValue && (next.indexOf("=") == -1)) { - throw new OptionException(this, ResourceConstants.UNEXPECTED_TOKEN, "argument: '" - + next + "' is not of the form x=y"); - } - properties.add(next); - } else { - arguments.previous(); - break; - } - } - - // add to any existing values (support specifying args multiple times) - List oldVal = (List) commandLine.getValue(this); - if (oldVal == null) { - commandLine.addValue(this, properties); - } else { - oldVal.addAll(properties); - } - } - } - - private Option createBoolOption(DefaultOptionBuilder builder, String longName, String shortName, - String desc) { - builder.reset(); - if (longName == null) { - return builder.withShortName(shortName).withDescription(desc).create(); - } else { - return builder.withShortName(shortName).withLongName(longName).withDescription(desc).create(); - } - } - - private Option createOptionWithArg(DefaultOptionBuilder builder, String longName, - String shortName, String desc, Argument arg) { - builder.reset(); - - DefaultOptionBuilder dob = builder.withShortName(shortName).withArgument(arg).withDescription( - desc); - - if (longName != null) { - dob = dob.withLongName(longName); - } - - return dob.create(); - } + @SuppressWarnings("static-access") public OptionsProcessor() { - DefaultOptionBuilder builder = new DefaultOptionBuilder("-", "-", false); - - ArgumentBuilder argBuilder = new ArgumentBuilder(); - - // -e - execOption = createOptionWithArg(builder, "exec", "e", "execute the following command", - argBuilder.withMinimum(1).withMaximum(1).create()); - - // -f - fileOption = createOptionWithArg(builder, "file", "f", - "execute commands from the following file", argBuilder.withMinimum(1).withMaximum(1) - .create()); - - // -S - isSilentOption = createBoolOption(builder, "silent", "S", "silent mode"); - // -v - isVerboseOption = createBoolOption(builder, "verbose", "v", "verbose mode"); - - // -help - isHelpOption = createBoolOption(builder, "help", "h", "help"); - - // -hiveconf var=val - confOptions = new MultiPropertyOption("-hiveconf", - "(n=v) Optional. Add or override Hive/Hadoop properties.", 'D', true); - - initFilesOption = new MultiPropertyOption( - "-i", "File to run before other commands", 'I', false); - - new PropertyOption(); - Group allOptions = - new GroupBuilder().withOption(confOptions).withOption(initFilesOption) - .withOption(isSilentOption).withOption(isHelpOption) - .withOption(execOption).withOption(fileOption) - .withOption(isVerboseOption).create(); - parser.setGroup(allOptions); + // -e 'quoted-query-string' + options.addOption(OptionBuilder + .hasArg() + .withArgName("quoted-query-string") + .withDescription("SQL from command line") + .create('e')); + + // -f + options.addOption(OptionBuilder + .hasArg() + .withArgName("filename") + .withDescription("SQL from files") + .create('f')); + + // -i + options.addOption(OptionBuilder + .hasArg() + .withArgName("filename") + .withDescription("Initialization SQL file") + .create('i')); + + // -hiveconf x=y + options.addOption(OptionBuilder + .withValueSeparator() + .hasArgs(2) + .withArgName("property=value") + .withLongOpt("hiveconf") + .withDescription("Use value for given property") + .create()); + + // [-S|--silent] + options.addOption(new Option("S", "silent", false, "Silent mode in interactive shell")); + + // [-v|--verbose] + options.addOption(new Option("v", "verbose", false, "Verbose mode (echo executed SQL to the console)")); + + // [-h|--help] + options.addOption(new Option("h", "help", false, "Print help information")); } - private CommandLine cmdLine; - public boolean process_stage1(String[] argv) { try { - cmdLine = parser.parse(argv); - - List hiveConfArgs = (List) cmdLine.getValue(confOptions); - if (null != hiveConfArgs) { - for (String s : hiveConfArgs) { - String[] parts = s.split("=", 2); - System.setProperty(parts[0], parts[1]); - } + commandLine = new GnuParser().parse(options, argv); + Properties confProps = commandLine.getOptionProperties("hiveconf"); + for (String propKey : confProps.stringPropertyNames()) { + System.setProperty(propKey, confProps.getProperty(propKey)); } - } catch (OptionException oe) { - System.err.println(oe.getMessage()); + } catch (ParseException e) { + System.err.println(e.getMessage()); + printUsage(); return false; } return true; @@ -194,58 +100,42 @@ public class OptionsProcessor { public boolean process_stage2(CliSessionState ss) { ss.getConf(); - // -S - ss.setIsSilent(cmdLine.hasOption(isSilentOption)); - // -e - ss.execString = (String) cmdLine.getValue(execOption); - // -f - ss.fileName = (String) cmdLine.getValue(fileOption); - // -v - ss.setIsVerbose(cmdLine.hasOption(isVerboseOption)); - // -i - List initFiles = (List) cmdLine.getValue(initFilesOption); - if (null != initFiles) { - ss.initFiles = initFiles; - } - // -h - if (cmdLine.hasOption(isHelpOption)) { - printUsage(null); + + if (commandLine.hasOption('h')) { + printUsage(); return false; } + + ss.setIsSilent(commandLine.hasOption('S')); + + ss.execString = commandLine.getOptionValue('e'); + + ss.fileName = commandLine.getOptionValue('f'); + + ss.setIsVerbose(commandLine.hasOption('v')); + + String[] initFiles = commandLine.getOptionValues('i'); + if (null != initFiles) { + ss.initFiles = Arrays.asList(initFiles); + } + if (ss.execString != null && ss.fileName != null) { - printUsage("-e and -f option cannot be specified simultaneously"); + System.err.println("The '-e' and '-f' options cannot be specified simultaneously"); + printUsage(); return false; } - List hiveConfArgs = (List) cmdLine.getValue(confOptions); - if (null != hiveConfArgs) { - for (String s : hiveConfArgs) { - String[] parts = s.split("=", 2); - ss.cmdProperties.setProperty(parts[0], parts[1]); + if (commandLine.hasOption("hiveconf")) { + Properties confProps = commandLine.getOptionProperties("hiveconf"); + for (String propKey : confProps.stringPropertyNames()) { + ss.cmdProperties.setProperty(propKey, confProps.getProperty(propKey)); } } return true; } - public void printUsage(String error) { - if (error != null) { - System.err.println("Invalid arguments: " + error); - } - System.err.println(""); - System.err.println( - "Usage: hive [--config confdir] [-hiveconf x=y]* [-i ]*" - + " [-f |-e ] [-S] [-v]"); - System.err.println(""); - System.err.println(" -i init Sql file"); - System.err.println(" -e 'quoted query string' Sql from command line"); - System.err.println(" -f Sql from files"); - System.err.println(" -S Silent mode in interactive shell"); - System.err.println(" -v Verbose mode (echo executed Sql to the console)"); - System.err.println(""); - System.err.println("-e and -f cannot be specified together. In the absence of these"); - System.err.println(" options, interactive shell is started."); - System.err.println(""); - + private void printUsage() { + new HelpFormatter().printHelp("hive", options); } } diff --git eclipse-templates/.classpath eclipse-templates/.classpath index e40a07a..8d2dc52 100644 --- eclipse-templates/.classpath +++ eclipse-templates/.classpath @@ -10,7 +10,6 @@ - @@ -29,6 +28,7 @@ + diff --git ivy/libraries.properties ivy/libraries.properties index 0ede62a..253fd7b 100644 --- ivy/libraries.properties +++ ivy/libraries.properties @@ -27,7 +27,7 @@ datanucleus-core.version=2.0.3 datanucleus-enhancer.version=2.0.3 datanucleus-rdbms.version=2.0.3 checkstyle.version=5.0 -commons-cli.version=2.0-SNAPSHOT +commons-cli.version=1.2 commons-codec.version=1.3 commons-collections.version=3.2.1 commons-dbcp.version=1.4 diff --git lib/commons-cli-2.0-SNAPSHOT.jar lib/commons-cli-2.0-SNAPSHOT.jar deleted file mode 100644 index 0b1d510..0000000 Binary files lib/commons-cli-2.0-SNAPSHOT.jar and /dev/null differ diff --git shims/build.xml shims/build.xml index 2021cfb..9dadc8a 100644 --- shims/build.xml +++ shims/build.xml @@ -60,7 +60,7 @@ to call at top-level: ant deploy-contrib compile-core-test - + diff --git shims/ivy.xml shims/ivy.xml index 82b6688..f392c43 100644 --- shims/ivy.xml +++ shims/ivy.xml @@ -1,7 +1,24 @@ + + - +