Skip to main content

Bulk data between relational databases
and Hadoop, in both directions.

Sqoop is a command-line tool that moves tables from relational databases into HDFS, Hive, and HBase and returns the results to the database, in parallel and with fault tolerance. Follow an import and an export, learn what each part of the command means, and see what Sqoop offers beyond the simple import.

Apache Sqoop is a command-line tool that transfers bulk data between Hadoop and relational databases.

The import brings tables into HDFS, and the export returns the processing results to the database.

From the database to Hadoop

Import

Each row of a database table becomes a record in HDFS. The destination can also be a Hive or HBase table.

From Hadoop to the database

Export

Files from HDFS go back to a table that already exists in the database, as new rows or, in update mode, as changes to existing rows.

In parallel

Each task, one part

Sqoop uses MapReduce to import and export, which provides parallel operation and fault tolerance: each map task handles a part of the data.

On this page

See an import happen​

Press Play or move forward step by step. Underlined names lead to the Glossary.

Sqoop and the databaseWho asks and where the data comes from
sqoop importTool and arguments
ConnectorTalks to the chosen database
Relational databaseSchema and rows
Hadoop clusterMap tasks of the job
Map taskReads one range of the table
Map taskReads another range
DestinationWhere the data arrives
HDFSMultiple files
HiveTable created by Sqoop
HBaseOne row per Put
Step 1 of 7

1 The command chooses the tool

Sqoop is a collection of related tools. The user specifies the tool, here the import, and the arguments that control it, such as the database connect string and the table to import.

  1. The command chooses the tool. Sqoop is a collection of related tools. The user specifies the tool, here the import, and the arguments that control it, such as the database connect string and the table to import.
  2. The connector talks to the database. Sqoop looks at the scheme of the connect string, for example jdbc:mysql://, to choose the logic specific to that database. For a database it does not know, it uses a generic path with standard SQL, as long as the JDBC driver is provided.
  3. The database describes the data. Sqoop automates most of the process and relies on the database to learn the schema of the data to import. The minimum and maximum values of the split column also come from the database.
  4. The range is divided among the map tasks. To import in parallel, Sqoop needs a criterion to divide the work. Without other instructions, it uses the primary key of the table as the split column, and each map task operates on a uniformly sized range of the total interval.
  5. Each task reads its part. Each map task runs a SELECT on the database limited to its range and reads the table row by row. A poorly distributed range leaves the tasks unequal, which is why the split column can be changed.
  6. The data arrives in parallel at the destination. The import runs in parallel, so the output is multiple files in HDFS, in delimited text, Avro or SequenceFiles. Along with the files, Sqoop generates a Java class that represents a row of the table.
  7. Or straight into Hive or HBase. With Hive associated with the cluster, Sqoop can create the table by generating and running a CREATE TABLE with the layout of the data. With an HBase table as the destination, each input row becomes a Put operation on a row of the table.
Figure 1 - An import: Sqoop queries the database and splits the work among map tasks, and each task reads its part and writes in parallel to HDFS, Hive or HBase.

See an export happen​

The way back: the files in HDFS become rows of a table that already exists in the database.

HDFSWhere the data comes from
FilesDelimited records
Hadoop clusterMap tasks of the job
Map taskWrites with its own connection
Map taskWrites with its own connection
Relational databaseWhere the data goes back to
Staging tableReceives the data before the destination
Destination tableAlready exists in the database
Step 1 of 5

1 The map tasks read the files

The export reads a set of delimited text files from HDFS in parallel and parses each one into records, according to the specified delimiters. The destination table must already exist in the database.

  1. The map tasks read the files. The export reads a set of delimited text files from HDFS in parallel and parses each one into records, according to the specified delimiters. The destination table must already exist in the database.
  2. The records become INSERT or UPDATE. The basic operation turns the records into INSERT statements that add rows. In update mode, the column specified in update-key identifies the row, and each record becomes an UPDATE. An UPDATE that changes no rows is not treated as an error.
  3. Each writer, one transaction. The writers write in parallel, each with its own connection and its own transaction. An export is therefore not atomic: partial results are visible before it ends.
  4. If a task fails. The failure of a map task makes the whole export job fail, and the result is undefined: what has already been committed remains in the database, and what has not is rolled back.
  5. The staging table protects the destination. With a staging table, the tasks write to it first, and the data is moved to the destination table in a single transaction. The staging table must be structurally identical to the destination table.
Figure 2 - An export: map tasks read the files from HDFS in parallel and write to the database, each with its own connection and its own transaction. With a staging table, the data moves to the destination in a single transaction.

Architecture​

Sqoop interprets the command; MapReduce runs the work; the database and the cluster exchange the data.

Sqoop architecture: the command triggers map tasks that move data between relational databases or mainframe and the Hadoop clusterThe user sends a command to Sqoop, which uses a connector for the database and triggers map tasks on the Hadoop cluster. The map tasks exchange data in both directions with relational databases, receive data from a mainframe and write to HDFS, Hive and HBase.CommandSqoopConnectorExternal sources and destinationsRelational databaseMainframeHadoop clusterMap tasksHDFSHiveHBase
Figure 3 - Sqoop architecture: the command reaches Sqoop, which launches map tasks on the Hadoop cluster. The tasks exchange data with relational databases, receive data from mainframes, and write to HDFS, Hive and HBase. Underlined terms lead to the Glossary.

