Help Center/ MapReduce Service/ Component Operation Guide (LTS) (Ankara Region)/ Using Loader/ Exporting Data/ Typical Scenario: Exporting Data from HDFS or OBS to a Relational Database
Updated on 2024-11-29 GMT+08:00

Typical Scenario: Exporting Data from HDFS or OBS to a Relational Database

Scenario

This section describes how to use Loader to export data from HDFS or OBS to a relational database.

Prerequisites

  • You have obtained the service username and password for creating a Loader job.
  • You have had the permission to access the HDFS or OBS directories and data involved in job execution.
  • You have obtained the username and password of the relational database.
  • No disk space alarm is reported, and the available disk space is sufficient for importing and exporting data.
  • If a configured task requires the Yarn queue function, the user must be authorized with related Yarn queue permission.
  • The user who configures a task must obtain execution permission on the task and obtain usage permission on the related connection of the task.
  • Before the operation, perform the following steps:
    1. Obtain the JAR file of the relational database driver and save it to the following directory on the active and standby Loader nodes: ${BIGDATA_HOME}/FusionInsight_Porter_*/install/FusionInsight-Sqoop-1.99.3/FusionInsight-Sqoop-1.99.3/server/webapps/loader/WEB-INF/ext-lib.
    2. Run the following command on the active and standby nodes as user root to modify the permission:

      cd ${BIGDATA_HOME}/FusionInsight_Porter_*/install/FusionInsight-Sqoop-1.99.3/FusionInsight-Sqoop-1.99.3/server/webapps/loader/WEB-INF/ext-lib

      chown omm:wheel JAR file name

      chmod 600 JAR file name

    3. Log in to FusionInsight Manager and choose Cluster > Services > Loader. On the Dashboard tab page that is displayed, click More and select Restart Service. In the displayed dialog box, enter the administrator password to restart the Loader service.

Procedure

Configure basic job information.

  1. Access the Loader web UI.

    1. Log in to FusionInsight Manager.
    2. Choose Cluster > Services > Loader.
    3. Click LoaderServer(Node name, Active). The Loader web UI is displayed.
      Figure 1 Loader web UI

  2. Click New Job. Configure basic job parameters on the Basic Information page displayed.

    Figure 2 Basic Information page
    1. Enter a job name in Name.
    2. Set Type to Export.
    3. Set Group to the group to which the job belongs. There is no group created by default. Click Add, enter the group name, and click OK.
    4. Set Queue to the Yarn queue that executes the job. The default value is root.default.
    5. Set Priority to the priority of the Yarn queue that executes the job. The default value is NORMAL. The options are VERY_LOW, LOW, NORMAL, HIGH, and VERY_HIGH.

  3. In the Connection area, click Add to create a connection, set Connector to generic-jdbc-connector or a dedicated database connector (oracle-connector, oracle-partition-connector, or mysql-fastpath-connector), set connection parameters, and click Test to verify whether the connection is available. When "Test Success" is displayed, click OK.

    • For connection to relational databases, general database connectors (generic-jdbc-connector) or dedicated database connectors (oracle-connector, oracle-partition-connector, and mysql-fastpath-connector) are available. However, compared with general database connectors, dedicated database connectors perform better in data import and export because they are optimized for specific database types.
    • When mysql-fastpath-connector is used, the mysqldump and mysqlimport commands of MySQL must be available on NodeManagers, and the MySQL client version to which the two commands belong must be compatible with the MySQL server version. If the two commands are unavailable or the versions are incompatible, visit http://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html. Install the MySQL client applications and tools.
    Table 1 generic-jdbc-connector connection parameters

    Parameter

    Description

    Example Value

    Name

    Name of a relational database connection

    dbName

    JDBC Driver Class

    Name of a Java database connectivity (JDBC) driver class

    oracle.jdbc.driver.OracleDriver

    JDBC Connection String

    JDBC connection string, in the format of jdbc:oracle:thin:@Database IP address:Database port number:Database name

    jdbc:oracle:thin:@10.16.0.1:1521:oradb

    Username

    Username for connecting to the database

    omm

    Password

    Password for connecting to the database

    xxxx

    JDBC Connection Properties

    JDBC connection attribute. Click Add to manually add the attribute.

    • Name: connection attribute name
    • Value: connection attribute value
    • Name: socketTimeout
    • Value: 20

