入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

Hive 笔记之 创建外部分区表并加载数据

创建时间:2015-09-26 投稿人: 浏览次数:2523

第一  创建数据库并自定义路径 如 /sogou/500w

         hive> create  database  sogou location "/sogou/500w" ;

              进入改表中创建表

        hive> use sogou;

第二步 创建外部分区表 如 sogou_partition

        hive> create external   table sogou_partition (ts string,uid string,keyword string,rank int ,order int,ulr string)    partitioned by (year string,month string,day stirng,hour string) row Format delimited fields  terminated by " " location "/sogou";


       标准格式 (注意关键字要大写)

       hive> CREATE EXTERNAL TABLE sogou_partition(ts STRING,uid STRING,keyword STRING,rank INT, order INT, url STRING) PARTITIONED BY (year STRING,month STRING,day STRING,hour STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY " " LOCATION "/sogou_3/500w";

       名词解释: 

       row  行

       format  格式化

       delimited    划定界限的

       fields  区域

       terminated 终止


第三步 加载数据

       hive> load   data  local  inpath  "/home/zkpk/resource/sogou-data/500w/ sogou.500w.utf8"  into   table  sogou_partition_3  partition (year="2011",month="12",day="30",hour="10");


第四步查询数据(前100行)

       hive> select * from  搜狗_partition_3 limit 100;


声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。