zoukankan      html  css  js  c++  java
  • hive 常用命令

    1、创建表

    内部表

    CREATE TABLE table_a (col_1 int, col_2 int, col_3 int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '	';

    外部表

    CREATE EXTERNAL TABLE table_a (col_1 int, col_2 int, col_3 int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '	';

    分区表

    CREATE TABLE table_a (col_1 int, col_2 int, col_3 int) PARTITIONED BY (`type` string COMMENT '分区') ROW FORMAT DELIMITED FIELDS TERMINATED BY '	';

    2、修改表

    表重命名

    ALTER TABLE table_a RENAME TO table_b;

    增加一个字段

    ALTER TABLE table_a ADD COLUMNS (col_4 String);

    修改字段

    alter table table_a change col_4 col_5 string COMMENT '说明'; --改列名
    alter table table_a change col_4 col_4 string COMMENT '说明BB'; -- 改说明
    alter table table_a change col_4 col_4 int COMMENT '说明'; -- 改类型

    删除字段

    ALTER TABLE table_a REPLACE COLUMNS(col_1 int, col_2 int, co_5 string);

    3、导数据

    从本地文件导入到表

    LOAD DATA LOCAL INPATH '/home/aaa.txt' OVERWRITE INTO TABLE table; 

    从hdfs导入

     LOAD DATA INPATH '/xxx/yyy/zzz.txt' OVERWRITE INTO TABLE table_a;

    添加表分区

    ALTER TABLE table_a ADD IF NOT EXISTS PARTITION (type='aa') LOCATION '/xxx/yyy/zzz';

    从查询结果导入表

     INSERT OVERWRITE TABLE table_a SELECT * FROM table_b ;

    从查询结果导入分区

    INSERT OVERWRITE TABLE table_a PARTITION(type='aaa')

    从表导数据到本地

    INSERT OVERWRITE LOCAL DIRECTORY '/tmp/zzz.txt' SELECT * FROM table_a;

    4、查询

    查找表

    SHOW TABLES;
    SHOW TABLES like '*table*';

    显示表结构

    desc table_a;

    显示表创建信息

    show create table table_a;

    数据查询

    select * from table_a;

    关联查询

    select a.* from table_a join table_b on table_a.id=table_b.id;

    查看hive为某个查询使用多少个MapReduce作业

    Explain SELECT a.* FROM table_a JOIN table_b ON (table_a.id = table_b.id); 

    5、分区刷新

    MSCK REPAIR TABLE table_a;
    MSCK: Hive's MetaStore Consistency checK
  • 相关阅读:
    Table Groups [AX 2012]
    Extended Data Type Properties [AX 2012]
    Base Enum Properties [AX 2012]
    Dynamics AX 2012 R2 Business Connector Error
    [转]System.Reflection.AssemblySignatureKeyAttribute
    为博客启用MetaWeBlog API
    How to create UrlSlug in Asp.Net MVC
    Serialize Documents with the C# Driver
    C# Driver LINQ Tutorial
    Getting Started with the C# Driver
  • 原文地址:https://www.cnblogs.com/lamp-lrh/p/13652783.html
Copyright © 2011-2022 走看看