CREATE TABLE LIKE
描述
CREATE TABLE
语句使用现有表或视图的定义/元数据定义新表。
语法
CREATE TABLE [IF NOT EXISTS] table_identifier LIKE source_table_identifier
[ USING data_source ]
[ ROW FORMAT row_format ]
[ STORED ( AS file_format | STORED BY storage_handler ) ]
[ TBLPROPERTIES ( key1=val1, key2=val2, ... ) ]
参数
table_identifier
指定表名,可以选择使用数据库名进行限定。
语法:
[ database_name. ] table_name
USING data_source
Data Source is the input format used to create the table. Data source can be CSV, TXT, ORC, JDBC, PARQUET, etc.
ROW FORMAT
SERDE is used to specify a custom SerDe or the DELIMITED clause in order to use the native SerDe.
STORED AS
File format for table storage, could be TEXTFILE, ORC, PARQUET, etc.
TBLPROPERTIES
Table properties that have to be set are specified, such as
created.by.user
,owner
, etc.LOCATION
Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. Location to create an external table.
示例
-- Create table using an existing table
CREATE TABLE Student_Dupli like Student;
-- Create table like using a data source
CREATE TABLE Student_Dupli like Student USING CSV;
-- Create table like using a rowformat
CREATE TABLE Student_Dupli like Student
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE
TBLPROPERTIES ('owner'='xxxx');
相关语句
TODO
- location 可以考虑直接禁用
- row format 和 stored as 应该也得考虑下怎么处理
- visitCreateTableLike 可能需要改一下
- properties 没生效?