zoukankan      html  css  js  c++  java
  • db2导出数据并导入hive临时表中

    操作:

    1、从db2 中导出数据到txt中

    2、修改文件中的分隔符为“:”

    3、在hive中新建表(建表时需要制定分隔符)

    4、导入数据

    --------

    1、从db2 中导出数据到txt中

    db2 -x "select col1,col2,col3  from tbl_name where xxx with ur">filename.txt

    2、修改文件中的分隔符为“:”

    cat filename.txt | awk '{print $1":"$2":"$3}'>filename1.txt

    3、在hive中新建表(建表时需要制定分隔符)

    ROW FORMAT DELIMITED 分隔符设置开始语句

    FIELDS TERMINATED BY:设置字段与字段之间的分隔符

    COLLECTION ITEMS TERMINATED BY:设置一个复杂类型(array,struct)字段的各个item之间的分隔符

    MAP KEYS TERMINATED BY:设置一个复杂类型(Map)字段的key value之间的分隔符

    Hive> create table t(id struct<id1:int,id2:int,id3:int>,name array<string>,xx map<int,string>)
        > row format delimited
        > fields terminated by ' '
        > collection items terminated by ','
        > map keys terminated by ':'
        > lines terminated by ' ';
    OK
    Time taken: 0.287 seconds

    ROW FORMAT DELIMITED 必须在其它分隔设置之前,也就是分隔符设置语句的最前

    LINES TERMINATED BY必须在其它分隔设置之后,也就是分隔符设置语句的最后,否则会报错

    hive> create table t (id struct<id1:int,id2:int,id3:int>,name array<string>,xx map<int,string>) 
        > row format delimited
        > fields terminated by ' '
        > lines terminated by ' '
        > collection items terminated by ','
        > map keys terminated by ':';
    FAILED: ParseException line 5:0 missing EOF at 'collection' near '' ''

    4、导入数据至hive中

    load data local inpath 'filename1.txt' into table tbl_cdhd_usr_id_xxt_tmp 

  • 相关阅读:
    启动Kafka
    利用Flume将本地文件数据中收集到HDFS
    集群安装hbase
    安装并配置hive
    python文件引用其他文件中的变量
    模拟用户登录爬取淘宝数据
    信息领域热词分析系统--详细设计说明书
    信息领域热词分析系统--词云
    《TCP/IP详解卷1:协议》——第4章 ARP:地址解析协议(转载)
    深入理解计算机系统——第12章:多线程中共享变量
  • 原文地址:https://www.cnblogs.com/xitingxie/p/6758950.html
Copyright © 2011-2022 走看看