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
- See an export happen
- Architecture
- Anatomy of a command
- Beyond the simple import
- Why Sqoop
- In the TDP editions
See an import happen
Press Play or move forward step by step. Underlined names lead to the Glossary.
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.
In the Glossary: sqoop import · Import
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
See an export happen
The way back: the files in HDFS become rows of a table that already exists 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Architecture
Sqoop interprets the command; MapReduce runs the work; the database and the cluster exchange the data.
What the figure shows:
- The command: the user provides the tool and the arguments and sends it to Sqoop.
- Sqoop is a command-line interface: it interprets the tool and the arguments and launches a MapReduce job on the Hadoop cluster.
- The connector is the database one, which Sqoop uses.
- The map tasks of the MapReduce job do the transfer work.
- The relational database exchanges data with the map tasks in both directions.
- 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.
- 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.
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
| Edition | Version | Documentation |
|---|---|---|
| TDP Datacenter | 1.4.7 | TDP Datacenter components |
In TDP Datacenter
In TDP Datacenter, Sqoop is the SQOOP service, installed and managed by Ambari.
SQOOP (client, one or more). The SQOOP requires HDFS_CLIENT (HDFS) and MAPREDUCE2_CLIENT (MapReduce). Component category.
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.
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.
Ambari requires in the cluster HDFS.
Next steps
TDP Datacenter
TDP Datacenter Architecture
The services of the cluster managed by Ambari and how they relate.
