Updated on 2024-10-09 GMT+08:00

Using Loader to Import Data from an SFTP Server to Hive

Scenario

Use Loader to import data from an SFTP server to Hive.

Prerequisites

  • You have obtained the service username and password for creating a Loader job.
  • You have had the permission to access the Hive table specified in the job.
  • You have obtained the username and password of the SFTP server as well as the read permission for the source files on the SFTP server. If file name extension needs to be added after a source file is imported, the user must have the write permission of the source file.
  • No disk space alarm is reported, and the available disk space is sufficient for importing and exporting data.
  • When using Loader to import data from the SFTP server, the input paths and input path subdirectories of the SFTP server and the name of the files in these directories do not contain any of the special characters /"':;.
  • 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.

Procedure

Setting Basic Job Information

  1. Access the Loader web UI.

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

  1. Click New Job to go to the Basic Information page and set basic job information.

    Figure 2 Basic Information
    1. Set Name to the name of the job.
    2. Set Type to Import.
    3. Set Group to the group to which the job belongs. No group is created by default. You need to click Add to create a group and click OK to save the created group.
    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.

  2. In the Connection area, click Add to create a connection, set Connector to sftp-connector, click Add, set connection parameters, and click Test to verify whether the connection is available. When "Test Success" is displayed, click OK. Loader allows multiple SFTP servers to be configured. Click Add to add the configuration information of multiple SFTP servers.

    Table 1 Connection parameters

    Parameter

    Description

    Example Value

    Name

    Name of the SFTP server connection

    sftpName

    SFTP Server IP Address

    IP address of the SFTP server

    10.16.0.1

    SFTP Server Port

    Port number of the SFTP server

    22

    SFTP Username

    Username for accessing the SFTP server

    root

    SFTP Password

    Password for accessing the SFTP server

    xxxx

    SFTP Public Key

    Public key of the SFTP server

    OdDt/yn...etM

    When multiple SFTP servers are configured, the data in the specified directories of the servers is imported to Hive.

    Setting Data Source Information

  3. Click Next. On the displayed From page, set the data source information.

    Table 2 Parameter description

    Parameter

    Description

    Example Value

    Input Path

    Input path or name of the source file on an SFTP server. If multiple SFTP server IP addresses are configured for the connector, you can set this parameter to multiple input paths separated with semicolons (;). Ensure that the number of input paths is the same as that of SFTP servers configured for the connector.

    NOTE:

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

    /opt/tempfile;/opt

    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 import.

    • 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 that of Maps. The file name format is import_part_xxxx, where xxxx is a unique random number generated by the system.

    FILE

    Filter Type

    File filter condition. This parameter is used when Path Filter or File Filter is set.

    • WILDCARD: indicates using a wildcard.
    • REGEX: indicates using a regular expression.
    • If the parameter is not set, a wildcard is used by default.

    WILDCARD

    Path Filter

    Wildcard or regular expression for filtering the directories in the input path of the source files. This parameter is used when Filter Type is set. Input Path is not used for filtering. Use semicolons (;) to separate the path filters on multiple servers and use commas (,) to separate the filter conditions of each server. If this parameter is left empty, directories are not filtered.

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

    For example, when Filter type is set to WILDCARD, set the parameter to *; when Filter type is set to REGEX, set the parameter to \\.*.

    1*,2*;1*

    File Filter

    Wildcard or regular expression for filtering the file names of the source files. This parameter is used when Filter Type is set. Use semicolons (;) to separate the path filters on multiple servers and use commas (,) to separate the filter conditions of each server. This parameter cannot be left blank.

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

    For example, when Filter type is set to WILDCARD, set the parameter to *; when Filter type is set to REGEX, set the parameter to \\.*.

    *.txt,*.csv;*.txt

    Encoding Type

    Source file encoding format, for example, UTF-8 and GBK. This parameter can be set only in text file import.

    UTF-8

    Suffix

    File name extension added to a source file after the source file is imported. If this parameter is empty, no file name extension is added to the source file. This parameter is valid only when the data source is a file system. You are advised to set this parameter in incremental data import.

    For example, if the parameter is set to .txt and the source file is test-loader.csv, the source file name is test-loader.csv.txt after export.

    .log

    Compression

    Indicates whether to enable compressed transmission when SFTP is used to export data.

    • The value true indicates that compression is enabled.
    • The value false indicates that compression is disabled.

    true

    Setting Data Transformation

  4. 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 Loader Operator Help and Table 3.

    Table 3 Input and output parameters of the operator

    Input Type

    Output Type

    CSV File Input

    Hive Output

    HTML Input

    Hive Output

    Fixed File Input

    Hive Output

    Figure 3 Operator operation procedure

    Setting Data Storage Information and Executing the Job

  5. Click Next. On the displayed To page, set Storage type to HIVE.

    Table 4 Parameter description

    Parameter

    Description

    Example Value

    Output Directory

    Directory for storing data imported into Hive.

    NOTE:

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

    /opt/tempfile

    Extractors

    Number of Maps that are started at the same time in a MapReduce task of a data configuration operation. The value must be less than or equal to 3000. You are advised to set the parameter to the maximum number of connections on the SFTP server.

    20

    Extractor Size

    Hive does not support this parameter. Please set Extractors.

    -

  6. Click Save and run to save and run the job.

    Checking the Job Execution Result

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

    Figure 4 Viewing job details