详情页标题前

阿里云对象存储OSS使用JindoTable MoveTo命令将Hive表和分区数据迁移至OSS-HDFS服务-云淘科技

详情页1

本文介绍如何使用JindoTable MoveTo命令将Hive分区数据迁移至OSS-HDFS服务。

前提条件

  • 已创建EMR-3.36.0及以上版本(除3.39.x版本以外)或EMR-5.2.0(除5.5.x版本以外)及以上版本的集群。具体步骤,请参见创建集群。
  • 已通过Hive命令创建分区表,且表中已写入数据。本教程以创建名为test_table的表,分区名称为dt,分区值为value为例。
  • 已开通并授权访问OSS-HDFS服务。具体步骤,请参见非EMR集群接入OSS-HDFS服务快速入门。

背景信息

MoveTo命令可以在拷贝底层数据结束后,自动更新元数据,使表和分区的数据完整地迁移到新路径;可以通过条件筛选,一次拷贝大量分区。在数据迁移过程中,还使用了多种措施保护数据的完整性,确保数据安全。

操作步骤

重要 集群上每次仅允许运行一个MoveTo进程。如果集群上有正在运行的MoveTo进程,启动新的MoveTo进程时会因为获取不到配置锁而退出,并告知正在运行的MoveTo进程。此时,您可以终止掉正在运行的MoveTo进程,启动新的MoveTo进程,或者等待正在运行的MoveTo进程结束。

  1. 通过SSH方式登录集群,详情请参见登录集群。
  2. 执行以下命令,获取帮助信息。
    sudo jindo table -help moveTo

    帮助信息如下所示。

          The table to move.
          The destination base directory which is always at the
                              same level of a 'table location', where the moved
                              partitions or un-partitioned data would located in.
    /-fullTable  A filter condition to determine which partitions should
                              be moved, supporting common operators (like '>') and
                              built-in UDFs (like to_date) (UDFs not supported
                              yet...), while -fullTable means that all partitions (or
                              a whole un-partitioned table) should be moved. One but
                              only one option must be specified among -c
                              "" and -fullTable.
               Optional, saying that table/partitions should be moved
                              only when they are created (not updated or modified)
                              more than some days before from now.
               The maximum concurrency when copying partitions, 1 by
                              default.
        Storage policy for OSS destination, which can be Standard
                              (by default), IA, Archive, or ColdArchive. Not applicable for destinations other
                              than OSS. NOTE: if you are willing to use ColdArchive storage policy, please
                              make sure that Cold Archive has been enabled for your OSS bucket.
    
    -o/-overWrite           Overwriting the final paths where the data would be moved.
                              For partitioned tables this overwrites partitions locations
                              which are subdirectories of ; for
                              un-partitioned table this overwrites the 
                              itself.
    -r/-removeSource        Let the source data be removed when the corresponding
                              table/partition is successfully moved to the new destination.
                              Otherwise (by default), the source data would be left as it
                              was.
    -skipTrash              Applicable only when [-r/-removeSource] is enabled. If
                              present, source data would be immediately deleted from the
                              file system, bypassing the trash.
    -e/-explain             If present, the command would not really move data, but only
                              prints the table/partitions that would be moved for given
                              conditions.
             A directory to locate log files, '/tmp//' by
                              default.
    • 命令格式
      sudo jindo table -moveTo \
        -t  \
        -d  \
        [-c "" | -fullTable] \
        [-b/-before ] \
        [-p/-parallel ] \
        [-s/-storagePolicy ] \
        [-o/-overWrite] \
        [-r/-removeSource] \
        [-skipTrash] \
        [-e/-explain] \
        [-l/-logDir ]
    • 命令说明
      参数 必选 描述
      -t 移动的表名称,格式为数据库名.表名

      数据库和表名之前以半角句号(.)分隔。表可以是分区表或非分区表。

      -d 待移动的目标位置。无论是移动分区还是移动非分区表的整表,该位置都对应 “表” 一级的位置。如果移动的是分区,则分区的完整路径是该路径+分区名。例如/p1=v1/p2=v2/
      -c “” | -fullTable 两者必须指定其中一个。即您可以指定-c "",或者指定-fullTable

      • 指定-fullTable时,则为移动整表,既可以是非分区表也可以是分区表。
      • 指定-c ""时,则提供了一个过滤条件,用来选择希望移动的分区,支持常见运算符,例如大于号(>)。

        例如,数据类型为String的分区ds,希望分区名大于 ‘d’,则代码为-c " ds > 'd' "

      -b/before 仅创建时间距离当前时间超过一定天数的表或者分区才会被移动。
      -p/-parallel 迁移操作的并行度。
      -s/-storagePolicy OSS-HDFS服务不支持该选项。
      -o/-overWrite 是否强制覆盖目标写入路径。如果是分区表,则只会清空待移动分区的分区路径,不会清空整个表路径。
      -r/-removeSource 移动完成,元数据也同步更新后,是否清理源路径。如果是分区表,则只会清理成功移动的分区的源路径。
      -skipTrash 清理源路径时是否跳过Trash。说明 该选项需与-r/-removeSource选项同时使用。
      -e/-explain 如果出现该选项,则为解释(explain )模式,只会显示待移动的分区列表,而不会真正移动数据。
      -l/-logDir 指定Log文件目录。

      默认值:/tmp//

  3. 将分区数据迁移至OSS-HDFS服务。
    1. 查看待迁移的分区是否符合预期。结合-e 选项仅列举待迁移的分区,但不会真正执行迁移任务。
      sudo jindotable -moveTo -t tdb.test_table -d oss://examplebucket.cn-hangzhou.oss-dls.aliyuncs.com/data/tdb.test_table -c " dt > 'v' " -e

      返回结果如下:

      Found 1 partitions to move:
            dt=value-2
      MoveTo finished for table tdb.test_table to destination oss://examplebucket.cn-hangzhou.oss-dls.aliyuncs.com/data/tdb.test_table with condition " dt > 'v' " (explain only).
    2. 将分区迁移至OSS-HDFS服务。
      sudo jindotable -moveTo -t tdb.test_table -d oss://examplebucket.cn-hangzhou.oss-dls.aliyuncs.com/data/tdb.test_table  -c " dt > 'v' " 

      返回结果如下:

      Found 1 partitions in total, and all are successfully moved.
      Successfully moved partitions:
          dt=value-2
      No failed partition.
      MoveTo finished for table tdb.test_table to destination oss://examplebucket.cn-hangzhou.oss-dls.aliyuncs.com/data/tdb.test_table with condition " dt > 'v' ".
    3. 通过查看Location属性,验证分区是否成功迁移。
      sudo hive> desc formatted test_table partition (dt='value-2');

      返回结果如下:

      OK
      # col_name              data_type               comment
      id                      int
      content                 string
      
      # Partition Information
      # col_name              data_type               comment
      dt                      string
      
      # Detailed Partition Information
      Partition Value:        [value-2]
      Database:               tdb
      Table:                  test_table
      CreateTime:             UNKNOWN
      LastAccessTime:         UNKNOWN
      Location:               oss://examplebucket.cn-hangzhou.oss-dls.aliyuncs.com/data/tdb.test_table/dt=value-2
    4. 可选:将分区从OSS-HDFS迁移至HDFS。
      sudo jindotable -moveTo -t tdb.test_table -d hdfs:///user/hive/warehouse/tdb.db/test_table  -c " dt > 'v' "

      返回结果如下:

      No successfully moved partition.
      Failed partitions:
          dt=value-2    New location is not empty but -overWrite is not enabled.
      MoveTo finished for table tdb.test_table to destination hdfs:///user/hive/warehouse/tdb.db/test_table with condition -c " dt > 'v' ".

      返回结果提示No successfully moved partition.,原因是HDFS目标目录非空。如果确认目标目录可以丢弃,您可以使用-overWrite选项强制覆盖目标目录,确保将分区从OSS-HDFS迁移至HDFS。

      sudo jindotable -moveTo -t tdb.test_table -d hdfs:///user/hive/warehouse/tdb.db/test_table  -c " dt > 'v' "

      迁移成功后,返回结果如下:

      Found 1 partitions in total, and all are successfully moved.
      Successfully moved partitions:
          dt=value-2
      No failed partition.
      MoveTo finished for table tdb.test_table to destination hdfs:///user/hive/warehouse/tdb.db/test_table with condition " dt > 'v' ", overwriting new locations.

