Qiheng He created HIVE-28317:
--------------------------------

             Summary: Support HiveServer2 JDBC Driver's `initFile` parameter to 
directly read SQL files on the classpath
                 Key: HIVE-28317
                 URL: https://issues.apache.org/jira/browse/HIVE-28317
             Project: Hive
          Issue Type: Wish
            Reporter: Qiheng He


- Support HiveServer2 JDBC Driver's {*}initFile{*} parameter to directly read 
SQL files on the classpath.
- In https://issues.apache.org/jira/browse/HIVE-5867 , the {*}initFile{*} 
parameter of HiveServer2 JDBC Driver is supported to read SQL files on absolute 
paths. However, this jdbcUrl parameter does not natively support paths on the 
{*}classpath{*}. This necessitates executing additional steps if one needs to 
read a file located on the {*}classpath{*}.

{code:java}
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;

import java.nio.file.Paths;
import java.time.Duration;

public class ExampleTest {

    @Test
    void test() {
        String absolutePath = 
Paths.get("src/test/resources/test-sql/test-databases-hive.sql")
                .toAbsolutePath().normalize().toString();
        HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.apache.hive.jdbc.HiveDriver");
        config.setJdbcUrl("jdbc:hive2://localhost:10000;initFile=" + 
absolutePath);
        try (HikariDataSource hikariDataSource = new HikariDataSource(config)) {
            
Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptions().until(() 
-> {
                hikariDataSource.getConnection().close();
                return true;
            });
        }
    }
}
{code}
- It would greatly facilitate integration testing scenarios, such as those with 
{*}testcontainers-java{*}, if the {*}initFile{*} parameter could recognize 
classpath files by identifying a {*}classpath{*} prefix. For instance, a JDBC 
URL like 
{*}jdbc:hive2://localhost:10000;initFile=classpath:test-sql/test-databases-hive.sql{*}
 would become much more useful.
- Further early discussions on this topic can be found at 
https://github.com/apache/shardingsphere/pull/31526 .



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to