• Hive之import和export使用详解


    在hive-0.8.0后引入了import/export命令。

    Export命令可以导出一张表或分区的数据和元数据信息到一个输出位置,并且导出数据可以被移动到另一个hadoop集群或hive实例,并且可以通过import命令导入数据。

    当导出一个分区表,原始数据可能在hdfs的不同位置,export/import命令也支持导出分区表的不同子分区。

    导出的元数据存储在目标目录,并且数据文件是存储在不同的子目录下。

    Export/import命令可以独立工作在使用存储元数据的rdbms中。

    一、语法

    Export语法:

    EXPORT TABLE tablename [PARTITION (part_column="value"[, ...])]

    TO 'export_target_path' [ FOR replication('eventid') ]

    Import语法:

    IMPORT [[EXTERNAL] TABLE new_or_original_tablename [PARTITION (part_column="value"[, ...])]]

    FROM 'source_path'

    [LOCATION 'import_target_path']

    二、使用复制:

    Export/import命令当在复制环境中使用时略有不同,并且确定使用该工具在两个数据仓库之间使用复制。在大多数情况下,用户不需要使用这个附加功能,除非手动引导仓库之间的复制,这样它可以作为一个增量复制工具。

    他们使用一个特殊的表属性“repl.last.id”在一个表或分区对象中,确保export/import工具每次复制的数据时最近更新的数据。在导出完成后,会对export的dump文件使用一个id打一个复制标签,表示在源仓库集成商单调递增的。此外,为复制导出打印的标记不会导致错误如果试图导出一个对象但是标记列当前不存在。

    在import方面,没有语法变化,但是import有一个一般性的标签对于复制的dump文件,他讲检查要复制的对象是否存在,如果对象已经存在,它检查对象的repl.last.id属性,确定是否导入当前对象的最新数据对于目标仓库,如果更新是最新的,那么它将复制最新的信息,如果更新已经是很旧的了对于已经存在的对象,那么更新将被忽略,并且不会产生错误。

    对于那些使用export进行首次手动引导用例,用户推荐使用“引导”标签,

    三、示例

    1、简单导入和导出

    export table department to 'hdfs_exports_location/department';

    import from 'hdfs_exports_location/department';

    2、在import时重命名表

    export table department to 'hdfs_exports_location/department';

    import table imported_dept from 'hdfs_exports_location/department';

    3、导出分区并且导入

    export table employee partition (emp_country="in", emp_state="ka") to 'hdfs_exports_location/employee';

    import from 'hdfs_exports_location/employee';

    4、导出表并且导入到分区表分区

    export table employee to 'hdfs_exports_location/employee';

    import table employee partition (emp_country="us", emp_state="tn") from 'hdfs_exports_location/employee';

    5、指定导入位置

    export table department to 'hdfs_exports_location/department';

    import table department from 'hdfs_exports_location/department'

           location 'import_target_location/department';

    6、导入作为一个外部表

    export table department to 'hdfs_exports_location/department';

    import external table department from 'hdfs_exports_location/department';

  • 相关阅读:
    《Advanced Bash-scripting Guide》学习(十九):两个整数的最大公约数
    《Advanced Bash-scripting Guide》学习(十八):[[ ]]与[ ]的一些特殊情况
    《Advanced Bash-scripting Guide》学习(十七):用more来查看gzip文件
    《Advanced Bash-scripting Guide》学习(十六):一个显示输入类型的脚本
    《Advanced Bash-scripting Guide》学习(十五):测试坏的链接文件(broken link)
    《Advanced Bash-scripting Guide》学习(十四):HERE Document和cat <<EOF
    《Advanced Bash-scripting Guide》学习(十三):引用变量的两个例子
    NOIP2016 蚯蚓
    [SCOI2012]滑雪与时间胶囊
    NOIP2016 天天爱跑步 80分暴力
  • 原文地址:https://www.cnblogs.com/wcwen1990/p/6845850.html
Copyright © 2020-2023  润新知