- CLI方式
通过hive或者beeline方式进入shell命令
- hive -e “sql” 不会进入交互模式,执行完hive进程直接退出
hive -e "use testdb;select * from person"
注: 加上 -S 可以不输出mapreduce的日志
- **hive -f “文件路径.sql” **
.sql后缀只为了清晰标明文件类型 , 不是必须的
drop table if exists tdb.person3; create table if not exists tdb.person3( id int comment "测试表", name string comment "这是名称注解" ) comment "表名注解";
执行文件在HDFS上 , mycluster是映射地址 , 配置了hdfs的HA
- hiveconf和hivevar
这里介绍两种方法:hiveconf 和 hivevar,hiveconf属于hive-site.xml下面配置的环境变量,hivevar为临时变量。在运行时hiveconf必须带上命名空间,如** h i v e c o n f : k e y , h i v e v a r 直 接 使 用 {hiveconf:key},hivevar直接使用 hiveconf:key,hivevar直接使用{key}**即可
hiveconf
sreach.sql USE testdb; SELECT * FROM person WHERE name = "${hiveconf:name}" LIMIT 10;
命令: hive --hiveconf name=lily -f /root/sreach.sql
hivevar
sreach.sql USE testdb; SELECT * FROM person WHERE name = "${name}" LIMIT 10; hivevar模式不能使用 "${hiveconf:name}"
命令: hive --hivevar name=lily -f /root/sreach.sql
- 完
hive执行Hql方式
最新推荐文章于 2023-04-26 18:19:59 发布