表结构
row format
delimited 文本适用
serde 序列化反序列化{二进制文件,正则解析}
文件格式:text,orc
复制表 create table xxx like
克隆表 create table xxx as
删除表drop table if exists tableName
修改表名称 alter table table_name rename to new_tableName
修改表字段 ALTER TABLE table_name [PARTITION partition_spec] CHANGE [COLUMN] col_old_name col_new_name column_type
[COMMENT col_comment] [FIRST|AFTER column_name] [CASCADE|RESTRICT];
创建表(默认创建的是内部表managed)
create table source_log(ip string,mid string,url string,status string,time string)row formatdelimilted fieldsterminated by " ";
导入数据
load data inpath "/flume/20181113/events-.1542075425513" into table source_log;
从一个表中查询到数据插入到一个已存在的表中
insert into table clear_logselect ip,mid,substring(time,0,8),substring(time,9,2)hourfrom source_log;insert into table result_logselect day,hour,count(ip) pv,count(distinct(mid)) uvfrom clear_loggroup by day,hour;导入的表中已存在数据,要想覆盖原来的数据insert overwrite table clear_logselect ip,mid,substring(time,0,8),substring(time,9,2)hourfrom source_log;
数据类型
-
数值类型:整型 int,bigint 浮点型double decimal(10,2)
-
字符类型:string
-
日期类型:date,timestamp
-
Misc Types(杂项类型):boolean,BINARY
-
复合数据类型:ARRAY,MAP STRUCT,UNIONTYPE
数据类型的转换可以通过隐式转换
也可以通过函数cast(数据 as 其他的数据类型)
函数substr和substring
语法 :substr(字段,starindex,len) 下标从 1 开始
