hive变量调用 hive和shell hdfs命令交互调用 hiverc预定义初始化
来源:互联网 发布:即时通讯软件市场份额 编辑:程序博客网 时间:2024/05/16 02:55
hive变量调用 hive和shell hdfs命令交互调用 hiverc预定义初始化
1 hive使用外部变量: 分为4种情况,
hive中引用外部变量: 在代码中引用时使用${...};方式1:[root@h2single bin]# hive -d name=username; 随便定义变量 后在hive中使用此变量 hive> create table t1(${name} string);OKTime taken: 3.499 secondshive> describe t1;OKusername 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;OKt4.root 展示字段方式3:system 读取java 变量 从java定义的配置属性,如system:user.namehive> create table t3(${system:user.name} string) > ;OKTime taken: 1.278 secondshive> describe t3;OKroot string Time taken: 0.894 seconds, Fetche方式4:env 读取shell环境变量hive> create table t4(${env:USER} string);OKTime taken: 2.891 secondshive> describe t4;OKroot 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交互过程信息 比如耗时等 不在控制台中显示出来[root@h2single bin]# vi test.hqlshow tables[root@h2single bin]# hive -f test.hql >> a.txt 将外部文件a.hql内容发送到hive中执行并将返回结果 追加写到当前shell目录下的 a.txt中[root@h2single bin]# cat a.txt t1t3t4hive -f 操作hdfs文件写法:hive -f hdfs://<namenode>:<port>/hive-script.sql
4 hive 环境下执行linux语句: hive环境下访问hdfs内容:
hive> dfs -ls / > ;Found 4 itemsdrwxr-xr-x - root supergroup 0 2015-03-06 02:35 /flumedrwxr-xr-x - root supergroup 0 2015-03-12 17:31 /hbasedrwx-wx-wx - root supergroup 0 2015-03-13 19:09 /tmpdrwx------ - root supergroup 0 2015-03-13 19:17 /userhive> hive>dfs -rm -r /root/t5hive环境下访问shell内容:hive>!mkdri /usr/local/test; hive> ! mkdir 111;hive> ! ls;111a.txtexthivehive-config.shtest.hqlhive>
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> 就会看到 显示数据库名称 查询表也会展示表字段名称
阅读全文
0 0
- hive变量调用 hive和shell hdfs命令交互调用 hiverc预定义初始化
- hive调用Linux的shell命令测试
- Spark-Sql整合hive,在spark-sql命令和spark-shell命令下执行sql命令和整合调用hive
- Hive中的.hiverc文件及命令运行方式
- Hive中的.hiverc文件及命令运行方式
- shell命令执行hive脚本(hive交互,hive的shell编程)
- shell命令执行hive脚本(hive交互,hive的shell编程)
- shell命令执行hive脚本(hive交互,hive的shell编程)
- hive安装和shell交互全步骤
- shell中循环调用hive sql 脚本
- [Hive学习笔记]hive命令的3种调用方式
- hive命令的3中调用方式
- Hive命令的3种调用方式
- Hive命令的3种调用方式
- hive命令的3种调用方式
- Hive命令的3种调用方式
- hive命令的3种调用方式
- hive命令的3种调用方式
- 数据结构——二叉树学习
- LoRa物联网在智慧农业的应用:智慧大棚解决方案
- 手机端页面去除a标签点击时的蓝色边框
- windows版本打开git bash总是闪退的解决办法
- formdata文件上传记录
- hive变量调用 hive和shell hdfs命令交互调用 hiverc预定义初始化
- FLV文件格式解析
- CMD基本命令
- C++第六次实验-友元函数
- C/C++预编译头的概念
- oracle中start with和connect by的用法理解
- spring-boot 开启Gzip解决办法
- @RequestParam的作用
- java HashMap插入重复Key值问题