> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/gridgain/gridgain-8/integrations/data-lake-accelerator/loading-and-synchronizing-with-hive.md).

# Loading and Synchronizing with Hive

Set up GridGain Hive Store to import a Hive schema, load data from Hadoop, and synchronize data between GridGain and Hadoop.

This document explains how to set up GridGain Hive Store and use it for:

* Schema importing
* Initial data loading
* Synchronization between GridGain and Hadoop

## Prerequisites

1. Install GridGain following this [Getting Started guide](/docs/gridgain/gridgain-8/integrations/data-lake-accelerator/getting-started.md).
2. Create an account in [GridGain Nebula](https://www.gridgain.com/docs/nebula/about/overview).
3. Ensure that the following versions are used: Apache Hadoop version 2.x and Apache Hive 2.x with configured transactions.
4. Run **hiveserver2** in order to enable JDBC connections to the Hive cluster.

Refer to the [official Apache Hive documentation](https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions) about transaction manager and related properties.

You must also have the **transactional property** enabled at the table level, for example:

```sql
CREATE TABLE test_pk1 (
  id Integer,
  value String,
  PRIMARY KEY (id)  DISABLE NOVALIDATE
) STORED AS ORC TBLPROPERTIES ('transactional'='true');
```

## Schema Importing

1. Go to GridGain Nebula, sign up or sign in if you already have an account.
2. Download Web Agent from GridGain Nebula:

   ![](https://3529983645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArQLGGUSG0VzKl1t2Y53%2Fuploads%2Fgit-blob-af697f4ac7d9082be48dc4e0878fe0d8a1faae70%2Fgg8-dla-hive-01.png?alt=media)
3. Configure Web Agent. The extracted package should contain the corresponding Hive JDBC driver in the jdbc-drivers directory. The driver's dependencies should be included in the java class path of the Web Agent. One possible solution is to place required jars in the Web Agent root directory.
4. Click Import from Database:

   ![](https://3529983645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArQLGGUSG0VzKl1t2Y53%2Fuploads%2Fgit-blob-188409ee11cf9b71e3c6db5ec8c6d1943ae94044%2Fgg8-dla-hive-02.png?alt=media)
5. Configure your Hive JDBC connection to allow Web Agent to collect metadata from the target Hive installation:

   ![](https://3529983645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArQLGGUSG0VzKl1t2Y53%2Fuploads%2Fgit-blob-61417155fa982b99a594fcfd6f8a9bb13e964487%2Fgg8-dla-hive-03.png?alt=media)
6. Select schema(s) to import:

   ![](https://3529983645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArQLGGUSG0VzKl1t2Y53%2Fuploads%2Fgit-blob-14a49bf3e90413c61565a3f364eb405fe9f68398%2Fgg8-dla-hive-04.png?alt=media)
7. Select the desired tables and configure the cache template:

   ![](https://3529983645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArQLGGUSG0VzKl1t2Y53%2Fuploads%2Fgit-blob-7671de8b5f9e7404853f8333b2f48450520b3a43%2Fgg8-dla-hive-05.png?alt=media)
8. Configure the results of project generation:

   ![](https://3529983645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArQLGGUSG0VzKl1t2Y53%2Fuploads%2Fgit-blob-70296ecbbc615d23821be565d80a792d603bced9%2Fgg8-dla-hive-06.png?alt=media)
9. Go to the generated configuration page:

   ![](https://3529983645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArQLGGUSG0VzKl1t2Y53%2Fuploads%2Fgit-blob-dbed9e7c59db6841b06d3c8a3d60cbfacc8d00fd%2Fgg8-dla-hive-07.png?alt=media)
10. Fill in the configuration fields and click Save and Download. GridGain Nebula will generate a maven project and implement the Hive CacheStore and cluster configurations:

    ![](https://3529983645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArQLGGUSG0VzKl1t2Y53%2Fuploads%2Fgit-blob-3e01289e50ced47b1308e123e632a459fbf91eda%2Fgg8-dla-hive-08.png?alt=media)
11. Place the Hive JDBC driver in the application java classpath. Here's an example maven dependency:

    ```xml
    <dependency>
    	<groupId>org.apache.hive</groupId>
         <artifactId>hive-jdbc</artifactId>
         <version>2.3.4</version>
         <exclusions>
             <exclusion>
                <groupId>org.eclipse.jetty.aggregate</groupId>
                <artifactId>jetty-all</artifactId>
             </exclusion>
         </exclusions>
    </dependency>
    ```

    The JDBC driver should be loaded before GridGain caches start:

    ```java
    try {
        Class.forName("org.apache.hive.jdbc.HiveDriver");
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException("No org.apache.hive.jdbc.HiveDriver", e);
    }
    ```
12. Edit the generated `secret.properties` file located in `src/main/resources/secret.properties` and add the Hive connection details.
13. Run `ServerNodeSpringStartup` or `ServerNodeCodeStartup` (the two classes use different types of configuration).

## Data Loading and Synchronization

This section shows how to use `HiveCacheJdbcPojoStore` for data loading and synchronization:

1. Add the corresponding GridGain Hadoop Connector dependency to the generated project pom:

   ```xml
    <dependency>
        <groupId>org.gridgain.plugins</groupId>
        <artifactId>gridgain-hive-store</artifactId>
        <version>8.10</version>
    </dependency>
   ```
2. Replace instances of `org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory` with `org.gridgain.cachestore.HiveCacheJdbcPojoStoreFactory`:

   ```java
   HiveCacheJdbcPojoStoreFactory cacheStoreFactory = new HiveCacheJdbcPojoStoreFactory();
   ```
3. Set `streamerEnabled` to true to enable more efficient data loading:

   ```java
   cacheStoreFactory.setStreamerEnabled(true);
   ```

## Write-through and read-through

Both `org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore` and `org.gridgain.cachestore.HiveCacheJdbcPojoStore` are based on the read-through and write-through cache capabilities.

Read more about these concepts in [Database Caching](https://ignite.apache.org/use-cases/caching/database-caching.html) and [Read-Through and Write-Through](/docs/gridgain/gridgain-8/gridgain8-development/caches-and-memory/persistence/external-storage.md).

The generated project will already contain the code that enables this functionality.

```java
CacheConfiguration ccfg = new CacheConfiguration();
ccfg.setReadThrough(true);
ccfg.setWriteThrough(true);
```
