Hive建表语句

  • 16

Hive建表语句

Hive创建语句格式如下:

CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name
[(column_name data_type [COMMENT column_comment], ...)]
[COMMENT table_comment]
[PARTITIONED BY (column_name data_type [COMMENT column_comment], ...)]
[CLUSTERED BY (column_name1, column_name2, ...)]
[SORTED BY (column_name [ASC|DESC], ...) INTO num_buckets BUCKETS]
[ROW FORMAT DELIMITED]
  [FIELDS TERMINATED BY fields_format]
  [LINES TERMINATED BY lines_format]
[STORED AS file_format]
[LOCATION hdfs_path]

范例

CREATE TABLE hive.student (
	id VARCHAR(255)  primary key DISABLE NOVALIDATE RELY comment '主键',
	name VARCHAR(255) comment '姓名',
	xb INT NOT NULL comment '性别',
	age INT comment '年龄'
) 
row format delimited
fields terminated by ','
comment '学生表';

如果在创建Hive表时提示权限不够,说明是Hadoop对应的hdfs目录权限没有写的权限,执行下面命令进行赋值操作

./hadoop fs -chmod -R 777 /

发表评论