Title
Page icon
Create new category
Edit page index title
Edit category
Edit link
Access Hive Tables with Spark
You can configure Spark 3.5.5 and Spark 4.1.1 to access and query Hive tables through the Hive Metastore.
Hive Metastore compatibility
The Hive Metastore in ODP can use Hive 4.x. Spark 3.5.5 and Spark 4.1.1 require different Hive Metastore configurations.
Spark version | Hive client | Hive Metastore configuration |
|---|---|---|
Spark 3.5.5 | Hive 2.3-based client | Use the Hive 3 standalone metastore JAR. |
Spark 4.1.1 | Supports Hive 4 | Use the Hive client libraries and set the metastore version to |
For Spark 3.5.5, using the default Hive client with a Hive 4 Metastore can cause errors such as Invalid method name: 'get_table' and NoSuchFieldError: out, or prevent Hive tables from being displayed.
Prerequisites
Before you access Hive tables:
Set
SPARK_HOMEfor the Spark version that you want to use.For Spark 3.5.5:
export SPARK_HOME=/usr/odp/current/spark3-clientFor Spark 4.1.1:
export SPARK_HOME=/usr/odp/current/spark4-clientVerify the Hive Metastore URI. The URI is typically configured in
hive-site.xml.For example:
thrift://<hms-host>:9083Use the version-specific Spark client instead of running
spark-sqldirectly from the systemPATH.
Note: The procedures on this page apply to non-ACID Hive tables. To access Hive managed ACID tables, use Hive Warehouse Connector (HWC).
Access Hive tables with Spark 3.5.5
Spark 3.5.5 requires a Hive 3 standalone metastore JAR to communicate with the Hive Metastore.
Configure the metastore JAR
Set SPARK_HOME:
Set the metastore JAR:
Verify that the JAR exists:
Access Hive tables using Spark SQL
Run:
Replace default with the required Hive database.
For example:
Access Hive tables using spark-submit
Use the same Hive Metastore configurations when you submit an application:
In your application, enable Hive support when you create the Spark session:
Use the same metastore configurations when you use spark-shell.
Access Hive tables with Spark 4.1.1
Spark 4.1.1 can communicate with the Hive 4 Metastore by using the Hive client libraries.
Spark 4.1.1 also requires JDK 17 for the YARN ApplicationMaster and executors.
Configure JDK 17
Set the JDK 17 installation directory:
If multiple JDK versions are installed, specify the complete JDK 17 installation path.
For example:
Without JDK 17, Spark 4.1.1 might report errors such as:
Configure the Hive client libraries
Set SPARK_HOME:
Create the Hive Metastore JAR path:
To verify the generated paths, run:
Access Hive tables using Spark SQL
Run:
Replace default with the required Hive database.
Note: With Spark 4.1.1
spark-sql, don't use-eand-fin the same command. Use-eto run a query directly, or use--databasewith-fto run queries from a file.
Access Hive tables using spark-submit
Run:
Hive Metastore configuration by Spark version
Configuration | Spark 3.5.5 | Spark 4.1.1 |
|---|---|---|
Spark client |
|
|
|
|
|
| Spark 2 |
|
|
|
|
Java configuration | No additional configuration | Configure JDK 17 for the ApplicationMaster and executors |
Verify Hive table access
After you configure the Hive Metastore, run the following queries:
Verify that Spark displays the expected Hive databases and tables.
If SHOW DATABASES displays only the default database when additional Hive databases exist, verify the configured metastore JARs and metastore version.
Troubleshoot Hive table access
Issue | Cause | Resolution |
|---|---|---|
| Spark 3.5.5 is using an incompatible Hive client to communicate with Hive 4. | Configure the Hive 3 standalone metastore JAR and set |
| Hive client version mismatch. | Configure the Hive 3 standalone metastore JAR and metastore version |
Hive databases or tables aren't displayed | Incorrect | Use the version-specific Spark client and verify |
| Spark 4.1.1 is running with JDK 11. | Configure JDK 17 for the ApplicationMaster and executors. |
Managed ACID table reads fail or return unexpected results | The table is a Hive managed ACID table. | Use Hive Warehouse Connector (HWC). |
Access Hive managed ACID tables
The procedures on this page are intended for non-ACID Hive tables accessed through Spark SQL and the Hive Metastore.
For Hive managed ACID tables, use Hive Warehouse Connector (HWC).
For Spark 3, see:
For Spark 4, see: