简体   繁体   English

从Apache Hive运行bash别名

[英]Run bash alias from Apache Hive

I am trying to create an alias on Hadoop machine and run it from Hive JVM. 我试图在Hadoop计算机上创建一个别名,然后从Hive JVM运行它。 When I explicitly run the command from Hive with ! 当我用!明确从Hive运行命令时 prefix it works, however when I add the alias, source the .bashrc file and call the alias from Hive, I get an error. 前缀可以正常工作,但是当我添加别名,获取.bashrc文件并从Hive调用别名时,出现错误。 Example: 例:

.bashrc content: .bashrc内容:

# 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: 呼叫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 (eg by default you cannot call an alias from a non-interactive shell). 与shell函数相比,别名具有一些限制(例如,默认情况下,您不能从非交互式shell调用别名)。

Define in your ~/.bashrc : ~/.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. 来源您.bashrc以应用更改。 Then, call load-table . 然后,调用load-table

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM