APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will...

23
APACHE SQOOP Presentation by: Shadaab Ghani Subhadutta Mahapatra

Transcript of APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will...

Page 1: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

APACHE SQOOP

Presentation by:

Shadaab Ghani

Subhadutta Mahapatra

Page 2: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Contents:

• What is sqoop?

• Usage of sqoop

• Scoop architecture(1 &2)

• Features of sqoop

• Sqoop commands

• connectors

• Limitations

Page 3: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

What is APACHE SQOOP ?

• Sqoop is a tool designed to transfer data between Hadoop and relational databases or mainframes.

• Sqoop can be used to import data from a relational database management system (RDBMS) such as MySQL or Oracle or a mainframe into the Hadoop Distributed File System (HDFS), transform the data in Hadoop MapReduce, and then export the data back into an RDBMS.

• Sqoop automates most of this process, relying on the database to describe the schema for the data to be imported. Sqoop uses MapReduce to import and export the data, which provides parallel operation as well as fault tolerance.

• That’s Scoop got its name from SQL to Hadoop and Hadoop to SQL

Page 4: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

• Big data developer’s works start once the data are in Hadoop system like in

HDFS, Hive or Hbase. They do their magical stuff to find all the golden

information hidden on such a huge amount of data.

• Before Sqoop came, developers used to write to import and export databetween

Hadoop and RDBMS and a tool was needed to the same.

• Again, Sqoop uses the MapReduce mechanism for its operations like import and

export work and work on a parallel mechanism as well as fault tolerance.

• In Sqoop, developers just need to mention the source, destination and the rest of

the work will be done by the Sqoop tool.

• Sqoop came and filled the gap between the transfer between relational

databases and Hadoop system.

Few more points…

Page 5: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Scope of Sqoop:

Sqoop is basically used by :

• System and application programmers

• System administrators

• Database administrators

• Data analysts

• Data engineers

Page 6: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Usage of Sqoop

• With Sqoop, one can import data from a relational database system or a mainframe into HDFS. The input to the import process is either database table or mainframe datasets.

• For databases, Sqoop will read the table row-by-row into HDFS.

• For mainframe datasets, Sqoop will read records from each mainframe dataset into HDFS. The output of this import process is a set of files containing a copy of the imported table or datasets.

Page 7: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

• Sqoop includes some other commands which allow you to inspect the database you are working with. For example, you can list the available database schemas (with the sqoop-list-databases tool) and tables within a schema (with the sqoop-list-tables tool). Sqoop also includes a primitive SQL execution shell (the sqoop-eval tool)

• Sqoop is a collection of related tools. To use Sqoop, you specify the tool you want to use and the arguments that control the tool.

• If Sqoop is compiled from its own source, you can run Sqoop without a formal installation process by running the bin/sqoop program.

# Users of a packaged deployment of Sqoop (such as an RPM shipped with Apache Bigtop) will see this program installed as /usr/bin/sqoop.

$ sqoop tool-name [tool-arguments]

Page 8: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Sqoop Architecture

Here is one source which is RDBMS like MySQL and other is a destination like Hbase or HDFS etc. and Sqoop performs the operation to perform import and export.

RDBMS(MYSQL,ORACLE,)

HADOOP FILE SYSTEM

(HDFS, Hbase ,Hive)

IMPORT

EXPORT

SQOOP TOOL

Page 9: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Sqoop 1 architecture

USER

HDFS/HBase

MAP TASK

DATA WAREHOUSE

DOCUMENT BASED

SYSTEM

RELATIONAL DATABASE

HADOOP

SQOOP

CO

MM

AN

D

When Sqoop 1 starts functioning, only mapper job will run and reducer is not required. Here is a detailed view of Sqoop architecture with mapper-

1. Sqoop 1 provides command line interface to the end users and can also be accessed using Java API.

2. Here only Map phase will run and reduce is not required because the complete import and export process doesn’t require any aggregation and so there is no need of reducers in Sqoop 1.

Page 10: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Challenges in Sqoop 1

• Sometimes Command Line arguments can lead to errors in connector matching as the user has to decide which one to choose.

• Due to tight coupling between data transfer and serialization format, some connectors may support certain data format while others may not

• Security issues are there

• Connectors are forced to be of JDBC model.

Page 11: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Sqoop 2 architecture

USER

REST

UI

Job Manager

SQOOP SERVER

Connector Manager

Connector

Metadata

RED

UC

E TASK

HDFS/HBase/Hive

MAP TASK

MetadataRepository

DATA WAREHOUSE

DOCUMENT BASED

SYSTEM

RELATIONAL DATABASE

HADOOP

CLI

Browser

Scoop Client

Page 12: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Key points of Sqoop 2

• Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by having a web-application run Sqoop, which allows Sqoop to be installed once and used from anywhere.

• Having a REST API for operation and management helps Sqoop 2 integrate better with external systems such as Oozie.

• Introducing a reduce phase allows connectors to be focused only on connectivity and ensures that Sqoop functionality is uniformly available for all connectors. This facilitates ease of development of connectors.

Page 13: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Sqoop 1 vs Sqoop 2

Sl No. Sqoop1 Sqoop 2

1. Client-only Architecture Client/Server Architecture

2. Requires client side installation and configuration Requires server side installation and configuration

3. Client access to Hive, Hbase making it insecure Server Access to Hive/Hbase making it secure

4. User is tasked with management of connectors and drivers for various operations, is JDBC based

Connectors and drivers are managed centrally in one place and can be non JDBC based

Page 14: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

1.Full Load:Apache Sqoop can load the whole table by a single command. You can also load all the tables from a database using a single command.2.Incremental Load: Apache Sqoop also provides the facility of incremental load where you can load arts of table whenever it is updated. Sqoop import supports two types

of incremental imports: 1. Append 2. Lastmodified.

3.Parallel import/ export: Sqoop uses YARN framework to import and export the data, which provides fault tolerance on top of parallelism.4.Import results of SQL query: You can also import the result returned from an SQL query in HDFS.5.Compression:You can compress your data by using deflate (gzip) algorithm with -compress argument, or by specifying –compression-codec argument. You can also load compressed table in Apache Hive.6.Connectors for all major RDBMS Databases: Apache Sqoop provides connectors formultiple RDBMS databases, covering almost the entire circumference.7.LoaddatadirectlyintoHIVE/HBase:You can load datadirectly into Apache Hive for analysis and also dump your data in HBase, which is a NoSQL database.

Features of sqoop

Page 15: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Sqoop commands

$ sqoop help

usage: sqoop COMMAND [ARGS]

Available commands:

codegen Generate code to interact with database records

create-hive-table Import a table definition into Hive

eval Evaluate a SQL statement and display the results

export Export an HDFS directory to a database table

help List available commands

import Import a table from a database to HDFS

import-all-tables Import tables from a database to HDFS

import-mainframe Import mainframe datasets to HDFS

list-databases List available databases on a server

list-tables List available tables in a database

version Display version information

Page 16: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Sqoop Import• The import tool imports an individual table from an RDBMS to HDFS. Each row from a table is represented as a

separate record in HDFS. Records can be stored as text files (one record per line), or in binary representation as Avro or SequenceFiles.

$ sqoop import (generic-args) (import-args)

$ sqoop-import (generic-args) (import-args)

Connecting to a database server

$ sqoop import --connect jdbc:mysql://database.example.com/employees \

--username venkatesh --password-file ${user.home}/.password

• Sqoop can also import the result set of an arbitrary SQL query. Instead of using the --table, --columns and --where arguments, one can specify a SQL statement with the --query argument.When importing a free-form query, one must specify a destination directory with --target-dir.

$ sqoop import \

--query 'SELECT a.*, b.* FROM a JOIN b on (a.id == b.id) WHERE $CONDITIONS' \

--split-by a.id --target-dir /user/foo/joinresults

Page 17: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

• Sqoop imports data in parallel from most database sources. You can specify the number of map tasks (parallel processes) to use to perform the import by using the -m or --num-mappers argument. Each of these arguments takes an integer value which corresponds to the degree of parallelism to employ. By default, four tasks are used. Some databases may see improved performance by increasing this value to 8 or 16.

• By default, the import process will use JDBC which provides a reasonable cross-vendor import channel. Some databases can perform imports in a more high-performance fashion by using database-specific data movement tools. For example, MySQL provides the mysqldump tool which can export data from MySQL to other systems very quickly. By supplying the --direct argument, you are specifying that Sqoop should attempt the direct import channel. This channel may be higher performance than using JDBC.

$ sqoop import --connnect <connect-str> --table foo --warehouse-dir /shared \

• Sqoop also provides features like incremental imports where only new data is imported.

• In Sqoop data can be imported in two file formats: Delimited text and SequenceFiles. Delimited text is the default import format. Delimited text is appropriate for most non-binary data types. It also readily supports further manipulation by other tools, such as Hive. SequenceFiles are a binary format that store individual records in custom record-specific data types. These data types are manifested as Java classes. Sqoop will automatically generate these data types for us.

Page 18: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Sqoop export

• The export tool exports a set of files from HDFS back to an RDBMS. The target table must already exist in the database. The input files are read and parsed into a set of records according to the user-specified delimiters.

• The default operation is to transform these into a set of INSERT statements that inject the records into the database. In "update mode," Sqoop will generate UPDATE statements that replace existing records in the database, and in "call mode" Sqoop will make a stored procedure call for each record.

$ sqoop export (generic-args) (export-args)

• By default, all columns within a table are selected for export. You can select a subset of columns and control their ordering by using the --columns argument. This should include a comma-delimited list of columns to export.

Page 19: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

• By default, sqoop-export appends new rows to a table; each input record is transformed into an INSERT statement that adds a row to the target database table. If specified the --update-key argument, Sqoop will instead modify an existing dataset in the database. Each input record is treated as an UPDATE statement that modifies an existing row. The row a statement modifies is determined by the column name(s) specified with --update-key.

• Exports are performed by multiple writers in parallel. Each writer uses a separate connection to the database; these have separate transactions from one another. Sqoop uses the multi-row INSERT syntax to insert up to 100 records per statement. Every 100 statements, the current transaction within a writer task is committed, causing a commit every 10,000 rows. This ensures that transaction buffers do not grow without bound, and cause out-of-memory conditions. Therefore, an export is not an atomic process. Partial results from the export will become visible before the export is complete.

• Since Sqoop breaks down export process into multiple transactions, it is possible that a failed export job may result in partial data being committed to the database. This can further lead to subsequent jobs failing due to insert collisions in some cases, or lead to duplicated data in others. You can overcome this problem by specifying a staging table via the --staging-table option which acts as an auxiliary table that is used to stage exported data. The staged data is finally moved to the destination table in a single transaction.

Page 20: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Other sqoop functions• Sqoop Validation - Validate the data copied, either import or export by comparing the row counts

from the source and the target post copy.

• Sqoop Job - The job tool allows you to create and work with saved jobs. Saved jobs remember the parameters used to specify a job, so they can be re-executed by invoking the job by its handle.If a saved job is configured to perform an incremental import, state regarding the most recently imported rows is updated in the saved job to allow the job to continually import only the newest rows.

• Sqoop metastore - The metastore tool configures Sqoop to host a shared metadata repository. Multiple users and/or remote users can define and execute saved jobs (created with sqoop job) defined in this metastore. Clients must be configured to connect to the metastore in sqoop-site.xml or with the --meta-connect argument.

• Sqoop merge - The merge tool allows you to combine two datasets where entries in one dataset should overwrite entries of an older dataset. For example, an incremental import run in last-modified mode will generate multiple datasets in HDFS where successively newer data appears in each dataset. The merge tool will "flatten" two datasets into one, taking the newest available records for each primary key.

Page 21: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

• Scoop create-hive-table - The create-hive-table tool populates a Hive metastorewith a definition for a table based on a database table previously imported to HDFS, or one planned to be imported. This effectively performs the "--hive-import" step of sqoop-import without running the preceeding import. If data was already loaded to HDFS, you can use this tool to finish the pipeline of importing the data to Hive. You can also create Hive tables with this tool; data then can be imported and populated into the target after a preprocessing step run by the user.

• Scoop help - List tools available in Sqoop and explain their usage.

• Scoop list-tables – list of all tables in the database

Page 22: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Connectivity

• Sqoop uses JDBC to connect to databases and adheres to published standards as much as possible. For databases which do not support standards-compliant SQL, Sqoop uses alternate codepaths to provide functionality. In general, Sqoop is believed to be compatible with a large number of databases, but it is tested with only a few.

Page 23: APACHE SQOOPvvtesh.co.in/teaching/bigdata-2020/slides/studentppt/sqoop.pdf · •Sqoop 2 will enable users to use Sqoop effectively with a minimal understanding of its details by

Limitations

• 1.Sqoop cannot be paused and resumed. It is an atomic step. If it is failed we need to clear things up and start again.

• 2.Sqoop Export performance also depends upon the hardware configuration (Memory, Hard disk) of RDBMS server.

• 3.Sqoop is slow because it still uses Map Reduce in backend processing.

• 4.Failures need special handling in case of partial import or export.

• 5.For few databases Sqoop provides bulk connector which has faster performance. It uses a JDBC connection to connect with RDBMS based on data stores, and this can be inefficient and less performance.