Hive中的CREATE
语句用于创建表、分区表、外部表等
CREATE TABLE table_name (
column1 data_type,
column2 data_type,
...
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY 'delimiter'
STORED AS file_format;
示例:
CREATE TABLE employees (
id INT,
name STRING,
age INT
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE;
CREATE TABLE table_name (
column1 data_type,
column2 data_type,
...
)
PARTITIONED BY (partition_column1 data_type, partition_column2 data_type, ...)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY 'delimiter'
STORED AS file_format;
示例:
CREATE TABLE sales (
order_id INT,
product_id INT,
customer_id INT,
quantity INT,
price FLOAT
)
PARTITIONED BY (order_date STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE;
CREATE EXTERNAL TABLE table_name (
column1 data_type,
column2 data_type,
...
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY 'delimiter'
STORED AS file_format
LOCATION 'hdfs_path';
示例:
CREATE EXTERNAL TABLE customer_data (
id INT,
name STRING,
age INT
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE
LOCATION 'hdfs://localhost:9000/user/customer_data';
请注意,这些示例中的data_type
、delimiter
和file_format
需要根据实际需求进行替换。在实际使用中,还需要考虑Hive的元数据存储(通常是HDFS)的可用性和配置。