hive sq操作

查看hive版本号:

hive> set hive.hwi.war.file

创建外表:

hive> create external table table_name (
	> name string,
	> type string,
	> comment string
	> )  
	> partitioned by (dt string)
	> row format delimited 
	> fields terminated by '\t'
	> location hdfs_path;

添加外部表分区:

hive> alter table table_name add partition (dt='2018-01-22') 
	> location hdfs_path;

分区可以通过多个维度来进行。例如通过日期划分之后,我们可以根据国家进一步划分,使用 PARTITIONED BY从句,该从句接受一个字段列表:

hive> CREATE TABLE logs (ts BIGINT , line STRING) 
	> PARTITIONED BY (dt STRING,country STRING); 

当导入数据到分区表时,分区的值被显式指定:

hive> LOAD DATA INPATH '/user/root/path'
	> INTO TABLE logs
	> PARTITION (dt='2001-01-01',country='GB');

查看外表信息:

hive> desc extended table_name;

查看表分区:

hive> show partitions table_name;

更改列属性:

ALTER TABLE table_name CHANGE
[CLOUMN] col_old_name col_new_name column_type
[CONMMENT col_conmment]
[FIRST|AFTER column_name];

hive> ALTER TABLE test_table CHANGE col1 col2 STRING COMMENT 'The datatype of col2 is STRING' AFTER col3;
// 将列名col1修改为col2,数据类型为STRING并添加注释,最后将这一列放在col3后面。

更改表权限,脱敏

alter table table_name set tblproperties('SENSITIVE_TABLE'='FALSE');

删除表:

hive> drop table if exists table_name;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值