官网文档0.2.37:https://prestodb.io/docs/current/

手动安装:参考原文:https://blog.csdn.net/liyaya0201/article/details/102700306

docker 版: 参考:https://hub.docker.com/r/starburstdata/presto/

 

if connect hive . need  config:

vim hive-site.xml

add:

<property>
  <name>hive.metastore.schema.verification</name>
  <value>false</value>
</property>
<property>
  <name>datanucleus.schema.autoCreateAll</name>
  <value>true</value>
</property>
<property>
  <name>hive.metastore.uris</name>
  <value>thrift://hadoop001:9083</value>
</property>

启动Hive Metastore :

nohup bin/hive --service metastore >/dev/null 2>&1 &

 

 

 idea连接 presto 操作:

package com.ruozedata.bigdata.spark.sql01
import java.sql.DriverManager

object PrestoApp {

  def main(args: Array[String]): Unit = {

    Class.forName("com.facebook.presto.jdbc.PrestoDriver")
    val connection = DriverManager.getConnection("jdbc:presto://spark000:8080/catalog","root",null)
    val stmt = connection.createStatement()
    val sql = "select e.empno, e.ename, e.deptno, d.dname from hive.wuji_spark.emp e join mysql.wuji_spark.dept d on e.deptno = d.deptno"
    val resultSet = stmt.executeQuery(sql)

    while (resultSet.next()){
      val empno = resultSet.getInt("empno")
      val ename = resultSet.getString("ename")
      val deptno = resultSet.getString("deptno")
      val dname = resultSet.getString("dname")
      println(empno + "\t" + ename + "\t" + deptno + "\t" + dname)
    }
    resultSet.close()
    stmt.close()
    connection.close()

  }

}

原文链接:https://blog.csdn.net/liyaya0201/java/article/details/102700306

依赖:

  <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.62</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.8.1</version>
        </dependency>



        <dependency>
            <groupId>com.facebook.presto</groupId>
            <artifactId>presto-jdbc</artifactId>
            <version>0.234.1</version>
        </dependency>

 

 

改进:

public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Class.forName("com.facebook.presto.jdbc.PrestoDriver");
        Connection connection = DriverManager.getConnection("jdbc:presto://192.168.18.129:8881/mongodb/swift","hadoop",null);  ;
        Statement stmt = connection.createStatement();
        String sql="show tables";
        sql="select * from mongodb.swift.booking ";
        JSONArray array = new JSONArray();
        ResultSet rs = stmt.executeQuery(sql);
        ResultSetMetaData metaData = rs.getMetaData();
        int columnCount = metaData.getColumnCount();
        // 遍历ResultSet中的每条数据
        while (rs.next())
        {
            JSONObject jsonObj = new JSONObject();
            // 遍历每一列
            for (int i = 1; i <= columnCount; i++) {
                String columnName = metaData.getColumnLabel(i);
                String value = StringUtils.isBlank(rs.getString(columnName)) ? "" : rs.getString(columnName);
                jsonObj.put(columnName, value);
            }
            array.add(jsonObj);
        }

        System.err.println(array);
        rs.close();
        connection.close();

    }

 

posted on 2020-06-20 15:44  lshan  阅读(1473)  评论(0编辑  收藏  举报