Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-28317

Support HiveServer2 JDBC Driver's `initFile` parameter to directly read SQL files on the classpath

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      • 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.
      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;
                  });
              }
          }
      }
      
      • 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 .

      Attachments

        Activity

          People

            Unassigned Unassigned
            linghengqian Qiheng He
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: