hive基本命令

来源:互联网 发布:蓝月翅膀升阶数据 编辑:程序博客网 时间:2024/06/04 19:32
建表语句,表中有map结构:
hive> create table test_score(name string, score map<string,int>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'

建分区表:
hive> create table test_table(id int,date_wid string) partitioned by(day string);
OK
Time taken: 0.084 seconds

删除表
hive> drop table test_table;
Moved: 'hdfs://.../test_table' to trash at: hdfs://.../.Trash/Current
OK
Time taken: 0.865 seconds

创建一个新表,结构与其他一样
hive> create table new_table like old_table;

修改表的名称
hive> alter table test_score rename to test_map;

将本地数据导入表中:
LOAD DATA LOCAL INPATH '/home/webopa/lei.wang/datas_test/test' OVERWRITE INTO TABLE test_map;

hive中删除表数据,但是不删除表结构
方式一:直接删除数据
hive> dfs -rmr /user/hive/warehouse/test_map
方式二:通过查询等到一个空结果集覆盖原表
hive> insert overwrite table test_map select * from test_map where 1=0

查看所有函数
hive> show functions;

修改表属性:
内部表转外部表 
hive> alter table test_map set TBLPROPERTIES ('EXTERNAL'='TRUE');
OK
Time taken: 0.182 seconds
外部表转内部表
hive> alter table test_map set TBLPROPERTIES ('EXTERNAL'='FALSE');
OK
Time taken: 0.217 seconds //外部表转内部表

添加列
在所有存在的列后面,但是在分区列之前添加一列
hive> ALTER TABLE test_map ADD COLUMNS (id int);
OK
Time taken: 0.182 seconds
hive> select * from test_map;
OK
leilei    {"数学":99,"语文":90,"英语":96}    NULL
lucy    {"数学":100,"语文":85,"英语":91}    NULL

删除列
需要删除表并重新建表

修改column属性(列名,列字段类型,列注释)

ALTER TABLE table_name  

CHANGE [COLUMN] col_old_name col_new_name

column_type [COMMENT col_comment] [FIRST|AFTER column_name]  



0 0
原创粉丝点击