Instructions on executing shell scripts in hive #! /Usr/bin/env bash # 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 T in compliance with # the License. you may obtain a c Opy 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. # cygwin is a windows Platform Run the unix simulated environment to determine whether it is a virtual unix environment cygwin = falsecase "'uname'" in CYGWIN *) cygwin = true ;; esac # determine the script directory bin = 'dirname "$0" 'bin = 'CD "$ bin"; pwd' # import the hive-config.sh configuration file under the script directory. "$ bin"/hive-config.sh SERVICE = "" HELP = "" # determine if the parameter is greater than 0 while [$ #-gt 0]; do case "$1" in -- service) # The first parameter is displayed, that is, Skip -- service shift SERVICE = $1 shift; -- rcfilecat) SERVICE = rcfilecat shift; -- help) HELP = _ help shift ;;*) break; esacdone if ["$ SERVICE" = ""]; then if ["$ HELP" = "_ help"]; then SERVICE = "help" else SERVICE = "cli" fifi # identify whether the file exists (import the script to store the hive-config.sh configuration file in the directory) if [-f "$ {HIVE_CONF_DIR}/hive-env.sh"]; then. "$ {HIVE_CONF_DIR}/hive-env.sh" fi CLASSPATH = "$ {HIVE_CONF_DIR}" HIVE_LIB =$ {HIVE_HOME}/lib # needed for executionif [! -F $ {HIVE_LIB}/hive-exec -*. jar]; then echo "Missing Hive Execution Jar: $ {HIVE_LIB}/hive-exec -*. jar "exit 1; fi if [! -F $ {HIVE_LIB}/hive-metastore-*. jar]; then echo "Missing Hive MetaStore Jar" exit 2; fi # cli specific codeif [! -F $ {HIVE_LIB}/hive-cli -*. jar]; then echo "Missing Hive CLI Jar" exit 3; fi # Add the jar package to the environment variable for f in $ {HIVE_LIB }/*. jar; do CLASSPATH =$ {CLASSPATH}: $ f; done # add the auxillary jars such as serdesif [-d "$ {HIVE_AUX_JARS_PATH}"]; then for f in $ {HIVE_AUX_JARS_PATH }/*. jar; do if [[! -F $ f]; then continue; fi if $ cygwin; then f = 'cygpath-w "$ f" 'fi AUX_CLASSPATH =$ {AUX_CLASSPATH }: $ f if ["$ {AUX_PARAM}" = ""]; then AUX_PARAM = file: // $ f else AUX_PARAM =$ {AUX_PARAM}, file: // $ f; fi doneelif ["$ {HIVE_AUX_JARS_PATH }"! = ""]; Then if $ cygwin; then HIVE_AUX_JARS_PATH = 'echo $ HIVE_AUX_JARS_PATH | sed's /,/: /g ''hive_aux_jars_path = 'cygpath-p-w "$ HIVE_AUX_JARS_PATH" 'hive_aux_jars_path = 'echo $ HIVE_AUX_JARS_PATH | sed's /;/, /g'' fi AUX_CLASSPATH =$ {HIVE_AUX_JARS_PATH} # AUX_PARAM needs to be a comma separated list of "file" scheme paths # Replace colons and semicolons with commas; eliminate repeats AUX_PARAM = 'echo $ UX_CLASSPATH | awk '{gsub (/[:;,] + /,","); print} ''# Strip leading/trailing commas AUX_PARAM = 'echo $ AUX_PARAM | awk '{gsub (/^, |, $ /,""); print} ''# Replace commas with file: // AUX_PARAM = file: // 'echo $ AUX_PARAM | awk '{gsub (//,/,", file: // "); print}'' fi # adding jars from auxlib directoryfor f in $ {HIVE_HOME}/auxlib /*. jar; do if [[! -F $ f]; then continue; fi if $ cygwin; then f = 'cygpath-w "$ f" 'fi AUX_CLASSPATH =$ {AUX_CLASSPATH }: $ f if ["$ {AUX_PARAM}" = ""]; then AUX_PARAM = file: // $ f else AUX_PARAM =$ {AUX_PARAM}, file: // $ f; fidoneif $ cygwin; then CLASSPATH = 'cygpath-p-w "$ CLASSPATH" 'classpath =$ {CLASSPATH}; $ {AUX_CLASSPATH} else CLASSPATH =$ {CLASSPATH }: $ {AUX_CLASSPATH} fi # pass classpath to hadoopexport HADOOP_CLASSPATH = "$ {HADO OP_CLASSPATH }:: {CLASSPATH} "# check for hadoop in the pathHADOOP_IN_PATH = 'which hadoop 2>/dev/null' if [-f $ {HADOOP_IN_PATH}]; then HADOOP_DIR = 'dirname "$ HADOOP_IN_PATH "'/.. fi # HADOOP_HOME env variable overrides hadoop in the pathHADOOP_HOME =$ {HADOOP_HOME:-$ HADOOP_DIR} if ["$ HADOOP_HOME" = "]; then echo" Cannot find hadoop installation: \ $ HADOOP_HOME must be set or hadoop must be in the path "; Exit 4; fi HADOOP = $ HADOOP_HOME/bin/hadoopif [! -F $ {HADOOP}]; then echo "Cannot find hadoop installation: \ $ HADOOP_HOME must be set or hadoop must be in the path"; exit 4; fi # Make sure we're re using a compatible version of Hadoophadoop_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.2hadoop _ version_re = "^ ([: digit:] + )\. ([[: digit:] + )(\. ([[: Digit:] + ))?. * $ "If [[" $ hadoop_version "= ~ $ Hadoop_version_re]; then versions =$ {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 5fi 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' return Ed: "echo '$ HADOOP version' exit 6fi if [" $ {AUX_PARAM }"! = ""]; Then HIVE_OPTS = "$ HIVE_OPTS-hiveconf hive. aux. jars. path = $ {AUX_PARAM} "AUX_JARS_CMD_LINE ="-libjars $ {AUX_PARAM} "fi SERVICE_LIST =" "for I in" $ bin "/ext /*. sh; do. $ idone for I in "$ bin"/ext/util /*. sh; do. $ idone TORUN = "" for j in $ SERVICE_LIST; do if ["$ j" = "$ SERVICE"]; then TORUN =$ {j} $ HELP fidone if ["$ TORUN" = ""]; then echo "Service $ SERVICE not found" echo "Available Services: $ SERVICE_LIST "exit 7 else $ TORUN" $ @ "fi