Title
Page icon
Create new category
Edit page index title
Edit category
Edit link
Use Hive Warehouse Connector with Spark 4
Hive Warehouse Connector (HWC) enables Spark 4 applications to access and operate on Hive tables, including Hive managed transactional tables.
This page describes how to configure HWC with Spark 4.1.1, connect to HiveServer2, and perform basic Hive operations.
Prerequisites
Before you begin, ensure that your environment meets the following requirements:
Component | Version |
|---|---|
ODP | 3.3.6.4-1 |
Spark | 4.1.1.3.3.6.4-1 |
Scala | 2.13.17 |
Java | OpenJDK 17.0.19 |
HWC JAR
The HWC JAR for Spark 4 is available at:
Authenticate with Kerberos
On a Kerberos-enabled cluster, obtain a Kerberos ticket before you start Spark Shell.
Run:
Replace the principal with the Spark principal for your environment.
Verify the Kerberos ticket:
Verify that the output contains a valid ticket for the Spark principal.
Start Spark Shell with HWC
Set SPARK_MAJOR_VERSION to 4 and start Spark Shell with the required HWC configurations:
Replace the HiveServer2 JDBC URL and Kerberos principal with the values for your environment.
HWC configuration
Configuration | Value | Description |
|---|---|---|
|
| Uses the Spark 4 binaries. |
| HiveServer2 Kerberos principal | Specifies the Kerberos principal for HiveServer2. |
|
| Loads the required SQL extensions. |
|
| Configures executors to read data through JDBC. |
|
| Configures the Kryo registrator required for Hive ACID tables. |
| HiveServer2 JDBC URL | Specifies the HiveServer2 connection. |
After Spark Shell starts, verify that it uses Spark 4.1.1, Scala 2.13, and Java 17.
Create a Hive Warehouse session
Import the required HWC classes:
Create the Hive Warehouse session:
Use the hive session to perform Hive operations.
List databases
Run:
Verify that the expected Hive databases are displayed.
You can also list databases by using executeQuery:
List tables
Run:
To select a database and list its tables, run:
Replace default with the required Hive database.
View a table schema
To view the columns and data types for a table, run:
Replace employeedata with the required table name.
Create a table
The following example creates an ORC table:
Note: Use the ORC/ACID format for HWC write operations.
Insert data
Insert data into the table:
Read table data
Query the table:
To verify the number of rows, run:
Troubleshoot HWC
Multiple values for the principal
You might receive an error indicating that multiple values are configured for the principal property.
This issue occurs when you specify the HiveServer2 Kerberos principal in both:
and the JDBC URL:
Specify the principal in only one location.
We recommend using:
and omitting principal from the JDBC URL.
Unsupported mechanism type PLAIN
The following error can occur when executors attempt to establish a non-Kerberos SASL connection to HiveServer2:
Verify that the HiveServer2 principal is configured:
Alternatively, specify the principal in the HiveServer2 JDBC URL.
Important: Don't configure the principal in both locations.
GSS initiate failed
The following error can occur when executors don't have valid Kerberos credentials to establish a GSSAPI connection with HiveServer2:
This issue can occur with JDBC_CLUSTER mode because executors establish their own JDBC connections.
To resolve the issue, obtain a valid Kerberos ticket before you start Spark Shell:
Alternatively, configure HWC to use DIRECT_READER_V2:
With DIRECT_READER_V2, executors read data from HDFS by using delegation tokens instead of establishing JDBC connections.