创建修改
创建表
CREATE TABLE testtable (foo INT, bar STRING);
CREATE TABLE testtable LIKE other;
CREATE TABLE logs(ts bigint,line string) PARTITIONED BY (dt String,country String);
注:hive建表的时候默认的分割符是' 01',若在建表的时候没有指明分隔符,load文件的时候文件的分隔符需要是' 01'
建表指定分隔符,例:
create table pokes(foo int,bar string) row format delimited fields terminated by ' ' lines terminated by ' ' stored as textfile; load data local inpath '/root/pokes.txt' into table pokes;
更新命令
更新表的名称:
ALTER TABLE source RENAME TO target;
添加新一列
ALTER TABLE invites ADD COLUMNS (new_col2 INT COMMENT 'a comment');
从本地文件加载数据:
hive> LOAD DATA LOCAL INPATH '/home/hadoop/input/ncdc/micro-tab/sample.txt' OVERWRITE INTO TABLE records;
删除表:
DROP TABLE records;
分区表语法
添加分区表语法(表已创建,在此基础上添加分区):ALTER TABLE table_name ADD
partition_spec [ LOCATION 'location1' ]
partition_spec [ LOCATION 'location2' ] ...
ALTER TABLE day_table ADD
PARTITION (dt='2008-08-08', hour='08')
location '/path/pv1.txt'
删除分区语法:ALTER TABLE table_name DROP
partition_spec, partition_spec,...
用户可以用 ALTER TABLE DROP PARTITION 来删除分区。分区的元数据和数据将被一并删除。例:
数据加载进分区表中语法:
例:
查看命令
展示表中有多少分区:
SHOW PARTITIONS logs;
SHOW TABLES '.*s';
显示表的结构信息
DESCRIBE testtable;
显示所有函数:
hive> show functions;
查看函数用法:
hive> describe function substr;
查看数组、map、结构
hive> select col1[0],col2['b'],col3.c from complex;
参考源:http://blog.csdn.net/xiaoping8411/article/details/7605039