问题描述:

I am trying to create an alias on Hadoop machine and run it from Hive JVM.

When I explicitly run the command from Hive with ! prefix it works, however when I add the alias, source the .bashrc file and call the alias from Hive, I get an error. Example:

.bashrc content:

# Environment variables required by hadoop

export JAVA_HOME=/usr/lib/jvm/java-7-oracle

export HADOOP_HOME_WARN_SUPPRESS=true

export HADOOP_HOME=/home/hadoop

export PATH=$PATH:/home/hadoop/bin

alias load-table='java -cp /home/hadoop/userlib/MyJar.jar com.MyClass.TableLoader';

Call on Hive:

!load-table;

Output:

Exception raised from Shell command Cannot run program "load-table": error=2, No such file or directory

网友答案:

Aliases have several limitations compared to shell functions (e.g. by default you cannot call an alias from a non-interactive shell).

Define in your ~/.bashrc:

function load-table() {
    # Make sure the java executable is accessible
    if which java > /dev/null 2>&1; then
        java -cp /home/hadoop/userlib/MyJar.jar com.MyClass.TableLoader
    else
        echo "java not found! Check your PATH!"
    fi
}
export -f load-table # to export the function (BASH specific)

Source you .bashrc to apply the changes. Then, call load-table.

相关阅读:
Top