赞
踩
CREATE [TEMPORARY][EXTERNAL] TABLE [IF NOT EXISTS][db_name.]table_name
[COMMENT table_comment]
[PARTITIONED BY (col_name data_type[COMMENT col_comment],...)]
[CLUSTERED BY (col_name,col_name,...)[SORTED BY (col_name[ASC|DESC],...)]INTO num_buckets BUCKETS]
[ROW FORMAT DELIMITED|SERDE serde_name WITH SERDEPROPERTIES(property_name=property_value,...)]
[STORED AS file_format]
[LOCATION hdfs_path]
[TBLPROPERTIES(property_name=property_value,...)];
ROW FORMAT DELIMITED|SERDE
DELIMITED
表示使用默认的LazySimpleSerDe类来处理数据ROW FORMAT SERDE serde_name
指定其他SerDe类来处理数据,甚至支持用户自定义类LazySimpleSerDe
包含四种子语法,用于指定字段之间、集合元素之间、map映射kv之间、换行的分隔符号。ROW FORMAT DELIMITED
[FIELDS TERMINATED BY char] #字符之间分隔符
[COLLECTION ITEMS TERMINATED BY char] #集合元素之间分隔符
[MAP KEYS TERMINATED BY char] #Map映射kv之间分隔符
[LINES TERMINATED BY char] #行数据之间分隔符
ROW FORMAT SERDE ser_name
[WITH SERDEPROPERTIES
(property_name=property_value,
property_name=proberty_value,..)]
\001
使用的是ASCLL编码的值。location
语法更改数据存储路径。LOCATION '<hdfs_location>'
--创建数据库并切换使用 CREATE DATABASE IF NOT EXISTS pljnb; USE pljnb; -- 创建表 CREATE TABLE t_archer( id INT COMMENT "ID", name STRING COMMENT "英雄名称", hp_max INT COMMENT "最大生命", mp_max INT COMMENT "最大法力", attack_max INT COMMENT "最高物攻", defense_max INT COMMENT "最大物防", attack_range STRING COMMENT "攻击范围", role_main STRING COMMENT "主要定位", role_assist STRING COMMENT "次要定位" )COMMENT "王者荣耀射手信息" ROW FORMAT DELIMITED FIELDS TERMINATED BY "\t";
CREATE TABLE t_hot_hero_skin_price(
id INT,
name STRING,
win_rate INT,
skin_price MAP<STRING,INT>
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',' --字段间分隔符
COLLECTION ITEMS TERMINATED BY '-' --集合元素之间分隔符
MAP KEYS TERMINATED BY ':'; --集合元素kv之间分隔符
\001
,则建表时可以不指定分隔符。CREATE TABLE t_team_ace_player(
id INT,
team_name STRING,
ace_player_name STRING
);
CREATE TABLE t_team_ace_player_location(
id INT,
team_name STRING,
ace_player_name STRING
)
LOCATION '/data'; --使用location关键字指定路径表在hdfs上的存储路径
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。