hive表信息查询:查看表结构、表操作等(转)
转自:http://www.aboutyun.com/forum.php?mod=viewthread&tid=8590&highlight=hive
问题导读:
1.如何查看hive表结构?
2.如何查看表结构信息?
3.如何查看分区信息?
4.哪个命令可以模糊搜索表
1.hive模糊搜索表
show tables like '*name*';
2.查看表结构信息
desc formatted table_name;desc table_name;
3.查看分区信息
show partitions table_name;
4.根据分区查询数据
select table_coulm from table_name where partition_name = '2014-02-25';
5.查看hdfs文件信息
dfs -ls /user/hive/warehouse/table02;
6.从文件加载数据进表(OVERWRITE覆盖,追加不需要OVERWRITE关键字)
LOAD DATA LOCAL INPATH 'dim_csl_rule_config.txt' OVERWRITE into table dim.dim_csl_rule_config;--从查询语句给table插入数据INSERT OVERWRITE TABLE test_h02_click_log PARTITION(dt) select * from stage.s_h02_click_log where dt='2014-01-22' limit 100;
7.导出数据到文件
insert overwrite directory '/tmp/csl_rule_cfg' select a.* from dim.dim_csl_rule_config a;hive -e "select day_id,pv,uv,ip_count,click_next_count,second_bounce_rate,return_visit,pg_type
from tmp.tmp_h02_click_log_baitiao_ag_sum where day_id in ('2014-03-06','2014-03-07','2014-03-08','2014-03-09','2014-03-10');">
/home/jrjt/testan/baitiao.dat;
8.自定义udf函数
1.继承UDF类
2.重写evaluate方法
3.把项目打成jar包
4.hive中执行命令add jar /home/jrjt/dwetl/PUB/UDF/udf/GetProperty.jar;
5.创建函数create temporary function get_pro as 'jd.Get_Property'//jd.jd.Get_Property为类路径;
9.查询显示列名 及 行转列显示
set hive.cli.print.header=true; // 打印列名set hive.cli.print.row.to.vertical=true; // 开启行转列功能, 前提必须开启打印列名功能set hive.cli.print.row.to.vertical.num=1; // 设置每行显示的列数
10.查看表文件大小,下载文件到某个目录,显示多少行到某个文件
dfs -du hdfs://BJYZH3-HD-JRJT-4137.jd.com:54310/user/jrjt/warehouse/stage.db/s_h02_click_log;dfs -get /user/jrjt/warehouse/ods.db/o_h02_click_log_i_new/dt=2014-01-21/000212_0 /home/jrjt/testan/;head -n 1000 文件名 > 文件名
11.杀死某个任务 不在hive shell中执行
hadoop job -kill job_201403041453_58315
12.hive-wui路径
http://172.17.41.38/jobtracker.jsp
13.删除分区
alter table tmp_h02_click_log_baitiao drop partition(dt='2014-03-01');alter table d_h02_click_log_basic_d_fact drop partition(dt='2014-01-17');
14.hive命令行操作15.hive上操作hadoop文件基本命令
查看文件大小
dfs -du /user/jrjt/warehouse/tmp.db/tmp_h02_click_log/dt=2014-02-15;
删除文件
dfs -rm /user/jrjt/warehouse/tmp.db/tmp_h02_click_log/dt=2014-02-15;
16.插入数据sql、导出数据sql
1.insert 语法格式为:
基本的插入语法:
INSERT OVERWRITE TABLE tablename [PARTITON(partcol1=val1,partclo2=val2)]select_statement FROM from_statementinsert overwrite table test_insert select * from test_table;
对多个表进行插入操作:
FROM fromstatteINSERT OVERWRITE TABLE tablename1 [PARTITON(partcol1=val1,partclo2=val2)]select_statement1INSERT OVERWRITE TABLE tablename2 [PARTITON(partcol1=val1,partclo2=val2)]select_statement2from test_table insert overwrite table test_insert1 select keyinsert overwrite table test_insert2select value;
insert的时候,from子句即可以放在select 子句后面,也可以放在 insert子句前面。
hive不支持用insert语句一条一条的进行插入操作,也不支持update操作。数据是以load的方式加载到建立好的表中。数据一旦导入就不可以修改。
2.通过查询将数据保存到filesystem
INSERT OVERWRITE [LOCAL] DIRECTORY directory SELECT.... FROM .....
导入数据到本地目录:
insert overwrite local directory '/home/zhangxin/hive' select * from test_insert1;
产生的文件会覆盖指定目录中的其他文件,即将目录中已经存在的文件进行删除。
导出数据到HDFS中:
insert overwrite directory '/user/zhangxin/export_test' select value from test_table;
同一个查询结果可以同时插入到多个表或者多个目录中:
from test_insert1insert overwrite local directory '/home/zhangxin/hive' select * insert overwrite directory '/user/zhangxin/export_test' select value;
17.mapjoin的使用 应用场景:1.关联操作中有一张表非常小 2.不等值的链接操作
select /*+ mapjoin(A)*/ f.a,f.b from A t join B f on ( f.a=t.a and f.ftime=20110802)
18.perl启动任务
perl /home/jrjt/dwetl/APP/APP/A_H02_CLICK_LOG_CREDIT_USER/bin/a_h02_click_log_credit_user.pl APP_A_H02_CLICK_LOG_CREDIT_USER_20140215.dir >& /home/jrjt/dwetl/LOG/APP/20140306/
a_h02_click_log_credit_user.pl.4.log
19.查看perl进程
ps -ef|grep perl
20.hive命令移动表数据到另外一张表目录下并添加分区
dfs -cp /user/jrjt/warehouse/tmp.db/tmp_h02_click_log/dt=2014-02-18 /user/jrjt/warehouse/ods.db/o_h02_click_log/;dfs -cp /user/jrjt/warehouse/tmp.db/tmp_h02_click_log_baitiao/* /user/jrjt/warehouse/dw.db/
d_h02_click_log_baitiao_basic_d_fact/;--复制所有分区数据alter table d_h02_click_log_baitiao_basic_d_fact add partition(dt='2014-03-11')
location '/user/jrjt/warehouse/dw.db/d_h02_click_log_baitiao_basic_d_fact/dt=2014-03-11';
21.导出白条数据
hive -e "select day_id,pv,uv,ip_count,click_next_count,second_bounce_rate,return_visit,pg_type
from tmp.tmp_h02_click_log_baitiao_ag_sum where day_id like '2014-03%';"> /home/jrjt/testan/baitiao.xlsx;
22.hive修改表名
ALTER TABLE o_h02_click_log_i RENAME TO o_h02_click_log_i_bk;
23.hive复制表结构
CREATE TABLE d_h02_click_log_baitiao_ag_sum LIKE tmp.tmp_h02_click_log_baitiao_ag_sum;
24.hive官网网址
https://cwiki.apache.org/conflue ... ionandConfiguration
http://www.360doc.com/content/12/0111/11/7362_178698714.shtml
25.hive添加字段
alter table tmp_h02_click_log_baitiao_ag_sum
add columns(current_session_timelenth_count bigint comment '页面停留总时长');ALTER TABLE tmp_h02_click_log_baitiao CHANGE current_session_timelenth
current_session_timelenth bigint comment '当前会话停留时间';
26.hive开启简单模式不启用mr
set hive.fetch.task.conversion=more;
27.以json格式输出执行语句会读取的input table和input partition信息
Explain dependency query
hive表信息查询:查看表结构、表操作等(转)相关推荐
- hive SQL 创建数据库,创建hive表、查询时,其表名,字段,统统不区分大写(在底层一律转换为小写)
hive SQL 创建数据库,创建hive表.查询时,其表名,字段,统统不区分大写(在底层一律转换为小写) (1).默认default数据库 hive默认自带一个名为default的数据库,如果建表时 ...
- 对Excel表的查询、插入和更新操作
为什么80%的码农都做不了架构师?>>> 本代码主要实现对Excel表的查询.插入和更新操作,而特别指出:Excel表的删除语句操作不支持,只能用更新来替代. using Un ...
- mysql教程详解之多表联合查询,MYSQL教程mysql多表联合查询返回一张表的内容实现代码...
搜索热词 <MysqL教程MysqL多表联合查询返回一张表的内容实现代码>要点: 本文介绍了MysqL教程MysqL多表联合查询返回一张表的内容实现代码,希望对您有用.如果有疑问,可以联系 ...
- hive表信息查询:查看表结构、表操作等--转
原文地址:http://www.aboutyun.com/forum.PHP?mod=viewthread&tid=8590&highlight=Hive 问题导读: 1.如何查看hi ...
- hive表信息查询:查看表结构、表操作、建表语句
问题导读: 1.如何查看hive表结构? 2.如何查看表结构信息? 3.如何查看分区信息? 4.哪个命令可以模糊搜索表 28.怎么查询创建表语句 1.hive模糊搜索表 show tables lik ...
- hive表信息查询:查看表结构、表操作等
转自:http://www.aboutyun.com/forum.php?mod=viewthread&tid=8590&highlight=hive 问题导读: 1.如何查看hive ...
- hive表信息查询、查看表结构、表操作等
转载:http://blog.csdn.net/lskyne/article/details/38427895 问题导读: 1.如何查看hive表结构? 2.如何查看表结构信息? 3.如何查看分区信息 ...
- cmd查看mysql数据库表_cmd中查看MySQL数据库表数据及结构
0. 1 .cmd进入mysql安装的bin目录(C:\Program Files\XXXXXX\MySQL Server 5.6\bin) mysql -hlocalhost -uroot -p 回 ...
- mysql数据库中插入表信息_mysql数据库中插入表
通过binlog恢复mysql数据库 在上一篇文章,我们讲解了有关mysql的binlog日志的基础知识.这篇文章,我们来讲解如何通过mysql的binlog日志来恢复数据库. 在使用binlog日志 ...
最新文章
- 《细胞》重磅!科学家培育全球首个人类自组织心脏类器官,可自主跳动能自我修复...
- Sorting It All Out 拓扑排序+确定点
- Nagios Apache报Internal Server Error错误的解决方法
- Linux内核系统调用处理过程
- PyTorch数据Pipeline标准化代码模板
- python 函数式编程 库_使用Python的toolz库开始函数式编程的方法
- 服务端断开_Java多线程技术:实现多用户服务端Socket通信
- 智能优化算法:纵横交叉算法-附代码
- 树莓派笔记004——步进电机驱动板
- 文本挖掘带你分析 “苏轼” 的一生!(附视频)
- Pearson 相关系数
- 有了它,将大大丰富VR内容,3D VR摄像机Vuze VR开启预定
- 了解更多全国各地浴室5×8装修图片
- truffle填坑指南:truffle unbox react项目npm run start启动失败
- python相对路径找不到文件_Python里使用相对路径的坑
- php 判断是否是机器人,php实现判断访问来路是否为搜索引擎机器人的方法_PHP
- 计算机硬盘错误怎么办,电脑维修:开机遇到Windows硬盘错误画面时,该怎么做?...
- Magento通过Paypal支付方式付款发送订单确认邮件
- 下载STM32CubeMX软件固件库包的方法
- C51 学习笔记03 | 8051单片机几大功能组成部件
热门文章
- 微信小程序底部实现自定义动态Tabbar
- linux安装VNC远程桌面环境
- Kubernetes kube-proxy 如何与 iptables 完美配合使用
- 计算机及其应用本课程,北京08自考计算机及应用(独本)课程设置
- 功能超级强大的计算器程序 免费开源 全部源码
- 【a标签的使用和属性】
- D435i:control_transfer returned error, index: 768, error: No data available, number: 61
- 为啥大公司只要全栈工程师?
- 电脑系统数据丢失了是什么原因?找回方法有哪些?
- HL7体系入门级介绍【转】