• hive常用操作


    1. 文件导入到hdfs

    从本地/tmp/path下拷贝文件上传到hive表test中的CHINA分区中。

    LOAD DATA LOCAL INPATH '/tmp/path/' OVERWRITE  INTO TABLE test PARTITION (country='CHINA')

    2. hive -f 带参数

    ⭐️注意⭐️:使用hive -e 查询时,查询结果是写入不了hive表中的,必须使用hive -f !!!!!!!

    带参数的脚本,script.q为sql语句,每个变量都需要通过--hivevar添加

    hive -f script.q --hiveconf params_dt=20180418 --hiveconf tmp_table=tmp_table

    script.q脚本中使用变量如下:

    insert into table dw_dm.target_table partition(dim,period)
    select  field1,field2,dim,period 
    from ${hiveconf:tmp_table}
    where dt = '${hiveconf:params_dt}';

     3. hive中查看function

    show functions;   //查看所有函数
    
    desc function extended data_format;   //查看函数具体定义

    4. 日期转换

    方法1: from_unixtime+ unix_timestamp
    --20171205转成2017-12-05 
    select from_unixtime(unix_timestamp('20171205','yyyymmdd'),'yyyy-mm-dd') from dual;
    
    --2017-12-05转成20171205
    select from_unixtime(unix_timestamp('2017-12-05','yyyy-mm-dd'),'yyyymmdd') from dual;
    
    方法2: substr + concat
    --20171205转成2017-12-05 
    select concat(substr('20171205',1,4),'-',substr('20171205',5,2),'-',substr('20171205',7,2)) from dual;
    
    --2017-12-05转成20171205
    select concat(substr('2017-12-05',1,4),substr('2017-12-05',6,2),substr('2017-12-05',9,2)) from dual;
  • 相关阅读:
    笔记-[5]-关于JS事件流!
    JS中的模块化开发之Sea.JS
    利用JavaScript如何创建一个table表格[第2种方法]
    二维数组左滑删除某一行
    sdwebimage缓存图片
    scrollView中内部控件的悬停
    (转)将图片保存到相册
    离屏渲染
    标签栏隐藏
    iOS8新特性之交互式通知
  • 原文地址:https://www.cnblogs.com/30go/p/8694185.html
Copyright © 2020-2023  润新知