如何在没有安装jar文件的系统中运行drill?

8tntrjer  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(338)

我正在使用ApacheDrill1.8编写程序。
我正在尝试在未安装的hdfs中运行这个程序。
我认为使用jar文件的方式,drill包含的jar文件可以运行这个程序,因为它是在虚拟机中运行的。
但我对这种方式没有信心。它能工作吗?
如果这种方法可行,如何在jar文件中包含drill?
如果没有,用什么方法?
另外一个问题是,如何使用java代码更改存储配置?

iqih9akk

iqih9akk1#

不管是否在同一台机器上运行drill或hdfs。
为什么需要创建一个jar。
如果您使用maven作为构建工具,请添加drill jdbc驱动程序依赖项:

  1. <dependency>
  2. <groupId>org.apache.drill.exec</groupId>
  3. <artifactId>drill-jdbc</artifactId>
  4. <version>1.8.0</version>
  5. </dependency>

示例代码:

  1. public class TestJDBC {
  2. // Host name of machine on which drill is running
  3. public static final String DRILL_JDBC_LOCAL_URI = "jdbc:drill:drillbit=192.xxx.xxx.xxx";
  4. public static final String JDBC_DRIVER = "org.apache.drill.jdbc.Driver";
  5. public static void main(String[] args) throws SQLException {
  6. try {
  7. Class.forName(JDBC_DRIVER);
  8. } catch (ClassNotFoundException ce) {
  9. ce.printStackTrace();
  10. }
  11. try (Connection conn = new Driver().connect(DRILL_JDBC_LOCAL_URI, null);
  12. Statement stmt = conn.createStatement();) {
  13. String sql = "select employee_id,first_name,last_name from cp.`employee.json` limit 10";
  14. ResultSet rs = stmt.executeQuery(sql);
  15. while (rs.next()) {
  16. System.out.print(rs.getInt("employee_id") + "\t");
  17. System.out.print(rs.getString("first_name") + "\t");
  18. System.out.print(rs.getString("last_name") + "\t");
  19. System.out.println();
  20. }
  21. rs.close();
  22. } catch (SQLException se) {
  23. se.printStackTrace();
  24. }
  25. }
  26. }
展开查看全部

相关问题