• hdfs文件导入hive(ods层),格式为ORC


    方式一:

    1、创建库表

    -- 创建库表
    set hive.exec.dynamic.partition=true;
    set hive.exec.dynamic.partition.mode=nonstrict;
    drop table if exists ods_log;
    CREATE EXTERNAL TABLE ods_log (`line` string)
    PARTITIONED BY (`dt` string) -- 按照时间创建分区
    STORED AS -- 指定存储方式
      textfile
    LOCATION '/warehouse/mall/ods/ods_log'  -- 指定数据在hdfs上的存储位置
    ;

    2、加载数据

    --加载数据
    load data  inpath '/flume/data/mall/log/topic_log/2021-04-06' overwrite into table ods_log partition(dt='2021-04-06');

    3、修改表存储格式

    --将表存储格式修改为orc
    ALTER TABLE ods_log SET FILEFORMAT ORC;

    4、查看表存储结构变化

    show create table ods_log;

     方式二:

    1、创建临时表并加载数据

    --创建临时表
    set hive.exec.dynamic.partition=true;
    set hive.exec.dynamic.partition.mode=nonstrict;
    drop table if exists ods_log_tmp;
    CREATE EXTERNAL TABLE ods_log_tmp (`line` string)
    PARTITIONED BY (`dt` string) -- 按照时间创建分区
    STORED AS -- 指定存储方式
      textfile
    LOCATION '/warehouse/mall/ods/ods_log_tmp';
    
    load data  inpath '/flume/data/mall/log/topic_log/2021-04-06' overwrite into table ods_log_tmp partition(dt='2021-04-06');

    2、创建ods库表

    -- 创建库表
    set hive.exec.dynamic.partition=true;
    set hive.exec.dynamic.partition.mode=nonstrict;
    drop table if exists ods_log;
    CREATE EXTERNAL TABLE ods_log (`line` string)
    PARTITIONED BY (`dt` string) -- 按照时间创建分区
    STORED AS -- 指定存储方式
      orc
    LOCATION '/warehouse/mall/ods/ods_log'  -- 指定数据在hdfs上的存储位置
    ;

    3、将数据导入orc格式表中

    -- 加载日志数据  --- 默认压缩格式为snappy
    insert overwrite  table  ods_log partition (dt='2021-04-06') select  line from ods_log_tmp;
  • 相关阅读:
    字典
    字符串常用的方法
    切片,集合、文件处理
    蓝桥杯练习 Day6 题解
    spoj-ORDERS
    spoj-SUBSUMS
    spoj
    spoj --- ABCDEF
    C. Andryusha and Colored Balloons
    B. The Meeting Place Cannot Be Changed
  • 原文地址:https://www.cnblogs.com/ywjfx/p/14621658.html
Copyright © 2020-2023  润新知