sqoop架构

by Jayvardhan Reddy

通过杰伊瓦尔丹·雷迪(Jayvardhan Reddy)

SQOOP架构的深入介绍 (An in-depth introduction to SQOOP architecture)

Apache Sqoop is a data ingestion tool designed for efficiently transferring bulk data between Apache Hadoop and structured data-stores such as relational databases, and vice-versa.

Apache Sqoop是一种数据提取工具,旨在在Apache Hadoop和结构化数据存储(例如关系数据库)之间有效地传输批量数据,反之亦然。

As part of this blog, I will be explaining how the architecture works on executing a Sqoop command. I’ll cover details such as the jar generation via Codegen, execution of MapReduce job, and the various stages involved in running a Sqoop import/export command.

作为该博客的一部分,我将解释该架构如何执行Sqoop命令。 我将介绍诸如通过Codegen生成jar,执行MapReduce作业以及运行Sqoop导入/导出命令所涉及的各个阶段等细节。

码元 (Codegen)

Understanding Codegen is essential, as internally this converts our Sqoop job into a jar which consists of several Java classes such as POJO, ORM, and a class that implements DBWritable, extending SqoopRecord to read and write the data from relational databases to Hadoop & vice-versa.

理解Codegen是必不可少的,因为在内部,这会将我们的Sqoop作业转换为一个jar,该jar由几个Java类(例如POJO,ORM)和一个实现DBWritable的类组成,将SqoopRecord扩展为从关系数据库到Hadoop读写数据,反之亦然。反之亦然。

You can create a Codegen explicitly as shown below to check the classes present as part of the jar.

您可以如下所示显式创建Codegen,以检查作为jar一部分存在的类。

sqoop codegen \   -- connect jdbc:mysql://ms.jayReddy.com:3306/retail_db \   -- username retail_user \   -- password ******* \   -- table products

The output jar will be written in your local file system. You will get a Jar file, Java file and java files which are compiled into .class files:

输出jar将被写入您的本地文件系统中。 您将获得一个Jar文件,Java文件和编译为.class文件的Java文件:

Let us see a snippet of the code that will be generated.

让我们看一看将要生成的代码片段。

ORM class for table ‘products’ // Object-relational modal generated for mapping:

表“产品”的ORM类//为映射生成的对象关系模态:

Setter & Getter methods to get values:

用Setter和Getter方法获取值:

Internally it uses JDBC prepared statements to write to Hadoop and ResultSet to read data from Hadoop.

在内部,它使用JDBC准备的语句写入Hadoop,并使用ResultSet从Hadoop读取数据。

Sqoop导入 (Sqoop Import)

It is used to import data from traditional relational databases into Hadoop.

它用于将数据从传统的关系数据库导入Hadoop。

Let’s see a sample snippet for the same.

让我们看一下相同的示例代码。

sqoop import \   -- connect jdbc:mysql://ms.jayReddy.com:3306/retail_db \   -- username retail_user \   -- password ******* \   -- table products \   -- warehouse-dir /user/jvanchir/sqoop_prac/import_table_dir \   -- delete-target-dir

The following steps take place internally during the execution of sqoop.

在执行sqoop时,以下步骤在内部进行。

Step 1: Read data from MySQL in streaming fashion. It does various operations before writing the data into HDFS.

步骤1 :以流方式从MySQL读取数据。 在将数据写入HDFS之前,它会执行各种操作。

As part of this process, it will first generate code (typical Map reduce code) which is nothing but Java code. Using this Java code it will try to import.

作为此过程的一部分,它将首先生成仅Java代码的代码(典型的Map reduce代码)。 使用此Java代码,它将尝试导入。

  • Generate the code. (Hadoop MR)生成代码。 (Hadoop MR)
  • Compile the code and generate the Jar file.编译代码并生成Jar文件。
  • Submit the Jar file and perform the import operations提交Jar文件并执行导入操作

During the import, it has to make certain decisions as to how to divide the data into multiple threads so that Sqoop import can be scaled.

在导入期间,它必须对如何将数据划分为多个线程做出某些决策,以便可以扩展Sqoop导入。

Step 2: Understand the structure of the data and perform CodeGen

步骤2 :了解数据的结构并执行CodeGen

Using the above SQL statement, it will fetch one record along with the column names. Using this information, it will extract the metadata information of the columns, datatype etc.

使用上面SQL语句,它将获取一条记录以及列名。 使用此信息,它将提取列的元数据信息,数据类型等。

Step 3: Create the java file, compile it and generate a jar file

步骤3 :创建Java文件,对其进行编译并生成一个jar文件

As part of code generation, it needs to understand the structure of the data and it has to apply that object on the incoming data internally to make sure the data is correctly copied onto the target database. Each unique table has one Java file talking about the structure of data.

