Updated on 2022-02-22 GMT+08:00

Running a HiveSQL Job

You can submit programs developed by yourself to MRS to execute them, and obtain the results. This section describes how to submit a HiveSQL job on the MRS management console. HiveSQL jobs are used to submit SQL statements and script files for data query and analysis. Both SQL statements and scripts are supported. If SQL statements contain sensitive information, use Script to submit them.

Prerequisites

You have uploaded the program packages and data files required for running jobs to OBS or HDFS.

Submitting a Job on the GUI

  1. Log in to the MRS management console.
  2. Choose Clusters > Active Clusters, select a running cluster, and click its name to switch to the cluster details page.
  3. If Kerberos authentication is enabled for the cluster, perform the following steps. If Kerberos authentication is not enabled for the cluster, skip this step.

    In the Basic Information area on the Dashboard tab page, click Click to synchronize on the right side of IAM User Sync to synchronize IAM users. For details, see Synchronizing IAM Users to MRS.

    • When the policy of the user group to which the IAM user belongs changes from MRS ReadOnlyAccess to MRS CommonOperations, MRS FullAccess, or MRS Administrator, wait for 5 minutes until the new policy takes effect after the synchronization is complete because the SSSD (System Security Services Daemon) cache of cluster nodes needs time to be updated. Then, submit a job. Otherwise, the job may fail to be submitted.
    • When the policy of the user group to which the IAM user belongs changes from MRS CommonOperations, MRS FullAccess, or MRS Administrator to MRS ReadOnlyAccess, wait for 5 minutes until the new policy takes effect after the synchronization is complete because the SSSD cache of cluster nodes needs time to be updated.

  4. Click the Jobs tab.
  5. Click Create. The Create Job page is displayed.
  6. Configure job information.

    Table 1 Job configuration information

    Parameter

    Description

    Name

    Job name. It contains 1 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

    NOTE:

    You are advised to set different names for different jobs.

    SQL Type

    Submission type of the SQL statement

    • SQL
    • Script

    SQL Statement

    This parameter is valid only when SQL Type is set to SQL. Enter the SQL statement to be executed, and then click Check to check whether the SQL statement is correct. If you want to submit and execute multiple statements at the same time, use semicolons (;) to separate them.

    SQL File

    This parameter is valid only when SQL Type is set to Script. The path of the SQL file to be executed must meet the following requirements:

    • Contains a maximum of 1,023 characters, excluding special characters such as ;|&><'$. The parameter value cannot be empty or full of spaces.
    • The path of the program to be executed can be stored in HDFS or OBS. The path varies depending on the file system.
      • OBS: The path must start with obs://. Example: obs://wordcount/program/xxx.jar
      • HDFS: The path must start with /user. For details about how to import data to HDFS, see Importing Data.
    • For SparkScript and HiveScript, the path must end with .sql. For MapReduce, the path must end with .jar. For Flink and SparkSubmit, the path must end with .jar or .py. The .sql, .jar, and .py are case-insensitive.
    NOTE:

    A file path on OBS can start with obs://. To submit jobs in this format, you need to configure permissions for accessing OBS.

    • If the OBS permission control function is enabled during cluster creation, you can use the obs:// directory without extra configuration.
    • If the OBS permission control function is not enabled or is not supported when you create a cluster, configure the function by following instructions in Accessing OBS.

    Program Parameter

    (Optional) Used to configure optimization parameters such as threads, memory, and vCPUs for the job to optimize resource usage and improve job execution performance.

    Table 2 describes the common parameters of a running program.

    Service Parameter

    (Optional) It is used to modify service parameters for the job. The parameter modification applies only to the current job. To make the modification take effect permanently for the cluster, follow instructions in Configuring Service Parameters.

    To add multiple parameters, click on the right. To delete a parameter, click Delete on the right.

    Table 3 lists the common service configuration parameters.

    Command Reference

    Command submitted to the background for execution when a job is submitted.

    Table 2 Program parameters

    Parameter

    Description

    Example Value

    --hiveconf

    Hive service configuration, for example, set the execution engine to MapReduce.

    Setting the execution engine to MR: --hiveconf "hive.execution.engine=mr"

    --hivevar

    Custom variable, for example, variable ID.

    Setting the variable ID: --hivevar id="123" select * from test where id = ${hivevar:id}

    Table 3 Service parameters

    Parameter

    Description

    Example Value

    fs.obs.access.key

    Key ID for accessing OBS.

    -

    fs.obs.secret.key

    Key corresponding to the key ID for accessing OBS.

    -

    hive.execution.engine

    Engine for running a job.

    • mr
    • tez

  7. Confirm job configuration information and click OK.

    After the job is created, you can manage it.

Submitting a Job in the Background

  1. Log in to the MRS management console.
  2. Choose Clusters > Active Clusters, select a running cluster, and click its name to switch to the cluster details page.
  3. On the Nodes tab page, click the name of a Master node to go to the ECS management console.
  4. Click Remote Login in the upper right corner of the page.
  5. Enter the username and password of the Master node as prompted. The username is root and the password is the one set during cluster creation.
  6. Run the following command to initialize environment variables:

    source /opt/BigData/client/bigdata_env

    • In MRS 3.x and later versions, the default installation path of the client is /opt/Bigdata/client. In MRS 3.x and earlier versions, the default installation path is /opt/client. For details, see the actual situation.
    • If you use the client to connect to a specific Hive multi-instance in a scenario where multiple Hive instances are installed, run the following command to load the environment variables of the instance. Otherwise, skip this step. For example, load the environment variables of the Hive2 instance.

      source /opt/BigData/client/Hive2/component_env

  7. If the Kerberos authentication is enabled for the current cluster, run the following command to authenticate the user. If the Kerberos authentication is disabled for the current cluster(normal mode), skip this step.

    kinit MRS cluster user (The user must be in the hive user group.)

  8. Run the beeline command to connect to HiveServer and run tasks.

    beeline

    For clusters in normal mode, run the following commands. If no component service user is specified, the current OS user is used to log in to the HiveServer.

    beeline -n Component service user

    beeline -f SQL files (SQLs in the execution files)