zoukankan      html  css  js  c++  java
  • 1、hive实现全排序

    目的:设置了 3 个reduce,在最终生成的 3 个文件中,实现全局是按year升序,year相同则按温度降序排列

    启动hive

    1、启动服务端,注意:删除掉hadoop脚本中的调试设置代码

    hiveserver2

    2、启动客户端

    beeline
    !connect jdbc:hive2://localhost:10000/xxxxxx;auth=noSasl;  //装hue后

     操作hive

    建表

    create table tmp(id int,t int)row format delimited fields terminated by ' ';
    alter table tmp change  id  year int;  //修改字段名

    加载数据

    load data local inpath 'ttt.dat' into table tmp;

    注:local本地文件:相当于复制;不加local,从hdfs上加载数据,相当于移动

    设置reduce个数

    set mapreduce.job.reduces = 3;

    使用ctas语法测试

    create table tmp2 as select * from tmp distribute by (case when year < 1930 then 0 when year > 1960 then 2 else 1 end) sort by (year asc ,t desc);

     知识点:1、ctas:有结构有数据,但分区变成普通字段

                         ctal:有结构没数据

                    2、distribute by  hash分区,和reduce个数取模,该例中有 3 个reduce,最终三个文件

                          order by  hive中实现全排序方式,只有一个reduce,因此数据量很大时,性能不好;因此使用时,一般加 limit 

                          sort  by  部分排序

                          cluster   by   distribute  by     +   sort   by

                    3、case  when then end语法

    渐变 --> 突变
  • 相关阅读:
    ES6 Set
    JavaScript 之 对象属性的特性 和defineProperty方法
    ES6 ... 展开&收集运算符
    ES6 箭头函数
    ES6 解构 destructuring
    canvas之事件交互效果isPointPath
    跨域及JSONP原理
    P03 显示隐藏
    最长公共子序列
    P02 CSS样式
  • 原文地址:https://www.cnblogs.com/lybpy/p/9703773.html
Copyright © 2011-2022 走看看