作为代码生成的一部分,它需要了解数据的结构,并且必须在内部将该对象应用于传入数据,以确保将数据正确复制到目标数据库中。 每个唯一表都有一个讨论数据结构的Java文件。

This jar file will be injected into Sqoop binaries to apply the structure to incoming data.

该jar文件将被注入Sqoop二进制文件中,以将结构应用于传入数据。

Step 4: Delete the target directory if it already exists.

步骤4 :删除目标目录(如果已存在)。

Step 5: Import the data

步骤5 :导入数据

Here, it connects to a resource manager, gets the resource, and starts the application master.

在这里,它连接到资源管理器,获取资源,然后启动应用程序主机。

To perform equal distribution of data among the map tasks, it internally executes a boundary query based on the primary key by default to find the minimum and maximum count of records in the table. Based on the max count, it will divide by the number of mappers and split it amongst each mapper.

为了在地图任务之间执行均等的数据分配,默认情况下,它会在内部基于主键执行边界查询,以查找表中记录的最小和最大计数。 根据最大计数,它将除以映射器的数量并将其分配给每个映射器。

It uses 4 mappers by default:

默认情况下,它使用4个映射器:

It executes these jobs on different executors as shown below:

它在不同的执行器上执行这些作业,如下所示:

The default number of mappers can be changed by setting the following parameter:

可以通过设置以下参数来更改默认的映射器数:

So in our case, it uses 4 threads. Each thread processes mutually exclusive subsets, that is each thread processes different data from the others.

因此,在我们的例子中,它使用4个线程。 每个线程处理互斥的子集,即每个线程处理彼此不同的数据。

To see the different values, check out the below:

要查看不同的值,请查看以下内容:

Operations that are being performed under each executor nodes:

在每个执行程序节点下正在执行的操作:

In case you perform a Sqooop hive import, one extra step as part of the execution takes place.

如果您执行Sqooop配置单元导入,则执行过程会多执行一个步骤。

Step 6: Copy data to hive table

步骤6 :将数据复制到配置单元表

Sqoop导出 (Sqoop Export)

This is used to export data from Hadoop into traditional relational databases.

这用于将数据从Hadoop导出到传统的关系数据库中。

Let’s see a sample snippet for the same:

让我们看一下相同的示例代码:

sqoop export \  -- connect jdbc:mysql://ms.jayReddy.com:3306/retail_export \  -- username retail_user \  -- password ******* \  -- table product_sqoop_exp \  -- export-dir /user/jvanchir/sqoop_prac/import_table_dir/products

On executing the above command, the execution steps (1–4) similar to Sqoop import take place, but the source data is read from the file system (which is nothing but HDFS). Here it will use boundaries upon block size to divide the data and it is internally taken care by Sqoop.

在执行上述命令时,将执行类似于Sqoop导入的执行步骤(1-4),但是从文件系统读取源数据(除了HDFS外什么也没有)。 在这里,它将使用块大小上的边界来划分数据,并且Sqoop会在内部对其进行处理。

The processing splits are done as shown below:

处理拆分如下所示:

After connecting to the respective database to which the records are to be exported, it will issue a JDBC insert command to read data from HDFS and store it into the database as shown below.

连接到要将记录导出到的相应数据库后,它将发出JDBC插入命令以从HDFS读取数据并将其存储到数据库中,如下所示。

Now that we have seen how Sqoop works internally, you can determine the flow of execution from jar generation to execution of a MapReduce task on the submission of a Sqoop job.

现在我们已经了解了Sqoop的内部工作原理,您可以确定从jar生成到提交Sqoop作业时执行MapReduce任务的执行流程。

Note: The commands that were executed related to this post are added as part of my GIT account.

注意与该帖子相关的已执行命令被添加为我的GIT帐户的一部分。

Similarly, you can also read more here:

同样,您也可以在此处内容:

  • Hive Architecture in Depth with code.

    具有代码 深度的Hive架构 。

  • HDFS Architecture in Depth with code.

    具有代码 深度的HDFS体系结构 。

If you would like too, you can connect with me on LinkedIn - Jayvardhan Reddy.

如果您愿意,也可以通过LinkedIn- Jayvardhan Reddy与我联系 。

If you enjoyed reading this article, you can click the clap and let others know about it. If you would like me to add anything else, please feel free to leave a response ?

如果您喜欢阅读本文,则可以单击拍手并告知其他人。 如果您希望我添加其他任何内容,请随时回复。

翻译自: https://www.freecodecamp.org/news/an-in-depth-introduction-to-sqoop-architecture-ad4ae0532583/

sqoop架构

