hql文


概要
hql hive sql   。hive   java      ,  hive           ,      hive udf       (     udf     )。

構文
               .
    LIKE  
      : A LIKE B
        :string
      :     A     B NULL,   NULL;     A     B        ,  TRUEFALSE。B   ”_”        ,   ”%”         。
      :
    hive> select * from tbl_lzo where sport like 'foot%';
    ...footbar...
    hive> select * from tbl_lzo where sport like 'foot___';
    ...footbar...
    hive> select * from tbl_lzo where not sport like 'foot___'; ##   
    REGEXP  
      :A REGEXP B
        :string
      :     A     B NULLNULL;     A  JAVA     B     ,  TRUEFALSE。
      :
    hive> select * from tbl_lzo where sport REGEXP '^f.*r$';
    ROUND  
      :round(double a, int decim)
       :double
      :      decim double  
      :
    hive> select round(score, 2) from tbl_lzo;
    FROM_UNIXTIME  
      :from_unixtime(bigint unixtime[, string format])
       :string
      :  UNIX   ( 1970-01-01 00:00:00 UTC        )          
      :
    hive> select from_unixtime(timestamp,'yyyyMMdd') from tbl_lzo;
    UNIX_TIMESTAMP  
      :unix_timestamp([string date[, string pattern]])
       : bigint
      :   date,   pattern        UNIX   。      0
      :
    hive> select unix_timestamp(), unix_timestamp('2016-01-05 17:50:33'), unix_timestamp('2016-01-05 17:50:33', 'yyyyMMdd') from tbl_lzo;
    TO_DATE  
      :to_date(string datetime)
       :string
      :              
      :
    hive> select to_date('2016-01-05 17:54:22') from tbl_lzo;
    datediff   [date_add,date_sub]
      :datediff(string enddate, string startdate)
       :int
      :               
      :
    hive> select datediff('2016-01-05', '2015-11-13') from tbl_lzo;
    CASE1.CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END
    2.CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END
       :T
      :
    1.  a  b,    c;  a  d,    e;    f
    2.  a TRUE,   b;  c TRUE,   d;    e
length
      : length(string A)
       : int
      :     A   
      :
    hive> select length('abcedfg') from tbl_lzo;
reverse
      : reverse(string A)
       : string
      :     A     
      :
    hive> select reverse('abcedfg’) from tbl_lzo;
           :concat
      : concat(string A, string B…)
       : string
      :             ,          
      :
    hive> select concat(‘abc’,'def’,'gh’) from tbl_lzo;
               :concat_ws
      : concat_ws(string SEP, string A, string B…)
       : string
      :             ,SEP            
      :
    hive> select concat_ws(',','abc','def','gh') from tbl_lzo;
           :substr,substring
      : 
    substr(string A, int start, int len)
    substring(string A, intstart, int len)
       : string
      :     A start    ,   len    
      :
    hive> select substr('abcde',3,2) from tbl_lzo;
    Map    : map
      : map (key1, value1, key2, value2, …)
      :     key value   map  
      :
    hive> Create table lxw_test as select 
    map('100','tom','200','mary')as t from tbl_lzo;

    hive> describe tbl_lzo;
    t       map<string,string>

    hive> select t from tbl_lzo;
    {"100":"tom","200":"mary"}
    Struct    : struct
      : struct(val1, val2, val3, …)
      :            struct  
      :
    hive> create table tbl_lzo as select 
    struct('tom','mary','tim')as t from tbl_lzo;

    hive> describe tbl_lzo;
    t       structstring,col2:string,col3:string>

    hive> select t from tbl_lzo;
    {"col1":"tom","col2":"mary","col3":"tim"}
    array    : array
      : array(val1, val2, …)
      :           array  
      :
    hive> create table tbl_lzo as 
    select array("tom","mary","tim") as t from tbl_lzo;

    hive> describe tbl_lzo;
    t       array<string>

    hive> select t from tbl_lzo;
    ["tom","mary","tim"]
    struct    : S.x
      : S.x
        : S struct  
      :     S  x  。  ,     struct foobar 
{int foo, int bar},foobar.foo       foo  
      :
    hive> create table tbl_lzo as select 
    struct('tom','mary','tim')as t from tbl_lzo;

    hive> describe tbl_lzo;
    t       structstring,col2:string,col3:string>

    hive> select t.col1,t.col3 from tbl_lzo;
    tom     tim
    array      : size(Array)
      : size(Array)
       : int
      :   array     
      :
    hive> select size(array('100','101','102','103')) 
    from tbl_lzo;

リファレンス
詳細コマンドは、以下を参照してください.
http://blog.csdn.net/wisgood/article/details/17376393 http://www.cnblogs.com/end/archive/2012/06/18/2553682.html
ポイント
以下、このブログのポイントを紹介します
        collect_set  
      :collect_set(string column)
       :arrayarray    
      :
    hive> select imei, device_os, collect_set(province), collect_set(game) from s_tbl_lzo where dayid='20160104' group by imei, device_os;

collect_set関数は集約操作に属し、プライマリ・キーに基づいて他のカラムの文字列であるカラムを集約できます.