hive创建外部表

  1. Create [EXTERNAL] TABLE [IF NOT EXISTS] table_name
  2. [(col_name data_type [COMMENT col_comment], ...)]
  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. [ROW FORMAT row_format]
  7. [STORED AS file_format]
  8. [LOCATION hdfs_path]
例子:
  1. create EXTERNAL table IF NOT EXISTS userInfo (id int,sex string, age int, name string, email string,sd string, ed string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' location '/hive/dw';
注意:location必须是个目录,而不是文件!

t表:
  1. a,aaa,bbb
  2. 2,ccc,ddd
  3. adfd,eee,fff
创建T表:
  1. create EXTERNAL table IF NOT EXISTS t (
  2. id int,
  3. s1 string,
  4. s2 string
  5. )
  6. ROW FORMAT DELIMITED
  7. FIELDS TERMINATED BY ','
  8. location '/user/hive/warehouse/t';
查询:
  1. hive>
  2. > select * from t;
  3. OK
  4. NULL bbb NULL
  5. 2 ccc ddd
  6. NULL eee fff
  7. Time taken: 2.051 seconds, Fetched: 3 row(s)
如果数据类型不对,则hive表示为NULL























posted on 2017-08-30 23:10  月饼馅饺子  阅读(644)  评论(0编辑  收藏  举报

导航