
# CREATE TABLE AS SELECT
#### 命令功能
CREATE TABLE As SELECT命令通过指定带有表属性的字段列表来创建Hudi Table。
#### 命令格式
**CREATE TABLE** *\[ IF NOT EXISTS\] \[database_name.\]table_name*
**USING hudi**
*\[ COMMENT table_comment \]*
*\[ LOCATION location_path \]*
*\[ OPTIONS (options_list) \]*
*\[ AS query_statement \]*
#### 参数描述
表1CREATE TABLE As SELECT参数描述 
| **参数**          | **描述**                        |
|:---|:---|
| database_name   | Database名称，由字母、数字和下划线（_）组成。   |
| table_name      | Database中的表名，由字母、数字和下划线（_）组成。 |
| using           | 参数hudi，定义和创建Hudi table。       |
| table_comment   | 表的描述信息。                       |
| location_path   | HDFS路径，指定该路径Hudi表会创建为外表。      |
| options_list    | Hudi table属性列表。               |
| query_statement | select查询表达式。                  |
   
#### 示例
- 创建分区表：
  ```
  create table h2 using hudi
  options (type = 'cow', primaryKey = 'id')
  partitioned by (dt)
  as
  select 1 as id, 'a1' as name, 10 as price, 1000 as dt;
  ```
  
- 创建非分区表：
  ```
  create table h3 using hudi
  as
  select 1 as id, 'a1' as name, 10 as price;
  从parquet表加载数据到Hudi表
  # 创建parquet表
  create table parquet_mngd using parquet options(path=’hdfs:///tmp/parquet_dataset/*.parquet’);
  # CTAS创建Hudi表
  create table hudi_tbl using hudi location 'hdfs:///tmp/hudi/hudi_tbl/' options (
  type = 'cow',
  primaryKey = 'id',
  preCombineField = 'ts'
  )
  partitioned by (datestr) as select * from parquet_mngd;
  ```
  
 
#### 注意事项
为了更好的加载数据性能，CTAS使用bulk insert作为写入方式。
#### 系统响应
Table创建成功，创建成功的消息将被记录在系统日志中。
