查看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;