异常处理

如果迁移表或分区时迁移失败并提示Conflicts found,请通过以下方法处理该问题。

  • 确保同一时间不存在其他命令向相同的目标路径迁移数据,例如DistCp、JindoDistCp等分布式拷贝命令。
  • 删除目标目录。对于非分区表,删除表一级目录。对于分区表,删除存在冲突的分区级目录。
  • 请勿删除源目录。

内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家

阿里云企业补贴进行中: 马上申请

腾讯云限时活动1折起,即将结束: 马上收藏

同尘科技为腾讯云授权服务中心。

购买腾讯云产品享受折上折,更有现金返利:同意关联,立享优惠

转转请注明出处:https://www.yunxiaoer.com/159533.html

(0)
上一篇 2023年12月10日
下一篇 2023年12月10日
详情页2

相关推荐

  • 阿里云大数据开发治理平台 DataWorks批量操作-云淘科技

    DataWorks支持对节点、资源、函数进行批量修改责任人等批量编辑操作,并支持批量提交并发布,将变更操作发布至生产环境生效。本文为您介绍批量操作的界面入口及详细指导。 操作步骤 登录DataWorks控制台,进入数据开发页面后,在顶部的快捷操作按钮中单击批量操作按钮,即可打开批量操作页面。 批量修改。 在批量操作页面中,您可以在顶部页签中选择对节点、资源或…

    2023年12月10日
  • 阿里云日志服务SLS导入云监控数据-云淘科技

    您可以通过数据导入方式将阿里云云监控数据导入到日志服务,实现时序数据的查询分析、加工等操作。 前提条件 已创建Project和Logstore。具体操作,请参见创建Project和创建Logstore。背景信息日志服务支持将云监控数据导入到Logstore(Log格式)或MetricStore(Metric格式)中。云监控数据以统计类的计量数据为主,推荐您导…

    阿里云日志服务SLS 2023年12月10日
  • 阿里云日志服务SLS数据加工延迟问题排查与处理-云淘科技

    本视频介绍数据加工延迟问题的排查与处理方法。 内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家阿里云企业补贴进行中: 马上申请腾讯云限时活动1折起,即将结束: 马上收藏同尘科技为腾讯云授权服务中心。 购买腾讯云产品享受折上折,更有现金返利:同意关联,立享优惠

    阿里云日志服务SLS 2023年12月10日
  • 阿里云大数据开发治理平台 DataWorks功能发布记录 2022年之前-云淘科技

    本文为您介绍2022年之前DataWorks产品功能和对应的文档动态。 MaxCompute的重要功能发布详情请参见产品重大更新。 2021-12 功能名称 功能描述 发布时间 发布地域 相关文档 数据质量支持选择规则模板来批量配置数据质量规则。 DataWorks数据质量支持选择规则模板来批量配置数据质量规则,简化配置难度: 支持选择表级规则模板,批量给多…

  • 信息流广告,信息流部分建议宽度830px,只针对默认列表样式,顺序随机
  • 阿里云RDS数据库自动备份MariaDB数据-云淘科技

    RDS MariaDB暂不支持手动备份数据,您可以通过设置备份策略来实现自动备份。 前提条件 若您初次使用RDS备份服务,您需要使用阿里云主账号完成DBS服务关联角色(AliyunServiceRoleForDBS)授权。具体操作,请参见如何授权DBS服务关联角色。 注意事项 实例备份文件占用备份空间,空间使用量超出免费的额度将会产生额外的费用,请合理设计备…

    阿里云数据库 2023年12月9日

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
本站为广大会员提供阿里云、腾讯云、华为云、百度云等一线大厂的购买,续费优惠,保证底价,买贵退差。