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命令行操作
   执行一个查询,在终端上显示mapreduce的进度,执行完毕后,最后把查询结果输出到终端上,接着hive进程退出,不会进入交互模式。
   hive -e 'select table_cloum from table'
   -S,终端上的输出不会有mapreduce的进度,执行完毕,只会把查询结果输出到终端上。这个静音模式很实用,,通过第三方程序调用,第三方程序通过hive的标准输出获取结果集。
   hive -S -e 'select table_cloum from table'
   执行sql文件
   hive -f hive_sql.sql

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_statement
    insert overwrite table test_insert select * from test_table;

对多个表进行插入操作:
    FROM fromstatte
    INSERT OVERWRITE TABLE tablename1 [PARTITON(partcol1=val1,partclo2=val2)]select_statement1
    INSERT OVERWRITE TABLE tablename2 [PARTITON(partcol1=val1,partclo2=val2)]select_statement2

from test_table                     
    insert overwrite table test_insert1 
    select key
    insert overwrite table test_insert2
    select 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_insert1
    insert 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 常用命令的更多相关文章

  1. Hive 常用命令和语句

    示例数据库为 db_hive 1. 创建表 create-table.sql create table if not exists db_hive.tb_user ( id int, username ...

  2. Hive常用命令

    本位为转载,原地址为:http://www.cnblogs.com/BlueBreeze/p/4232421.html #创建新表 hive> CREATE TABLE t_hive (a in ...

  3. 大数据-Hive 常用命令

    Hive 启动 ~$ hive 退出 hive>quit; --退出hive or hive> exit; --exit会影响之前的使用,所以需要下一句kill掉hadoop的进程 > ...

  4. HIVE常用命令之MSCK REPAIR TABLE

    MSCK REPAIR TABLE命令主要是用来解决通过hdfs dfs -put或者hdfs api写入hive分区表的数据在hive中无法被查询到的问题.我们知道hive有个服务叫metastor ...

  5. Hive记录-Hive常用命令操作

    1.hive支持四种数据模型 • external table ---外部表:Hive中的外部表和表很类似,但是其数据不是放在自己表所属的目录中,而是存放到别处,这样的好处是如果你要删除这个外部表,该 ...

  6. Hive常用命令及作用

    1-创建表 -- 内部表 create table aa(col1 string,col2 int) partitioned by(statdate int) ROW FORMAT DELIMITED ...

  7. 【原创】官方文档-hive 启动命令

    [一起学Hive]之十六-Hive的WEB页面接口-HWI Apache Hive 管网 hive metrics hive常用命令整理 Hive学习之HiveServer2服务端配置与启动 启动hi ...

  8. hive 常用操作

    参考:https://www.cnblogs.com/jonban/p/10779938.html Hive 启动:hive 退出:hive>quit; show databases; use  ...

  9. 【Hadoop离线基础总结】Sqoop常用命令及参数

    目录 常用命令 常用公用参数 公用参数:数据库连接 公用参数:import 公用参数:export 公用参数:hive 常用命令&参数 从关系表导入--import 导出到关系表--expor ...

随机推荐

  1. golang 多级json转map

    func main() { jsonStr := `{"isSchemaConforming":true,"schemaVersion":0,"unk ...

  2. CentOS下Vim加密解密文本

    CentOS用vim/vi给文件加密和解密 一. 利用 vim/vi 加密: 优点:加密后,如果不知道密码,就看不到明文,包括root用户也看不了: 缺点:很明显让别人知道加密了,容易让别人把加密的文 ...

  3. 【Python开发】Python PIL ImageDraw 和ImageFont模块学习

    ImageDraw 新建一个空白图片为本文作示例,新建空白文件的方法 见Image模块,Image.new: mport Image   blank = Image.new("RGB&quo ...

  4. 【Linux开发】linux设备驱动归纳总结(七):1.时间管理与内核延时

    linux设备驱动归纳总结(七):1.时间管理与内核延时 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  5. PTA(Basic Level)1037.在霍格沃茨找零钱

    如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易.& ...

  6. python网络爬虫(3)python爬虫遇到的各种问题(python版本、进程等)

    import urllib2 源地址 在python3.3里面,用urllib.request代替urllib2 import urllib.request as urllib2 import coo ...

  7. 什么是 Serverless 应用引擎?优势有哪些?

    Serverless 应用引擎(Serverless App Engine,简称 SAE)是面向应用的 Serverless PaaS 平台,能够帮助 PaaS 层用户免运维 IaaS,按需使用,按量 ...

  8. Mysql学习(二)之通过homebrew安装mysql后,为什么在系统偏好设置里没有mysql

    原因 用brew install packagename是用来安装命令行工具的,一般不可能影响到图形界面. mysql官方文档是通过dmg文件安装的: The MySQL Installation P ...

  9. pytorch中torch.narrow()函数

    torch.narrow(input, dim, start, length) → Tensor Returns a new tensor that is a narrowed version of  ...

  10. pytorch中的torch.repeat()函数与numpy.tile()

    repeat(*sizes) → Tensor Repeats this tensor along the specified dimensions. Unlike expand(), this fu ...