Running a HiveSQL Job
MRS allows you to submit and run your own programs, and get the results. This section will show you how to submit a HiveSQL job in an MRS cluster.
HiveSQL jobs enable the submission of SQL statements and script files for data analysis and querying. Both SQL statements and scripts are supported, and script files can be used to submit sensitive information.
You can create a job online and submit it for running on the MRS console, or submit a job in CLI mode on the MRS cluster client.
Prerequisites
- You have uploaded the program packages and data files required by jobs to OBS or HDFS.
- If the job program needs to read and analyze data in the OBS file system, you need to configure storage-compute decoupling for the MRS cluster. For details, see Configuring Storage-Compute Decoupling for an MRS Cluster.
Submitting a Job on the Console
- Log in to the MRS console.
- On the Active Clusters page, select a running cluster and click its name to switch to the cluster details page.
- In the Basic Information area of the Dashboard page, click Synchronize on the right side of IAM User Sync to synchronize IAM users.
Perform this step only when Kerberos authentication is enabled for the cluster.
- After the IAM user synchronization is complete, wait for 5 minutes before submitting a job. For details about IAM user synchronization, see Synchronizing IAM Users to MRS..
- When the policy of the user group an IAM user belongs to changes from MRS ReadOnlyAccess to MRS CommonOperations, MRS FullAccess, or MRS Administrator, or vice versa, it takes time for the cluster node's System Security Services Daemon (SSSD) cache to refresh. To prevent job submission failure, wait for five minutes after user synchronization is complete before submitting the job with the new policy.
- If the IAM username contains spaces (for example, admin 01), jobs cannot be added.
- Click Job Management. On the displayed job list page, click Create.
- Set Type to HiveSql and configure HiveSQL job information be referring to Table 1.
Figure 1 Adding a HiveSQL job
Table 1 Job configuration information Parameter
Description
Example
Name
Job name. It contains 1 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.
hivesql
SQL Type
Submission type of the SQL statement.
- SQL: Run the entered SQL statement.
- Script: Load SQL scripts from HDFS or OBS to run SQL statements.
SQL
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:
Path of the SQL script file to be executed. You can enter the path or click HDFS or OBS to select a file.
- The value contains a maximum of 1,023 characters. It cannot contain special characters (;|&>,<'$) and cannot be left blank or all spaces.
- The OBS program path should start with obs://, for example, obs://wordcount/program/XXX.jar. The HDFS program path should start with hdfs://, for example, hdfs://hacluster/user/XXX.jar.
- The HiveScript file must end with .sql.
obs://wordcount/program/test.sql
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 lists the common program parameters of HiveSQL jobs. You can configure the parameters based on the execution program and cluster resources.
-
Service Parameter
(Optional) Service parameters for the job.
To modify the current job, change this parameter. For permanent changes to the entire cluster, refer to Modifying the Configuration Parameters of an MRS Cluster Component and modify the cluster component parameters accordingly.
Click on the right to add more parameters.
For example, add the following service configuration parameters:
- fs.obs.access.key: key ID used to access OBS in AK/SK mode.
- fs.obs.secret.key: key used to access OBS in AK/SK mode.
- hive.execution.engine: engine for executing the job. The value can be mr or tez.
-
Command Reference
Command submitted to the background for execution when a job is submitted.
beeline-e"SELECT * for TABLE test;"
Table 2 HiveSQL job running program parameters Parameter
Description
Example Value
--hiveconf
Configure the Hive service.
For example, set the execution engine to MapReduce.
- Parameter: --hiveconf
- Value: hive.execution.engine=mr
--hivevar
Set user-defined variables.
Set the variable ID as follows:
- Parameter: --hivevar id
- Value: "123" select * from test where id = ${hivevar:id};
- Confirm job configuration information and click OK.
- After the job is submitted, you can view the job running status and execution result in the job list. After the job status changes to Completed, you can view the analysis result of related programs.
Submitting a Job Using the Cluster Client
- Install the MRS cluster client. For details, see Installing an MRS Cluster Client.
The MRS cluster comes with a client installed for job submission by default, which can also be used directly. For MRS 3.x and later versions, the default client installation path is /opt/Bigdata/client on the Master node. For versions earlier than MRS 3.x, the default client installation path is /opt/client on the Master node.
- Log in to the node where the client is located as the MRS cluster client installation user.
- Initialize environment variables.
cd /opt/Bigdata/client
source bigdata_env
- Perform authentication if Kerberos authentication has been enabled for the current cluster.
Skip this step for normal clusters.
kinit MRScluster service user
The MRS cluster service user needs to create a service user who has the permission to submit jobs on Manager. The user needs to be added to the hive user group. For details, see Creating an MRS Cluster User.
Example:
kinit testuser
- Run the beeline command to connect to Hive in the cluster and run related tasks.
beeline -f SQL file (SQL statements in the execution files.)
To specify a component service user for normal clusters, use the command below. If no service user is specified, HiveServer will connect using the current OS user.
beeline -nMRS cluster service user
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot