Skip to content

linghengqian/hive-server2-jdbc-driver

Repository files navigation

Third-party builds of the HiveServer2 JDBC Driver

The purpose of the current project is to create a Thin JAR of HiveServer2 JDBC Driver. All release products have been verified and usable in the GraalVM Native Image compiled by GraalVM CE For JDK 22.0.2.

The steps to use directly in Maven are as follows. The latest version is available at https://central.sonatype.com/artifact/io.github.linghengqian/hive-server2-jdbc-driver-thin .

<dependencies>
    <dependency>
        <groupId>io.github.linghengqian</groupId>
        <artifactId>hive-server2-jdbc-driver-thin</artifactId>
        <version>{latest.version}</version>
    </dependency>
</dependencies>

The current project also provides a HiveServer2 JDBC Driver Uber JAR to simplify the steps of specifying the classifier. The current JAR also contains fixes for missing classes from the master branch of apache/hive. The steps to use directly in Maven are as follows. The latest version is at https://central.sonatype.com/artifact/io.github.linghengqian/hive-server2-jdbc-driver-uber .

<dependencies>
    <dependency>
        <groupId>io.github.linghengqian</groupId>
        <artifactId>hive-server2-jdbc-driver-uber</artifactId>
        <version>{latest.version}</version>
    </dependency>
</dependencies>

Quick Start

Start a HiveServer2 instance through Docker Engine.

docker run -d -p 10000:10000 -p 10002:10002 --env SERVICE_NAME=hiveserver2 apache/hive:4.0.0

Use third-party builds of this project in any Maven project.

<dependencies>
    <dependency>
        <groupId>io.github.linghengqian</groupId>
        <artifactId>hive-server2-jdbc-driver-thin</artifactId>
        <version>1.4.0</version>
    </dependency>
    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>5.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>5.11.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Simply enjoy the happiness that comes without dependency conflicts.

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.jupiter.api.Test;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
@SuppressWarnings("SqlNoDataSourceInspection")
public class ExampleTest {
    @Test
    void test() throws SQLException {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:hive2://127.0.0.1:10000/");
        config.setDriverClassName("org.apache.hive.jdbc.HiveDriver");
        try (HikariDataSource dataSource = new HikariDataSource(config);
             Connection connection = dataSource.getConnection();
             Statement statement = connection.createStatement()) {
            statement.execute("CREATE DATABASE demo_ds_0");
            statement.executeQuery("show tables");
            statement.execute("create table hive_example(a string, b int) partitioned by(c int)");
            statement.execute("alter table hive_example add partition(c=1)");
            statement.execute("insert into hive_example partition(c=1) values('a', 1), ('a', 2),('b',3)");
            statement.executeQuery("select count(distinct a) from hive_example");
            statement.executeQuery("select sum(b) from hive_example");
        }
    }
}

Background

The current project is actually a third-party build of HiveServer2 JDBC Driver. apache/hive only provides Skinny JAR and Uber JAR for HiveServer2 JDBC Driver, which leads to many unexpected situations in downstream projects.

For org.apache.hive:hive-jdbc:4.0.0 corresponding to Skinny JAR, this leads to PRs like apache/shardingsphere#31680 and apache/shardingsphere#31774 . The related PRs make hundreds of lines of dependency adjustments to apache/hive.

For org.apache.hive:hive-jdbc:4.0.0:standalone corresponding to the Uber JAR, this leads to issues like https://issues.apache.org/jira/browse/HIVE-28315 and https://issues.apache.org/jira/browse/HIVE-28445. It often takes months to wait for the fixes of the related issues to be released into the new version, without any way to fix the class conflicts. This is almost unacceptable to downstream projects.

It is designed to be easily integrated into the nativeTest form of the GraalVM Native Image of apache/shardingsphere or other projects.

More background at https://lists.apache.org/thread/63lr45kyh78s64spwsjxjy8zdyzprnz1 .

Release Note

Refer to CHANGELOG .

Contributing

Refer to CONTRIBUTING .

About

Third-party builds of HiveServer2 JDBC Driver.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages