Presto使用指南
更新时间:2024-03-13
概览
Presto是Facebook开发的数据查询引擎,可对海量数据进行快速地交互式分析,支持Hive,关系数据库等多种数据源。由于 BOS 在超低价格、超高性能、高可靠和高吞吐的强大存储优势,越来越多企业选择 BOS 作为大数据的存储媒介。因此,本文将对Presto在 BOS 上的使用方法作一个简要的介绍。
前提条件
参考Hive使用指南一文安装并配置Hive
安装配置
安装版本为349,可参考presto部署一文的过程。其中,如果本机也作为worker,在config.properties中可设置:
node-scheduler.include-coordinator=true #需要改为true
在etc/catalog/hive.properties中,配置为:
connector.name=hive-hadoop2
hive.config.resources=/ssd2/hadoop-3.3.2/etc/hadoop/core-site.xml,/ssd2/hadoop-3.3.2/etc/hadoop/hdfs-site.xml #这里的地址一定要正确
hive.metastore.uri=thrift://127.0.0.1:9083
hive.allow-drop-table=false
hive.storage-format=ORC
hive.metastore-cache-ttl=1s
hive.metastore-refresh-interval=1s
hive.metastore-timeout=35m
hive.max-partitions-per-writers=1000
hive.cache.enabled=true
hive.cache.location=/opt/hive-cache
把bos filesystem的jar包复制到plugin/hive-hadoop2/下,之后运行:
./bin/launcher start
启动presto-server,
./presto-cli --server localhost:8881 --catalog hive --schema default
运行
presto:default>use hive;
USE
presto:hive>select * from hive_test limit 10;
a | b
-------+----------
11027 | "11345"
10227 | "24281"
32535 | "16409"
24286 | "24435"
2498 | "10969"
16662 | "16163"
5345 | "26005"
21407 | "5365"
30608 | "4588"
19686 | "11831"
(10 rows)
Query 20230601_084130_00004_dzvjb, FINISHED, 1 node
Splits: 18 total, 18 done (100.00%)
[Latency: client-side: 0:02, server-side: 0:02] [59.4K rows, 831KB] [28.9K rows/s, 404KB/s]
在以上示例中,我们就通过presto查询到了存储在bos中的数据。
基于S3的presto访问
presto访问存储在BOS中的数据只能是通过hive,但是hive访问BOS中的数据有两种方式,第一种就是通过上述的介绍,基于bos-hdfs;第二种就是直接通过S3协议访问BOS。
hive配置
安装metastore:
wget "https://repo1.maven.org/maven2/org/apache/hive/hive-standalone-metastore/3.1.2/hive-standalone-metastore-3.1.2-bin.tar.gz"
tar -zxvf hive-standalone-metastore-3.1.2-bin.tar.gz
sudo mv apache-hive-metastore-3.1.2-bin /usr/local/metastore
sudo chown user:user /usr/local/metastore
下载并使用hive-standalone-metastore,增加必需的jar包:
rm /usr/local/metastore/lib/guava-19.0.jar
cp /usr/local/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar \
/usr/local/metastore/lib/
cp /usr/local/hadoop/share/hadoop/tools/lib/hadoop-aws-3.2.1.jar \
/usr/local/metastore/lib/
cp /usr/local/hadoop/share/hadoop/tools/lib/aws-java-sdk-bundle-1.11.375.jar \
/usr/local/metastore/lib/
之后配置/usr/local/metastore/conf/metastore-site.xml
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost/metastore?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
<property>
<name>hive.metastore.event.db.notification.api.auth</name>
<value>false</value>
</property>
<property>
<name>fs.s3a.access.key</name>
<value>S3_ACCESS_KEY</value>
</property>
<property>
<name>fs.s3a.secret.key</name>
<value>S3_SECRET_KEY</value>
</property>
<property>
<name>fs.s3a.connection.ssl.enabled</name>
<value>false</value>
</property>
<property>
<name>fs.s3a.path.style.access</name>
<value>true</value>
</property>
<property>
<name>fs.s3a.endpoint</name>
<value>S3_ENDPOINT</value>
</property>
fs.s3a.endpoint 是指s3 的endponit,bos的s3 endpoint在BOS S3域名可查.
启动hive metastore:
/usr/local/metastore/bin/start-metastore &
presto配置
preto的版本这里不作改变,hive.properties的内容改为:
connector.name=hive-hadoop2
hive.metastore.uri=thrift://localhost:9083
hive.s3.path-style-access=true
hive.s3.endpoint=S3_ENDPOINT
hive.s3.aws-access-key=S3_ACCESS_KEY
hive.s3.aws-secret-key=S3_SECRET_KEY
hive.s3.ssl.enabled=false
启动presto
/usr/local/trino/bin/launcher start
创建schema
CREATE SCHEMA IF NOT EXISTS hive.iris
WITH (location = 's3a://my-bos-bucket/'); //注意,这里的location就是以s3a开头,如果bucket为my-bos-bucket,则location应为s3a://my-bos-bucket/开头
#创建表
CREATE TABLE IF NOT EXISTS hive.iris.iris_parquet (
sepal_length DOUBLE,
sepal_width DOUBLE,
petal_length DOUBLE,
petal_width DOUBLE,
class VARCHAR
)
WITH (
external_location = 's3a://my-bos-bucket/iris_parquet',
format = 'PARQUET'
);
SELECT
sepal_length,
class
FROM hive.iris.iris_parquet
LIMIT 10;