hive脚本的执行方式大致有三种

hive脚本的执行方式大致有三种:

参考hive的用法:

usage: hive
 -d,--define <key=value>          Variable subsitution to apply to hive
                                  commands. e.g. -d A=B or --define A=B
    --database <databasename>     Specify the database to use
 -e <quoted-query-string>         SQL from command line
 -f <filename>                    SQL from files
 -H,--help                        Print help information
 -h <hostname>                    connecting to Hive Server on remote host
    --hiveconf <property=value>   Use value for given property
    --hivevar <key=value>         Variable subsitution to apply to hive
                                  commands. e.g. --hivevar A=B
 -i <filename>                    Initialization SQL file
 -p <port>                        connecting to Hive Server on port number
 -S,--silent                      Silent mode in interactive shell
 -v,--verbose                     Verbose mode (echo executed SQL to the
                                  console)
  1. hive控制台执行;

hive控制台以后,执行sql语句

  1. hive -e “SQL”执行;
hive -e " select page_name, tpa_name 
from pms.pms_exps_prepro 
limit 2;"
  1. hive -f SQL文件执行;
    将sql保存到一个文件中demo.sql
    demo.sql的内容:
select * from table_name where ...

执行hive命令

hive -f demo.sql

ps:如果sql中需要有参数,而且和Linux shell脚本结合跑批

例子:

demo2.sql的内容:

insert overwrite table ods_yqg.fdm_yqg_user_asset_full partition(dt = "${p_date}")
select t.id,t.user_id,t.product_id,t.principal,t.asset,
t.return_accumulated,t.return_yesterday,t.last_update_date,t.time_updated
from tmp_export.user_asset_full as t where t.dt = "${p_date}";

通过hive -hivevar 加参数

test.sh的内容:

#!/usr/bin/env bash

start_date="$1"
hive -hivevar p_date=${start_date} -f /data/apps/yqg_datatask_cheetah/task/tempdata/load_tmp_export_asset_full_to_ods_yqg/hivescript.sql
  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值