zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    定义结构体
    UML建模需求分析常用的UML图
    UML建模EA模型的组织
    优化Python脚本替换VC2005/2008工程x64配置
    C++插件框架已在 Mac OS X 下编译通过
    《iPhone开发快速入门》交流提纲
    X3插件框架发布v1.1.3
    从零开始创建一个插件
    Google论坛什么时候又可以使用的
    我的第一个Py脚本:批量替换VC工程中的x64条件定义配置
  • 原文地址:https://www.cnblogs.com/ywjfx/p/14621658.html
Copyright © 2011-2022 走看看