赞
踩
drop table if exists ods_order_info; create external table ods_order_info ( `id` string COMMENT '订单号', `consignee` string COMMENT '收货人', `consignee_tel` string COMMENT '收件人电话',`final_total_amount` decimal(16,2) COMMENT '订单金额',`order_status` string COMMENT '订单状态', `user_id` string COMMENT '用户id',`delivery_address` string COMMENT '送货地址',`order_comment` string COMMENT '订单备注',`out_trade_no` string COMMENT '支付流水号',`trade_body` string COMMENT '订单描述(第三方支付用)',`create_time` string COMMENT '创建时间', `operate_time` string COMMENT '操作时间', `expire_time` string COMMENT '失效时间', `tracking_no` string COMMENT '物流单编号', `parent_order_id` string COMMENT '父订单编号', `img_url` string COMMENT '图片路径', `province_id` string COMMENT '省份ID', `benefit_reduce_amount` decimal(16,2) COMMENT '优惠金额', `original_total_amount` decimal(16,2) COMMENT '原价金额', `feight_fee` decimal(16,2) COMMENT '运费' ) COMMENT '订单表' PARTITIONED BY (`dt` string) --创建分区 row format delimited fields terminated by '\t' -- 指定分割符为\t location '/data/hive/gmall/order_info/' -- 指定数据在hdfs上的存储位置,此路径会在hdfs中生成 ;
alter table ods_order_info add if not exists partition(dt='2021-04-17') location '2021-04-17';
这里的数据是我之前就存在的了,没有数据的话可以自己造,这个不难,但是用这种方法的话,原来hdfs的文件,会被移动到/data/hive/gmall/order_info/这个目录下面,源文件消失。
load data INPATH '/data/sqoop/gmall/db/order_info/2021-04-17/part-m-00000.gz' overwrite into table ods_order_info PARTITION (dt='2021-04-17');
在原来创建表的语句中的location 的路径,直接改成hdfs源文件所在路径。
location '/data/sqoop/gmall/db/order_info'
因为我们建的是分区表,所以要创建一个分区
alter table ods_order_info add if not exists partition(dt='2021-04-17') location '2021-04-17';
select * from ods_order_info where dt = '2021-04-17';
自学大数据的路中,建了一个交流群,678513209。有转大数据的小伙伴,加群一起交流
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。