sqoop架构_SQOOP架构的深入介绍相关推荐

  1. 企业架构 - ADM方法概要介绍

    在<企业架构 - 开篇:TOGAF介绍>中介绍了ADM是TOGAF的核心,本篇概要的介绍一下ADM方法的每个阶段的工作内容. 预备阶段 确定实现过程涉众,并且让它们面对企业架构工作的内容. ...

  2. JDO 的架构作一个简单的介绍

    JDO快速入门 Java数据对象(Java Data Objects,JDO)是一个应用程序接口(API),它是Java程序员能够间接地访问数据库,也就是说,不需使用直接的结构化查询语言(SQL)语句 ...

  3. 爬虫的基础架构及常用的工具介绍

    爬虫的基础架构及常用的工具 写在前面 爬虫和页面解析都是实操性非常强的技能,需要分析待爬取的网站和信息,过程中不乏需要很多尝试和调整. 爬虫的基础架构 基础架构方面主要分为 3 个部分,分别是 URL ...

  4. android系统架构图及各层介绍

    此技术文档主要是从基础了解Android系统架构,便于对以后开发形成一些基本应用架构. Android的系统架构采用了分层架构的思想,如图1所示.从上层到底层共包括四层,分别是应用程序程序层.应用框架 ...

  5. 我要带徒弟学JAVA架构 ( 写架构,非用架构 )

    我要带徒弟学JAVA架构 (写架构,非用架构)     很多人做java开发2,3年后,都会感觉自己遇到瓶颈.什么都会又什么都不会,如何改变困境,为什么很多人写了7,8年还是一个码农,工作中太多被动是 ...

  6. 什么是架构?架构的本质和作用!

    提起企业架构很多朋友都不明白其与数字化转型之间的关系,其实可以这样了解:将数字化转型的本质当成技术对业务的重塑,那么为了达到重塑的目标,就需要企业具备数字化的核心力量.而企业架构就相当于技术实现与业务 ...

  7. 微信架构 支付架构(下)

    微信架构 & 支付架构(下) 管理网络请求 首先看看原来 iOS 处理支付网络请求的缺陷: 原来支付的请求,都是通过一个单例网络中心去发起请求,然后收到回包后,通过抛通知,或者调用闭包的方式回 ...

  8. 微信架构 支付架构(上)

    微信架构 & 支付架构(上) 一. 微信和支付宝对比 这两者现在已经占领了移动支付的90%市场,支付形式也都大抵相同,只是在实现细节上略微不同.这里之所以要专门对比,是因为有些接口的不同在后边 ...

  9. 旧文重发:做人、做事,做架构师——架构师能力模型解析

    这篇文章发表于<程序员>2008.04期.其中有关模型图参见: http://blog.csdn.net/aimingoo/archive/2007/06/26/1667508.aspx ...

最新文章

  1. 终于有人把 java代理 讲清楚了,万字详解!
  2. 中国工程师最喜欢的10大WiFi物联网芯片
  3. React开发(249):react项目理解 ant design form加个扩展样式
  4. 加速财务自由的7种理财方法
  5. 云计算学习笔记002---云计算的理解及介绍,google云计算平台实现原理
  6. android+获取图库图片+4.4,Android 从 Android 本地图库选择多个图片
  7. oracle改表结构非空字段类型,oracle 表结构的非完全复制
  8. 互联网创业团队需要什么样的人
  9. 题解【51nod 1290 Counting Diff Pairs】
  10. R语言数据分析笔记——方差分析(单因素方差分析、双因素方差分析、多因素方差分析)在Excel、SPSS、R语言中的操作)
  11. 某条微博评论数据爬取
  12. 软件质量需要静态代码分析和动态测试
  13. java 字符串转pdf_Java pdf转String 并修正格式
  14. 博士申请 | 香港城市大学赵翔宇老师招收人工智能全奖PhD/联培PhD/RA
  15. 领袖的七个非常重要的根性-余世维
  16. Android:使用百度地图SDK定位当前具体位置(类似QQ发表说说的选择地点功能)
  17. iPhone连接电脑后iTunes不识别的解决办法
  18. layui提交成功之后刷新当前页、关闭当前页、刷新父页、重载父页数据表格
  19. 可以直接考全国计算机四级吗,国家计算机四级可以直接考吗
  20. 共享内存shmget的郁闷

热门文章

  1. 【数据库】兴唐第二十七节课之jdbc的使用
  2. IDEA配置GitHub报错GitHub Invalid authentication data.404 Not Found-Not Found
  3. 数据结构之【队列】的基本操作C语言实现
  4. Vue父组件网络请求回数据后再给子组件传值demo示例
  5. 05-自己创建mapmodel自定义迁移方式
  6. flask的客户端服务端
  7. #读书笔记 Android-Activity启动模式
  8. Extjs 基础篇—— Function基础
  9. 2017SDN市场一片繁荣,全球企业纷纷“亮剑“
  10. [Python] 中文路径和中文文本文件乱码问题