zoukankan      html  css  js  c++  java
  • 对于hive使用的一点记录

    最近一段时间因工作需要接触了一些hive上的使用!当然大部分都是比较基本的使用,仅当入门!各位看到有不足之处望多多指正!

    废话不多说,开始:

    首先是创建数据库

    create database ‘数据库名称’

    创建外部表(大部分时候我使用的是外部表):

    CREATE EXTERNAL TABLE tmp.lng_lat(
    lng string,
    lat string)
    ROW FORMAT SERDE
    'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
    WITH SERDEPROPERTIES (
    'field.delim'=',',
    'line.delim'=' ',
    'serialization.format'=',')
    STORED AS INPUTFORMAT
    'org.apache.hadoop.mapred.TextInputFormat'
    OUTPUTFORMAT
    'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
    LOCATION
    '/user/guojienan/tmp/tmp1/lng_lat'

    注意 “ ' ” 并不是引号  是键盘左上角的 “ ~ ” 号! 

    LOCATION
    '/user/guojienan/tmp/tmp1/lng_lat'
    是指外表存放路径!
     
    停用临时表
    drop table 数据库名称.表名
    查看建表语句:
    show create table
    插入数据:
    向外表插入数据
    insert into table tmp.tmp_xiaoqutong
    SELECT(查询语句) from
    直接数据插入分区
    INSERT INTO TABLE test_olap_event PARTITION (date='2018-01-19',hour='02') values('1',88888888,7777777)
    覆盖插入
    INSERT OVERWRITE TABLE test_olap_event PARTITION (date='2018-01-19',hour='02') values('1',88888888,7777777)
     
    连接函数的一点用法
    concat、concat_ws、group_concat函数用法
    一、concat()函数可以连接一个或者多个字符串
      CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串。如有任何一个参数为NULL ,则返回值为 NULL。
      select concat('11','22','33');     112233
    二、CONCAT_WS(separator,str1,str2,...) 
      是CONCAT()的特殊形式。第一个参数是其它参数的分隔符。分隔符的位置放在要连接的两个字符串之间。分隔符可以是一个字符串,也可以是其它参数。
        select concat_ws(',','11','22','33');    11,22,33
    三、group_concat()分组拼接函数
      group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
      对下面的一组数据使用 group_concat()
      | id |name
      |1 | 10|
      |1 | 20|
      |1 | 20|
      |2 | 20|
      |3 | 200   |
      |3 | 500   |
      1、select id,group_concat(name) from aa group by id;
      |1 | 10,20,20|
      |2 | 20 |
      |3 | 200,500|
      2、select id,group_concat(name separator ';') from aa group by id;
      |1 | 10;20;20 |
      |2 | 20|
      |3 | 200;500   |
      3、select id,group_concat(name order by name desc) from aa group by id;
      |1 | 20,20,10   |
      |2 | 20|
      |3 | 500,200|
      4、select id,group_concat(distinct name) from aa group by id;
      |1 | 10,20|
      |2 | 20   |
      |3 | 200,500 |
     
     
     
     
     
  • 相关阅读:
    JavaScript:事件
    JavaScript系统对象
    DOM基础:table(表格)
    DOM基础
    Cookie的简单实用
    javascript:变量的作用域
    javascript:没有定义的变量和没有定义的属性
    数组的基本使用
    静态代码块、代码块、构造函数、匿名内部类、匿名内部类中的代码块
    java使用指定的国际化文件
  • 原文地址:https://www.cnblogs.com/baierfa/p/8334524.html
Copyright © 2011-2022 走看看