hdfs文件加載進hive表的兩種方法


1.第一種方法 當存儲路徑與表所在路徑不一致時,可以load進去,如果表中字段類型不對應,該字段的值將會為空

load data inpath 'hdfs://hadoop01:9000/tmp/sales_info.txt' overwrite into table sales_info partition(dt = '20191215');

 

2.當存儲路徑與表所在路徑一致時,可以采用添加分區的方式

alter table ods_nshop.ods_01_releasedatas add partition (bdp_day='20191215') location 'hdfs://hadoop01:9000/data/nshop/ods/release/bdp_day=20191215'

hive的表如下:

create external table if not exists ods_nshop.ods_01_releasedatas(
  customer_id string comment '用戶id',
  device_num string comment '設備號',
  device_type string comment '設備類型',
  os string comment '手機系統',
  os_version string comment '手機系統版本',
  manufacturer string comment '手機制造商',
  area_code string comment '地區編碼',
  release_sid string comment '投放請求id',
  release_session string comment '投放會話id',
  release_sources string comment '投放渠道',
  release_params string comment '投放請求參數',
  ct bigint comment '創建時間'

partitioned by (bdp_day string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
stored as textfile
location '/data/nshop/ods/release/'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM