zoukankan      html  css  js  c++  java
  • hive的简单操作语句

    **1.create table**
    1.1创建分区表
    create [external] table [if not exists] dcx1234(
        cookieid string,
        create_tiem STRING,
        pv int
    ) comment 'dcx1234表'
    partition by (dt string comment '日期分区字段(YYYYMMDD)')
    ;

    1.2复制一个空表
    create table empty_dcx1234 like dcx1234;

    **2.alter table**
    2.1 添加分区
    alter table dcx1234 add [if not exists] partition (dt='${bdp.system.bizdate}')
    2.2 删除分区
    alter table dcx1234 drop partition (dt='${bdp.system.bizdate}')
    2.3 重命名表
    alter table dcx1234 rename to new_table_name
    2.4 修改列/属性
    alter table dcx1234 change column create_tiem create_time STRING;
    2.5 添加列
    alter table dcx1 add columns(create_time_bak string)
    2.6 删除列   (hive中删除列时没有与mysql语句alter table <table> drop column <col>对应的语句。)
    alter table dcx1 replace columns (create_time_bak string);   --只保留create_time_bak这一列,实现机制是把表中的字段先全部删除,然后在增加create_time_bak这一列      --odps中暂时不支持此语句

    **3.查看表结构**
    desc dcx1234

    **4.加载**
    LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)]

    **5.插入**
    insert overwrite table dcx1234 partition  (dt='${bdp.system.bizdate}')
    select a.xx,a.xx,a.xx from a;

    **6.查询**  (如果是分区表,要限制分区)
    select cookieid,create_time,pv
       from dcx1234
      where dt='${bdp.system.bizdate}'

  • 相关阅读:
    【转】C++11优化使用emplace,emplace_back
    面试经历总结
    Hive常用函数
    股票指标
    Visual Studio Code 可以翻盘成功主要是因为什么?
    openpyxl模块操作Excel
    JavaScript(二)
    前端之CSS
    ps导出ICO格式
    Qt 所有版本官方下载地址
  • 原文地址:https://www.cnblogs.com/dcx-1993/p/10232178.html
Copyright © 2011-2022 走看看