在脚本中运行脚本? - Hive(以及其他QL' s)

时间:2015-06-29 23:32:53

标签: hadoop hive hdfs hue

是否可以在运行脚本的其余部分之前调用脚本并运行它?

我的目标是执行一个设置脚本,该脚本将下载和组织执行主查询所需的数据。

我正在寻找类似的东西:

create table logcontent (content string) row format delimited fields terminated by '\n';

**call secondary hive script with date-range arguments and download necessary logs into <logcontent>**

**perform the rest of the query**

我想这样做是为了为表格设置创建一个漂亮的抽象,以便最终用户不必担心表格设置,它将为他们完成。

我知道AWS可以选择添加Hive脚本作为工作中的一个步骤但是如何在本地执行相同的操作?这可能吗?如果是这样,语法是什么?如果没有,有什么解决办法吗?

2 个答案:

答案 0 :(得分:1)

您可以尝试这样的事情:

create table logcontent (content string) row format delimited fields terminated by '\n'; 
&& sh /path/to/script.sh 
&& **perform the rest of the query**

&&符号用于在前一个命令成功完成后执行后续命令。

答案 1 :(得分:1)

答案是在类似的模板中组织主shell脚本。

## Content of main.sh

## Code block to setup Hadoop Environment and config in Path, if not already exist.

## Step 1> Create the hive table in non-interactive mode.
hive -e "create table test(id int, name string) row format delimited fields terminated by '\n'"
# Check if the command is successful. IF else logic can be added.
echo $? 

## Step 2> Call the secondary script executable to download logs
ksh downloadlogs.sh # Assuming the download script could be invoked this way.

## Step 3> Execute rest of the hive queries to organize data
hive -e "select * from test"