要完成如下任务,请确保已经使用其他方法将hudi数据同步到hive中。
如果没有同步hive数据,可参考文章:使用flink SQL Client将mysql数据写入到hudi并同步到hive,并且,以下内容中的presto查询,即是基于上述参考文章所同步的hive表进行查询的,建议可先阅读上述参考文章。
以下presto安装以单节点为例。
presto 0.261下载下载presto-server和presto-cli
mkdir /data mkdir /data/presto-cli cd /data wget https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.261/presto-server-0.261.tar.gz wget https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.261/presto-cli-0.261-executable.jar cp presto-cli-0.261-executable.jar /data/presto-cli chmod +x /data/presto-cli/presto-cli-0.261-executable.jar ln -s /data/presto-cli/presto-cli-0.261-executable.jar /data/presto-cli/presto tar zxvf presto-server-0.261.tar.gz ln -s /data/presto-server-0.261 /data/presto-server
目录如下:
presto配置进入/data/presto-server目录下,执行如下操作:
新建etc目录以及配置文件:
cd /data/presto-server mkdir data mkdir etc cd etc touch config.properties touch jvm.config touch log.properties touch node.properties mkdir catalog touch catalog/hive.properties
编辑配置文件:
vim config.properties
填入:
coordinator=true node-scheduler.include-coordinator=true http-server.http.port=8282 query.max-memory=5GB query.max-memory-per-node=1GB query.max-total-memory-per-node=2GB discovery-server.enabled=true discovery.uri=http://hadoop1:8282
上述配置项为presto-server配置信息,同时将coordinator以及worker都集中在同一台主机。
vim jvm.config
填入:
-server -Xmx8G -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+UseGCOverheadLimit -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumponOutOfMemoryError -XX:+ExitonOutOfMemoryError
上述配置项为presto-server jvm相关配置信息。
vim log.properties
填入:
com.facebook.presto = INFO
上述配置项为presto-server日志级别。
vim node.properties
填入:
node.environment=production node.id=presto1 node.data-dir=/data/presto-server/data
上述配置项为节点信息。
vim catalog/hive.properties
填入:
connector.name = hive-hadoop2 hive.metastore.uri = thrift://hadoop:9083 hive.parquet.use-column-names=true hive.config.resources = /data/presto-server/etc/catalog/core-site.xml,/data/presto-server/etc/catalog/hdfs-site.xml
上述配置项为hive连接信息,其中,
-
connector.name为hive connector名称
-
hive.metastore.uri为hive metastore连接信息
-
hive.parquet.use-column-names=true设置来解决presto读取parquet类型问题,必填项
-
hive.config.resources为hdfs集群的相关配置文件信息,可将其拷贝到/data/presto-server/etc/catalog目录下
关于presto更详细的配置信息可参考:https://prestodb.io/docs/current/installation/deployment.html
presto server启动启动命令如下:
/data/presto-server/bin/launcher start
启动之后,可以在/data/presto-server/data/var/log中看到相应的日志文件。
[root@hadoop1 presto-server]# ll /data/presto-server/data/var/log total 3208 -rw-r--r--. 1 root root 1410243 Sep 27 07:07 http-request.log -rw-r--r--. 1 root root 2715 Sep 27 05:44 launcher.log -rw-r--r--. 1 root root 1867319 Sep 27 06:01 server.logpresto cli启动
/data/presto-cli/presto --server hadoop1:8282 --catalog hive --schema test
其中,schema表示库名。
至此,我们完成了presto安装与启动工作,接下来就可以对hive中的数据进行查询。
使用presto查询cow表首先确保,你已经通过其他方式,将hudi COW表同步到hudi中,如果没有相关同步,可参考文章:使用flink SQL Client将mysql数据写入到hudi并同步到hive
本文在参考文章基础上进行,所查询的表也是基于上述参考文章导入的表数据。
执行如下查询操作:
select count(*) from stu_tmp_1; select * from stu_tmp_1 limit 10; select name from stu_tmp_1 group by name, school limit 10;
得到如下结果:



