- 1. Connectors连接器的原理
- 2 添加Connector
- 2.1 TPC-H和TPC-DS连接器
- 2.2 JMX连接器
- 2.3 黑洞blackhole连接器
- 2.4 memory内存连接器
如果一个数据源的数据格式,可以用Presto/Trino的数据类型表示成表的行和列,就可以实现Presto/Trino提供的服务提供者接口(service provider interface, SPI),抽象成Presto/Trino的表,就可以使用Presto/Trino的SQL查询各种数据源
SPI主要包含3部分的功能:
- 在数据源和Presto/Trino数据处理引擎进行之间数据格式转换,以便读取和写入
- 获取schema、table、视图的元数据
- 进行逻辑单位的数据分区,实现并行计算
其中coordinator的SPI包含元数据SPI、数据统计SPI、数据位置SPI,worker的SPI包含数据流SPI
最基本的Connector与数据源之间建立单条连接;高级的Connector将一条SQL分解成多个连接,并行执行操作
2 添加Connector使用一个连接器连接到一个新的数据源,需要在etc/catalog下面新建一个properties文件, 比如mysql.properties, 文件内容如下:
connector-name=mysql
......省略属性......
- mysql.properties的文件名就是presto系统中的catalog
- connector-name是必填属性,表示使用的是哪个Connector(一个Connector可以用于多个catalog)
有了该catalog配置文件,则会自动将数据库schema和表table暴露给presto
2.1 TPC-H和TPC-DS连接器以内置的方式提供了schema和table,查询时,会通过算法实时生成数据
在所有节点新建连接器配置文件
[root@trino1 catalog]#
[root@trino1 catalog]# pwd
/root/trino-server-367/etc/catalog
[root@trino1 catalog]#
[root@trino1 catalog]# cat tpch.properties
connector.name=tpch
[root@trino1 catalog]#
[root@trino1 catalog]# cat tpcds.properties
connector.name=tpcds
[root@trino1 catalog]#
然后重启Trino
查询数据
[root@trino1 ~]#
[root@trino1 ~]# ./trino --server trino1:8080
trino>
trino> show catalogs;
Catalog
------------
system
test_mysql
tpcds
tpch
(4 rows)
Query 20211227_125302_00002_8x3r9, FINISHED, 2 nodes
Splits: 6 total, 6 done (100.00%)
1.47 [0 rows, 0B] [0 rows/s, 0B/s]
trino>
trino> show schemas from tpch;
Schema
--------------------
information_schema
sf1
sf100
sf1000
sf10000
sf100000
sf300
sf3000
sf30000
tiny
(10 rows)
Query 20211227_125410_00004_8x3r9, FINISHED, 3 nodes
Splits: 6 total, 6 done (100.00%)
2.06 [10 rows, 119B] [4 rows/s, 58B/s]
trino>
2.2 JMX连接器
可以使用JMX连接器查询Trino的coordinator和worker的JVM运行时信息,底层使用的Java管理拓展(Java management extensions)
在所有节点新建连接器配置文件,并重启Trino
[root@trino1 catalog]#
[root@trino1 catalog]# pwd
/root/trino-server-367/etc/catalog
[root@trino1 catalog]#
[root@trino1 catalog]# cat jmx.properties
connector.name=jmx
[root@trino1 catalog]#
JMX连接器为历史数据、聚合数据提供了名称为history的schema,为当前数据提供了名称为current的schema,为元数据提供了名称为information_schema的schema,查询数据如下:
trino>
trino> show schemas from jmx;
Schema
--------------------
current
history
information_schema
(3 rows)
Query 20211227_140351_00002_y9cev, FINISHED, 3 nodes
Splits: 6 total, 6 done (100.00%)
1.19 [3 rows, 47B] [2 rows/s, 39B/s]
trino>
trino> show tables from jmx.current;
------------------------------------------------------
com.sun.management:type=diagnosticcommand
com.sun.management:type=hotspotdiagnostic
io.airlift.discovery.client:name=announcer
......省略部分......
trino.sql.planner.optimizations:name=planoptimizer,op
trino.sql.planner.optimizations:name=planoptimizer,op
trino.type:name=typeoperatorscache
(312 rows)
Query 20211227_140448_00003_y9cev, FINISHED, 3 nodes
Splits: 6 total, 6 done (100.00%)
1.22 [312 rows, 27.8KB] [255 rows/s, 22.7KB/s]
trino>
表名使用Java classpath,其包含指标所发出的类及其参数
trino>
trino> describe jmx.current."java.lang:type=runtime";
Column | Type | Extra | Comment
------------------------+---------+-------+---------
bootclasspath | varchar | |
bootclasspathsupported | boolean | |
classpath | varchar | |
......省略部分......
vmversion | varchar | |
node | varchar | |
object_name | varchar | |
(20 rows)
Query 20211227_141310_00004_y9cev, FINISHED, 3 nodes
Splits: 6 total, 6 done (100.00%)
1.44 [20 rows, 1.66KB] [13 rows/s, 1.16KB/s]
trino>
trino> select vmname, uptime, node from jmx.current."java.lang:type=runtime";
vmname | uptime |
-----------------------------------+---------+--------
Java HotSpot(TM) 64-Bit Server VM | 1095525 | d1c6b13
Java HotSpot(TM) 64-Bit Server VM | 1095543 | a49c04c
Java HotSpot(TM) 64-Bit Server VM | 1095590 | bcd1f84
(3 rows)
Query 20211227_141607_00007_y9cev, FINISHED, 3 nodes
Splits: 4 total, 4 done (100.00%)
0.67 [3 rows, 231B] [4 rows/s, 346B/s]
trino>
2.3 黑洞blackhole连接器
类似UNIX操作系统的null设备(/dev/null),主要用来测试其他连接器的读取性能,从其他读取器读取数据,插入到黑洞连接器中的表
在所有节点新建连接器配置文件,并重启Trino
[root@trino1 catalog]#
[root@trino1 catalog]# pwd
/root/trino-server-367/etc/catalog
[root@trino1 catalog]#
[root@trino1 catalog]# cat blackhole.properties
connector.name=blackhole
[root@trino1 catalog]#
使用黑洞连接器
trino>
trino> create schema blackhole.test;
CREATE SCHEMA
trino>
trino> create table blackhole.test.orders as select * from tpch.tiny.orders;
CREATE TABLE: 15000 rows
Query 20211227_181026_00004_4cqix, FINISHED, 3 nodes
Splits: 8 total, 8 done (100.00%)
8.34 [15K rows, 0B] [1.8K rows/s, 0B/s]
trino>
trino> insert into blackhole.test.orders select * from tpch.sf3.orders;
INSERT: 4500000 rows
Query 20211227_181141_00005_4cqix, FINISHED, 3 nodes
Splits: 8 total, 8 done (100.00%)
27.99 [4.5M rows, 0B] [161K rows/s, 0B/s]
trino>
2.4 memory内存连接器
可以在memory连接器中的catalog创建数据库和表,也可以删除数据库和表,但是关闭集群数据就会全丢失
在所有节点新建连接器配置文件,并重启Trino
[root@trino1 catalog]#
[root@trino1 catalog]# pwd
/root/trino-server-367/etc/catalog
[root@trino1 catalog]#
[root@trino1 catalog]# cat memory.properties
connector.name=memory
[root@trino1 catalog]#