zoukankan      html  css  js  c++  java
  • 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 ' ' 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























  • 相关阅读:
    assignment of day nine
    不会互相转化,看我的
    enumrate用法
    这是作业
    这是表格
    本周回顾
    爬虫
    今天又学了啥?
    what have we learnt in day five
    OMG that's another blog!
  • 原文地址:https://www.cnblogs.com/skyrim/p/7455891.html
Copyright © 2011-2022 走看看