<一>数据定义(DML)操作
1、创建普通表
create table page_view
(viewtime int,
userid bigint,
page_url string,
referrer_url string,
ip STRING comment 'IP Address of the User')
comment 'This is the page view table' ;
create table page_view
(viewtime int,
userid bigint,
page_url string,
referrer_url string,
ip STRING comment 'IP Address of the User')
comment 'This is the page view table'
partitioned by (dt string , country string)
row format delimited
fields terminated by '\001'
stored as sequencefile;
create table page_view
(viewtime int,
userid bigint,
page_url string,
referrer_url string,
ip STRING comment 'IP Address of the User')
comment 'This is the page view table'
partitioned by (dt string , country string)
clustered by(userid) sorted by(viewTime) into 32 buckets
row format delimited --delimite限制
fields terminated by '\001'
collection items terminated by '\002'
map keys terminated by '\003'
stored as sequencefile;
create table page_view
(viewtime int,
userid bigint,
page_url string,
referrer_url string,
ip STRING comment 'IP Address of the User')
comment 'This is the page view table'
row format delimited
fields terminated by '\054'
stored as textfile
location '';
alter table tablename rename to new_table_name ;
create table test (a int , b int , c int);
alter table test change a a1 int ;
alter table test change a a1 string after b ;
alter table test change b b1 int first ;
注意:列的改变只会修改hive的元数据,不会修改实际数据。用户应该确保元数据定义和实际数据结构的一致性。
7、增加/更新列
alter table test add|replace
columns (d int comment 'new columns');
注:replace,删除当前的列,增加新的列。只有使用native的SerDE时才可以这么做。
alter table table_name set tblproperties table_properties
table_properties:
:(property_name = property_value , property_name = property_value)
alter table table_name
set serde serde_class_name
[with serdeproperties serde_properties]
alter table table_name
set serdeproperties serde_properties
ser_properties:
:(property_name =property_value , property_name = property_value)
注:Hive 为了序列化和反序列化,将会初始化SerDe属性。
10、改变文件格式和组织
alter table table_name set fileformat file_format ;
alter table table_name clustered by (col_name,col_name,...)
[sorted by (col_name,col_name,...)] into num_buckets buckets
alter table page_view add
partition (dt='2010-08-08',country='us')
location '/path/to/us/part080808'
partition (dt='2010-08-09',country='us')
location '/path/to/us/part080809';
alter table page_view drop
partition (dt='2010-08-08',country='us');
create view [if not exists] view
[(column_name [comment column_comment],...)]
[comment view_coment]
as select ... ;
create temporary funcation funcation_name as class_name;
drop temporary funcation_name ;
其他的可以参考:http://blog.csdn.net/lifuxiangcaohui/article/details/40588929
<三>数据查询(DCL)
与标准的SQL类似。