Configure data source information.

  1. Click Next. On the displayed From page, set Source type to HDFS.

    Table 2 Data source parameters

    Parameter

    Description

    Example Value

    Input directory

    Specifies the input path when data is exported from HDFS or OBS.

    NOTE:

    You can use macros to define path parameters. For details, see Using Macro Definitions in Configuration Items.

    /user/test

    Path filter

    Specifies the wildcard for filtering the directories in the input paths of the source files. Input directory is not used in filtering. If there are multiple filter conditions, use commas (,) to separate them. If the parameter is empty, the directory is not filtered. The regular expression filtering is not supported.

    • ? matches a single character.
    • * indicates multiple characters.
    • Adding ^ before the condition indicates negated filtering, that is, file filtering.

    *

    File filter

    Specifies the wildcard for filtering the file names of the source files. If there are multiple filter conditions, use commas (,) to separate them. The value cannot be left blank. The regular expression filtering is not supported.

    • ? matches a single character.
    • * indicates multiple characters.
    • Adding ^ before the condition indicates negated filtering, that is, file filtering.

    *

    File Type

    Specifies the file import type.

    • TEXT_FILE: imports a text file and saves it as a text file.
    • SEQUENCE_FILE: imports a text file and saves it as a sequence file.
    • BINARY_FILE: imports files of any format using binary streams but not to process the files.
    NOTE:

    When the file import type to TEXT_FILE or SEQUENCE_FILE, Loader automatically selects a decompression method based on the file name extension to decompress a file.

    TEXT_FILE

    File split type

    Indicates whether to split source files by file name or size. The files obtained after the splitting are used as the input files of each map in the MapReduce task for data export.

    • FILE: indicates that the source file is split by file. That is, each map processes one or multiple complete files, the same source file cannot be allocated to different maps, and the source file directory structure is retained after data import.
    • SIZE: indicates that the source file is split by size. That is, each map processes input files of a certain size, and a source file can be divided and processed by multiple maps. After data is stored in the output directory, the number of saved files is the same as the number of maps. The file name format is import_part_xxxx, where xxxx is a unique random number generated by the system.

    FILE

    Extractors

    Number of Maps that are started at the same time in a MapReduce task of a data configuration operation. This parameter cannot be set when Extractor size is set. The value must be less than or equal to 3000.

    20

    Extractor size

    Specifies the size of data processed by maps that are started in a MapReduce job of a data configuration operation. The unit is MB. The value must be greater than or equal to 100. The recommended value is 1000. This parameter cannot be set when Extractors is set. When a relational database connector is used, Extractor size is unavailable. You need to set Extractors.

    -

Configure data transformation.

  1. Click Next. On the displayed Transform page, set the transformation operations in the data transformation process. For details about how to select operators and set parameters, see Operator Help and Table 3.

    Table 3 Input and output parameters of the operator

    Input Type

    Output Type

    CSV File Input

    Table Output

    HTML File Input

    Table Output

    Fixed File Input

    Table Output

    In input, drag CSV File Input, HTML File Input, or Fixed File Input to the grid. In output, drag Table Output to the grid. Use an arrow to connect CSV File Input, HTML File Input, or Fixed File Input to Table Output.

Set data storage information and execute the job.

  1. Click Next. On the displayed To page, set the data storage mode.

    Table 4 Parameter description

    Parameter

    Description

    Example Value

    Schema name

    Specifies the database schema name.

    dbo

    Table name

    Specifies the name of a database table that is used to save the final data of the transmission.

    NOTE:

    Table names can be defined using macros. For details, see Using Macro Definitions in Configuration Items.

    test

    Temporary table

    Specifies the name of a temporary database table that is used to save temporary data during the transmission. The fields in the table must be the same as those in the database specified by Table name.

    NOTE:

    A temporary table is used to prevent dirty data from being generated in the destination table when data is exported to the database. Data is migrated from the temporary table to the destination table only after all data is successfully written to the temporary table. Using temporary tables increases the job execution time.

    tmp_test

  2. Click Save and Run to save and run the job.

View the job execution result.

  1. Go to the Loader web UI. When Status is Succeeded, the job is complete.

    Figure 3 Viewing a job