Presto命令行、API操作

丢个官网
我们先要启动presto

./bin/launcher run

1.presto整合mysql

官网文档
展示一下mysql的数据spark数据库下的dept表
Presto命令行、API操作_第1张图片
首先需要在etc/catalog中创建一个mysql.properties

connector.name=mysql
connection-url=jdbc:mysql://localhost:3306
connection-user=root
connection-password=password

接下来执行命令

./bin/presto --server localhost:8090 --catalog mysql

接下来就可以进行操作了
Presto命令行、API操作_第2张图片
需求完成

2.presto整合hive

官网文档
展示一下hive的数据test数据库下的emp表
Presto命令行、API操作_第3张图片
首先需要在etc/catalog中创建一个hive.properties
配置hive.config.resources时要指定core-site.xml和hdfs-site.xml地址

connector.name=hive-hadoop2
hive.metastore.uri=thrift://localhost:9083
hive.config.resources=(core-site.xml),(hdfs-site.xml)

接下来执行命令

./bin/presto --server localhost:8080 --catalog hive

接下来就能操作了,查询emp
Presto命令行、API操作_第4张图片

3.presto整合hive和mysql

直接进行join语句就行了

select * from hive.test.emp e join mysql.spark.dept d on e.iss=d.deptno;

Presto命令行、API操作_第5张图片

需求完成

3.presto的api操作

官网文档
先加依赖


com.facebook.presto
presto-jdbc
0.233.1

上代码

public static void main(String[] args) throws Exception{
		//加载Driver类
        Class.forName("com.facebook.presto.jdbc.PrestoDriver");
        //获得连接,3个参数分别是url,presto的用户名和密码
        Connection connection = DriverManager.getConnection("jdbc:presto://localhost:8090/hive/test", "hadoop", "");
        //通过连接获得Statement 
        Statement statement = connection.createStatement();
        //运行sql获得返回值
        ResultSet resultSet = statement.executeQuery("select * from emp");
        //遍历
        while (resultSet.next()){
            System.out.println(resultSet.getInt("id")+"\t"+resultSet.getString("name"));
        }
    }

查看控制台

Presto命令行、API操作_第6张图片
需求完成

你可能感兴趣的:(Presto命令行、API操作)