EMR Serverless Spark connects to an external Hive Metastore service, letting you access its stored data. This topic shows you how to configure this connection in your workspace to manage and use your data resources efficiently.
Prerequisites
A workspace and an SQL session are created. For more information, see Create a workspace and Manage SQL sessions.
Limitations
-
To use the Hive Metastore service, you must restart any existing sessions in your workspace.
-
After you set a Hive Metastore service as the default data catalog, workflow tasks will use it.
Procedure
Step 1: Prepare Hive Metastore service
This document uses a Hive Metastore service from EMR on ECS as an example. If you already have a Hive Metastore service in your VPC, you can skip this step.
-
On the EMR on ECS page, create a DataLake cluster that includes the Hive service and set Metadata to Built-in MySQL. For more information, see Create a cluster.
-
Use SSH to log on to the cluster's master node. For more information, see Log on to a cluster.
-
Run the following command to enter the Hive CLI:
hive -
Run the following commands to create a table named
dw_usersin Object Storage Service (OSS) and insert data into it:CREATE TABLE `dw_users`( `name` string) LOCATION 'oss://<yourBucket>/path/to/file'; INSERT INTO dw_users select 'Bob';
Step 2: Add a network connection
-
Go to the network connection page.
-
Log on to the EMR console.
-
In the left-side navigation pane, choose EMR Serverless > Spark.
-
On the Spark page, click the name of the target workspace.
-
On the EMR Serverless Spark page, click Normal Network Connection in the left-side navigation pane.
-
-
On the Normal Network Connection page, click Create Network Connection.
-
In the Create Network Connection dialog box, configure the following parameters and click OK.
Parameter
Description
Name
Enter a name for the new connection.
VPC
Select the same VPC as the EMR cluster.
vSwitch
Select the vSwitch that is in the same VPC as the EMR cluster.
A Status of Succeeded indicates that the network connection has been added.
Step 3: Open the Hive Metastore service port
-
Obtain the CIDR block of the vSwitch for the network connection.
You can log on to the VPC console and go to the vSwitch page to obtain the CIDR block of the vSwitch.
-
Add a security group rule.
-
Log on to the EMR on ECS console.
-
On the EMR on ECS page, click the ID of the target cluster.
-
On the Basic Information page, click the link next to Cluster Security Group.
-
On the Security Group page, click Add Rule. Specify the Source and Port, and then click OK.
Parameter
Description
Port
Enter
9083.Source
Enter the CIDR block of the vSwitch that you obtained in the preceding step.
ImportantTo prevent security risks from external attacks, do not set the Source to 0.0.0.0/0.
-
Step 4: Connect to Hive Metastore
-
On the EMR Serverless Spark page, click Catalogs in the left-side navigation pane.
-
On the Catalogs page, click Add Catalog.
-
In the dialog box that appears, click External Hive Metastore, configure the following information, and then click OK. On the External Hive Metastore tab, enter
hive_metastorein the Data Catalog Name field, and configure the following parameters.Parameter
Description
Normal Network Connection
Select the network connection that you added in Step 2.
Metastore service address
The URI of the Hive Metastore service. The format is
thrift://<IP address of Hive metastore>:9083.The
<IP address of Hive metastore>is the internal IP of the master node in your EMR on ECS cluster. You can find this IP address on the cluster's Nodes page.NoteIf your Hive Metastore service uses high availability (HA), enter the URIs for all relevant nodes, separated by commas (,). For example:
thrift://<IP address of Hive metastore 1>:9083,thrift://<IP address of Hive metastore 2>:9083.Kerberos keytab file
The path to the Kerberos keytab file.
Kerberos principal
The name of the Principal in the keytab file, which is used to authenticate with the Kerberos service. You can use the
klist -kt <keytab_file>command to view the name of the Principal in the target keytab file.
Step 5: Use Hive Metastore
-
On the Catalogs page, find the
hive_metastoreentry and click Set as default in the Actions column to set it as the default data catalog for the workspace. -
Restart the SQL session.
If an SQL session is running in your workspace, you must restart it for the
hive_metastoresettings to take effect. -
Query data from the
hive_metastoretable in your SparkSQL job.-
Create a SparkSQL development job. For more information, see SparkSQL development.
-
Run the following command to query the
dw_userstable in the Hive Metastore service:SELECT * FROM dw_users;The query returns one record, with the value
Bobin thenamecolumn.
-