参考链接 http://www.crazyant.net/1451.html 疯狂蚂蚁
目前 hive需要的外部参数完全可以通过 将hive脚本写在 xxx.sh中 利用sh的变量来获取
这是目前工作中最常用方式。
1 hive使用外部变量: 分为4种情况,
hive中引用外部变量: 在代码中引用时使用${...}; 方式1: [root@h2single bin]# hive -d name=username; 随便定义变量 后在hive中使用此变量 hive> create table t1(${name} string); OK Time taken: 3.499 seconds hive> describe t1; OK username string 方式2: hiveconf: 覆盖hive-site hive-default的值: [root@h2single bin]# pwd /usr/local/hive/bin [root@h2single bin]# hive --hiveconf hive.cli.print.current.db=true; 显示库名称 hive (default)> 展示库名称为default [root@h2single bin]# hive --hiveconf hive.cli.print.header=true; 查表记录时,展示字段名称 hive> select * from t4; OK t4.root 展示字段 方式3:system 读取java 变量 从java定义的配置属性,如system:user.name hive> create table t3(${system:user.name} string) > ; OK Time taken: 1.278 seconds hive> describe t3; OK root string Time taken: 0.894 seconds, Fetche 方式4:env 读取shell环境变量 hive> create table t4(${env:USER} string); OK Time taken: 2.891 seconds hive> describe t4; OK root string
2 启动时 指定hive目录:
#hive --hiveconf hive.metastore.warehouse.dir=/hive/$USER;
3 linux环境下执行hive语句:
如下命令均在linux下执行: [root@h2single bin]# hive -e "show tables"; hive -e "show tables" linux shell下将此语句发送到shell执行 后将结果打印在linux shell下 hive -e "show tables">tablename 将结果写到当前linux目录的tablename文件中 hive -S -e "show tables">tablename 将和hive交互过程信息 比如耗时等 不在控制台中显示出来 $ hive -S -e "select * from stu limit 3;" > /tmp/myquery $ cat /tmp/myquery 里面会将交互信息OK 耗时信息Time taken:4.95 seconds忽略掉 1 zhangsan 2 lisi [root@h2single bin]# vi test.hql show tables [root@h2single bin]# hive -f test.hql >> a.txt 将外部文件a.hql内容发送到hive中执行并将返回结果 追加写到当前shell目录下的 a.txt中 [root@h2single bin]# cat a.txt t1 t3 t4 hive -f 操作hdfs文件写法: hive -f hdfs://<namenode>:<port>/hive-script.sql
4 hive 环境下执行linux语句: hive环境下访问hdfs内容:
hive> dfs -ls / > ; Found 4 items drwxr-xr-x - root supergroup 0 2015-03-06 02:35 /flume drwxr-xr-x - root supergroup 0 2015-03-12 17:31 /hbase drwx-wx-wx - root supergroup 0 2015-03-13 19:09 /tmp drwx------ - root supergroup 0 2015-03-13 19:17 /user hive> hive>dfs -rm -r /root/t5 hive环境下访问shell内容: hive>!mkdri /usr/local/test; hive> ! mkdir 111; hive> ! ls; 111 a.txt ext hive hive-config.sh test.hql hive>
5 hiverc 文件 做初始化操作:
[root@h2single bin]# ls -a ~ [root@h2single bin]# vi ~/.hiverc 创建此文件 里面添加如下内容 set hive.cli.print.current.db=true; set hive.cli.print.header=true; 此时在进入hive> 就会看到 显示数据库名称 查询表也会展示表字段名称
相关推荐
Hive几种数据导出方式,总结的几种方式希望能帮到大家
Ambari搭建hadoop环境下,hive的数据导入
hadoop下Hive的三种方式安装与搭建,hadoop下Hive的三种方式安装与搭建
java调用hive需要的jar
hive hive hive hive hive hive hive hive hive hive hive hive
Hive几种使用方式: 1.Hive交互shell bin/hive 2.Hive JDBC服务(参考java jdbc连接mysql) 3.hive启动为一个服务器,来对外提供服务 bin/hiveserver2 nohup bin/hiveserver2 1>/var/log/hiveserver.log 2>/...
基于hadoop的Hive数据仓库JavaAPI简单调用的实例,关于Hive的简介在此不赘述。hive提供了三种用户接口:CLI,JDBC/ODBC和 WebUI CLI,即Shell命令行 JDBC/ODBC 是 Hive 的Java,与使用传统数据库JDBC的方式类似 Web...
1 Hive 概念与连接使用: 2 2 Hive支持的数据类型: 2 2.1原子数据类型: 2 2.2复杂数据类型: 2 2.3 Hive类型转换: 3 3 Hive创建/删除数据库 3 3.1创建数据库: 3 3.2 删除数据库: 3 4 Hive 表相关语句 3 4.1 Hive ...
DateGrip连接Hive时添加驱动文件时使用
hive数据加载的几种方式、数据的导出、数据简单查询
hive权限,通过自定义jar对hive的10000端口进行权限管控,直接放入到hive所在的lib环境下,然后对xml文件进行相应的配置
部分普通sql查询在hive中的实现方式详细说明;
-hivevar : 用于定义hive运行时的变量替换 ,专门提供给用户自定义变量。 -hiveconf : 用于定义hive执行时的属性,即配置参数,可覆盖hive-site.xml中配置的hive全局变量。 egg: hive -e查询: hive -S -e ...
hive-jdbc
使用hive3.1.2和spark3.0.0配置hive on spark的时候,发现官方下载的hive3.1.2和spark3.0.0不兼容,hive3.1.2对应的版本是spark2.3.0,而spark3.0.0对应的hadoop版本是hadoop2.6或hadoop2.7。 所以,如果想要使用高...
大数据的hive资源的详细代码设计以及分享,望博友相互交流
spark3读hive1,配置spark.sql.hive.metastore.jars
Hive表生成工具,Hive表生成工具Hive表生成工具
HIVE在腾讯分布式数据仓库实践分享 赵伟.pdf Hap数据仓库工具--hive介绍.docx The Hive An The Hney Bee Langstrth.pdf bigtable,hive,pig.pdf HIVE优化以及执行原理.pdf hive实现原理-weib.pdf 【Hive】Hap Data ...
Python 连接Hive离线方式1