hive官方create介绍
建表
1 CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name -- (Note: TEMPORARY available in Hive 0.14.0 and later) 2 [(col_name data_type [column_constraint_specification] [COMMENT col_comment], ... [constraint_specification])] 3 [COMMENT table_comment] 4 [PARTITIONED BY (col_name data_type [COMMENT col_comment], ...)] 5 [CLUSTERED BY (col_name, col_name, ...) [SORTED BY (col_name [ASC|DESC], ...)] INTO num_buckets BUCKETS] 6 [SKEWED BY (col_name, col_name, ...) -- (Note: Available in Hive 0.10.0 and later)] 7 ON ((col_value, col_value, ...), (col_value, col_value, ...), ...) 8 [STORED AS DIRECTORIES] 9 [ 10 [ROW FORMAT row_format] 11 [STORED AS file_format] 12 | STORED BY 'storage.handler.class.name' [WITH SERDEPROPERTIES (...)] -- (Note: Available in Hive 0.6.0 and later) 13 ] 14 [LOCATION hdfs_path] 15 [TBLPROPERTIES (property_name=property_value, ...)] -- (Note: Available in Hive 0.6.0 and later) 16 [AS select_statement]; -- (Note: Available in Hive 0.5.0 and later; not supported for external tables) 17 18 CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name 19 LIKE existing_table_or_view_name 20 [LOCATION hdfs_path]; 21 22 data_type 23 : primitive_type 24 | array_type 25 | map_type 26 | struct_type 27 | union_type -- (Note: Available in Hive 0.7.0 and later) 28 29 primitive_type 30 : TINYINT 31 | SMALLINT 32 | INT 33 | BIGINT 34 | BOOLEAN 35 | FLOAT 36 | DOUBLE 37 | DOUBLE PRECISION -- (Note: Available in Hive 2.2.0 and later) 38 | STRING 39 | BINARY -- (Note: Available in Hive 0.8.0 and later) 40 | TIMESTAMP -- (Note: Available in Hive 0.8.0 and later) 41 | DECIMAL -- (Note: Available in Hive 0.11.0 and later) 42 | DECIMAL(precision, scale) -- (Note: Available in Hive 0.13.0 and later) 43 | DATE -- (Note: Available in Hive 0.12.0 and later) 44 | VARCHAR -- (Note: Available in Hive 0.12.0 and later) 45 | CHAR -- (Note: Available in Hive 0.13.0 and later) 46 47 array_type 48 : ARRAY < data_type > 49 50 map_type 51 : MAP < primitive_type, data_type > 52 53 struct_type 54 : STRUCT < col_name : data_type [COMMENT col_comment], ...> 55 56 union_type 57 : UNIONTYPE < data_type, data_type, ... > -- (Note: Available in Hive 0.7.0 and later) 58 59 row_format 60 : DELIMITED [FIELDS TERMINATED BY char [ESCAPED BY char]] [COLLECTION ITEMS TERMINATED BY char] 61 [MAP KEYS TERMINATED BY char] [LINES TERMINATED BY char] 62 [NULL DEFINED AS char] -- (Note: Available in Hive 0.13 and later) 63 | SERDE serde_name [WITH SERDEPROPERTIES (property_name=property_value, property_name=property_value, ...)] 64 65 file_format: 66 : SEQUENCEFILE 67 | TEXTFILE -- (Default, depending on hive.default.fileformat configuration) 68 | RCFILE -- (Note: Available in Hive 0.6.0 and later) 69 | ORC -- (Note: Available in Hive 0.11.0 and later) 70 | PARQUET -- (Note: Available in Hive 0.13.0 and later) 71 | AVRO -- (Note: Available in Hive 0.14.0 and later) 72 | JSONFILE -- (Note: Available in Hive 4.0.0 and later) 73 | INPUTFORMAT input_format_classname OUTPUTFORMAT output_format_classname 74 75 column_constraint_specification: 76 : [ PRIMARY KEY|UNIQUE|NOT NULL|DEFAULT [default_value]|CHECK [check_expression] ENABLE|DISABLE NOVALIDATE RELY/NORELY ] 77 78 default_value: 79 : [ LITERAL|CURRENT_USER()|CURRENT_DATE()|CURRENT_TIMESTAMP()|NULL ] 80 81 constraint_specification: 82 : [, PRIMARY KEY (col_name, ...) DISABLE NOVALIDATE RELY/NORELY ] 83 [, PRIMARY KEY (col_name, ...) DISABLE NOVALIDATE RELY/NORELY ] 84 [, CONSTRAINT constraint_name FOREIGN KEY (col_name, ...) REFERENCES table_name(col_name, ...) DISABLE NOVALIDATE 85 [, CONSTRAINT constraint_name UNIQUE (col_name, ...) DISABLE NOVALIDATE RELY/NORELY ] 86 [, CONSTRAINT constraint_name CHECK [check_expression] ENABLE|DISABLE NOVALIDATE RELY/NORELY ]