What the figure shows:

  1. The command: the user provides the tool and the arguments and sends it to Sqoop.
  2. Sqoop is a command-line interface: it interprets the tool and the arguments and launches a MapReduce job on the Hadoop cluster.
  3. The connector is the database one, which Sqoop uses.
  4. The map tasks of the MapReduce job do the transfer work.
  5. The relational database exchanges data with the map tasks in both directions.
  6. The mainframe: the map tasks receive data from it. For this data there is a dedicated tool, which imports into HDFS the sequential datasets of a partitioned dataset on the mainframe.
  7. HDFS, Hive and HBase: the map tasks write to them.

Anatomy of a command​

Each command names a tool and the arguments that control it. The example is an import of a table from a MySQL database.

Click each part of the command.

Sqoop

The command-line program. Sqoop is a collection of related tools, and the usage has the form sqoop tool-name [tool-arguments].

sqoop — Sqoop
The command-line program. Sqoop is a collection of related tools, and the usage has the form sqoop tool-name [tool-arguments].
import — Tool
The tool that imports a table from a relational database into HDFS. Each row of the table becomes a record. The export tool does the way back.
--connect jdbc:mysql://database.example.com/employees — Connect string
Identifies the database. Sqoop looks at its scheme, here jdbc:mysql://, to choose the logic specific to the database. Databases with built-in support are handled automatically.
--table foo — Table
The table to import. Without other instructions, the files are written to a directory named after the table inside the user's directory in HDFS. The parent directory or the target can be specified separately.
--split-by employee_id — Split column
The column that divides the work among the map tasks. Without this argument, Sqoop uses the primary key of the table. It must be specified when the table has no index or has a multi-column key.
--num-mappers n — Parallelism
The number of map tasks that perform the import in parallel. Increasing it beyond what the MapReduce cluster can handle makes the tasks run serially, and the database also has a reasonable limit of simultaneous connections.

Beyond the simple import​

What Sqoop offers when importing or exporting a whole table is not enough.

Only what is new

Incremental import

Brings only the rows newer than those already imported: in append mode, by an id column that keeps growing. In lastmodified mode, by a column with the date of the last modification.

Rerun

Saved job

Stores the configuration of a command to run it later. In an incremental import, the saved job keeps the state of the last imported rows, and the description can live in a metastore shared among users.

Query result

Free-form query

In place of a table, the import accepts the result of an SQL query. Each map task runs a copy of the query, and the $CONDITIONS token receives the condition of each one.

Database channel

Direct mode

For some databases, the database's own tools move the data in place of JDBC, and the channel can be faster.

Safe export

Staging table

Receives the export data before the destination, so that a failure midway does not leave partial data in the final table.

Import by-product

Generated class

A Java class that represents a row of the imported table, with the source code available for further processing of the data.

Why Sqoop​

Automatic

The database describes the schema

Sqoop automates most of the process and relies on the database to know the schema of the data to import.

Parallel

Parallel and fault-tolerant operation

The import and the export use MapReduce, which provides parallel operation and fault tolerance.

Databases

Built-in support and any JDBC database

There is specific logic for databases such as MySQL, Oracle and PostgreSQL, and any JDBC-compliant database can be used with the driver installed.

Destinations

HDFS, Hive and HBase

The import writes files to HDFS and can also create tables in Hive or write to an HBase table.

Formats

Delimited text, Avro and SequenceFiles

Records can be written as text, with the delimiters of your choice, or in a binary representation.

Selection

Rows and columns of your choice

It is possible to control the range of rows and the columns imported, and also to import the result of a query.

Where it comes from

Sqoop became an Apache Top Level Project in March 2012. The project was retired in June 2021, and the move to the Apache Attic was completed in July 2021. Its mission was the creation and maintenance of software for bulk data transfer for Apache Hadoop and structured datastores.

In the TDP editions​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter1.4.7TDP Datacenter components

In TDP Datacenter​

In TDP Datacenter, Sqoop is the SQOOP service, installed and managed by Ambari.

Service components

SQOOP (client, one or more). The SQOOP requires HDFS_CLIENT (HDFS) and MAPREDUCE2_CLIENT (MapReduce). Component category.

Configuration

The service has the sqoop-env, sqoop-site and sqoop-atlas-application.properties configurations. In sqoop-env, the user that runs Sqoop is configurable in sqoop_user, and the additional JDBC driver classes in jdbc_drivers.

Lineage

Sending metadata to Atlas through the hook can be enabled in sqoop.atlas.hook (sqoop-env).

Security

Sqoop has a descriptor in the Ambari Kerberos, and authentication can be enabled through Ambari. See Kerberos. In sqoop-atlas-application.properties are the Kafka client properties of the hook, atlas.jaas.KafkaClient.option.renewTicket and atlas.jaas.KafkaClient.option.useTicketCache.

Dependencies

Ambari requires in the cluster HDFS.

Next steps​

Sources​

Apache Sqoop

Apache Sqoop - User Guide

Apache Attic - Sqoop