Hive:DCL(库表结构)

表创建:1.create   2.文件导入  3.creat + select

方式一:create

  • create table 表名(字段1 类型,字段2 类型,...,字段n 类型,) row format delimited fields terminated by '\t';
    ------------------------------------------------------
    create table user_info(id bigint, account string, name string) row format delimited fields terminated by '\t'; 

方式二: 文件导入 

  • load data local inpath '/路径/../文件名(尽量=表名)' into table 表名;
    --------------------------------------------------
    load data local inpath '/home/hadoop/data/user_info' into table user_info;   
    
    ------------------------------------------------------------------------
    load data inpath '路径/表文件' into table 表名 partition (分区名)
    ----------------------
    load data inpath '/outout/p*' into table tbl2 partition (logdate='2020-12'); 

方式三:creat + select

  • create table 表名 row format delimited fields terminated by '\t' 
    as
    	select 基表(字段列表 )
        from  基表
    	[where 条件]
    	[join  基表2] 
    	[on    条件]  ;
    ----------------------------------
    create table result row format delimited fields terminated by '\t' 
    as
    	select t1.account, t1.income, t1.surplus, t2.name 
    	from user_info t2 
    	join 
    		(select account, sum(income) as income, sum(income-expenses) as surplus 
    		from trade_detail 
    		group by account) t1 
    	on(t1.account = t2.account);
    ---------------------------------------------------------
    create table pv row format delimited fields terminated by '\t' 
    as 
        select count(*) from logs where date='2020-12-25';

创建 外部表

  • create external table 表名(字段名 字段类型...列表) 
    partitioned by (分区字段 字段类型) 
    row format delimited fields terminated by '\t' 
    location '存放路径';
    ----------------------
    create external table t_detail(id bigint, account string, income double,time string) 
    partitioned by (logdate string) 
    row format delimited fields terminated by '\t' 
    location '/hive/mytb_partition';

分区创建和修改

分区添加或删除

  • alter table 表名 add/delete partition (分区信息) location '/路径/文件夹名==分区
    --------------------
    alter table daxiang add partition (nation='in') location '/hive/daxiang/nation=in'
    

猜你喜欢

转载自blog.csdn.net/JinChao94/article/details/111613246
今日推荐