zoukankan      html  css  js  c++  java
  • hive学习笔记

    1.OLAP离线计算,在线分析
    2.HiveSQL,是类Sql语言
    3.hive的表是存放在rdbms中的
    4.hive处理的数据就是hdfs,hive在查询的时候通常会转换成mr,但不是所有的查询都会转成mr,比如全字段扫描,全表扫面,不加任何条件,就是全字段的读取,聚合查询需要转成mr

    内部表,管理表,托管表

    表和数据都是由hive进行管理的,在drop表的时候,表被删除了,那么数据也就没有了
    

    外部表

    hive只是维护表结构的,当删除表的时候,当删除表的时候数据还在,安全性比较高
    

    分区表

    分区就是目录。在创建表的时候可以指定分区,在查询的时候可以把分区映射成字段,可以缩小查询范围
    

    桶表

    桶表对应的是文件,桶表在建表的时候需要指定按照哪个表进行分桶clustered by 
    

    union查询

    联合查询,是竖直的,把多个表的数据叠加在一起返回
    select id,name from customers union select id,orderno from orders ;
    

    join查询

    连接查询是水平的,把两个表或者多个表的记录合在一条记录上来返回
    

    hive使用jdbc协议实现远程访问

    $hive        //hive --service cli
    $hive --service hiveserver2    //启动hiveserver2,10000,要实现beeline远程访问的话,就需要启动这个服务器
    $hive --service beeline        //$hive>beeline
    

    在hive中,大部分的操作都是sql操作

    hive建表的语句

    create table xxx(id int ,name string,age int) partitioned by(year int,month int) row format delimited fields terminated by ","
    

    导出表数据

    $export table customers to '/user/centos/tmp.txt'
    
    //order by全排序
    $hive>select * from orders order by id asc;//注意:一旦order by就会变成mr了 
    
    //sort,map端排序,也就是本地有序
    $hive>select * from orders sort by id asc;
    
     set hive.exec.reducers.bytes.per.reducer=<number>        //设置每一个reduce作业处理的字节数
    
     set hive.exec.reducers.max=<number>                            //设置reduce作业的最大任务数
    
    set mapreduce.job.reduces=<number>                            //设置reduce的个数
    
    //distribute by 类似于mysql的group by,进行分区操作。
    $hive>select id,orderno,cid form orders distribute by cid sort by cid desc;
    

    函数

    mysql>select concat('tom',1000);
    

    hive事务处理

    1.使用事务性操作
    

    $hive>set hive.support.concurrency=true;
    $hive>set hive.enforce.bucketing=true;
    $hive>set.exec.dynamic.partition.mode=nonstrict;
    $hive>set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
    $hive>set hive.comparator.initiator.on=true;
    $hive>set hive.comparator.worker.threads = 1;

  • 相关阅读:
    09暑假总结
    给我同学的一点建议
    委托(一个主窗体统计多个从窗体的按钮单击的次数)
    关于C#写的记事本中一个问题
    IT行业最重要的四件宝我的实习体会
    使用结构、数组、循环和DataGridView写的分数统计小程序
    Visual Studio 2005 打不开,一直停在启动画面问题
    解决Cannot open the disk 'F:/vmware/Ubuntu.vmdk' or one of the snapshot disks it depends on.
    设计原则笔记
    交叉表组件
  • 原文地址:https://www.cnblogs.com/stone-learning/p/9280056.html
Copyright © 2011-2022 走看看